mediautil.gen
Class BasicIo

java.lang.Object
  extended by mediautil.gen.BasicIo
Direct Known Subclasses:
BasicJpegIo

public class BasicIo
extends Object

This is a utility class containing io and other general methods. This is mainly for use by other MediaUtil classes but may also be useful otherwise.


Field Summary
static String[] FACTOR_ABVS
           
 
Constructor Summary
BasicIo()
           
 
Method Summary
static int asInt(String str)
           
static String asString(int i)
           
static void bn2s(byte[] result, int offset, int value, int length)
          Converts the passed int value to bytes of Motorola Type (byte[0] is LSB)
static byte[] bn2s(int value, int length)
          Converts the passed int value to bytes of Motorola Type (byte[0] is LSB)
static String convertLength(long l)
           
static void in2s(byte[] result, int offset, int value, int length)
          Converts the passed int value to bytes of Intel Type (byte[0] is MSB)
static boolean isSignature(byte[] markerData, int offset, String signature)
          Checks if the bytes in markerData match the signature String.
static int read(InputStream is, byte[] data)
          Definitely Reads data.length bytes unless End of Stream is reached.
static int read(InputStream is, byte[] b, int off, int minBytes, int n)
          Attempts to read n bytes and definitely reads minBytes.
static int s2n(byte[] buf, int offset, int length, boolean signed, boolean intel)
          Converts bytes to a number
static long skip(InputStream is, long n)
          Definitely Skips n bytes unless End of Stream is reached.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACTOR_ABVS

public static final String[] FACTOR_ABVS
Constructor Detail

BasicIo

public BasicIo()
Method Detail

s2n

public static int s2n(byte[] buf,
                      int offset,
                      int length,
                      boolean signed,
                      boolean intel)
Converts bytes to a number

Parameters:
buf - Bytes to convert
offset - Start offset of bytes
length - Length of bytes to convert
signed - If signed
intel - Specifies If data is of intel type (buf[0] is Most Significant Byte). If false then data is of Motorola Type (buf[0] is LSB)

in2s

public static void in2s(byte[] result,
                        int offset,
                        int value,
                        int length)
Converts the passed int value to bytes of Intel Type (byte[0] is MSB)

Parameters:
result - Output bytes
offset - Start offset to store the result
value - Value to convert
length - Length of bytes required

bn2s

public static void bn2s(byte[] result,
                        int offset,
                        int value,
                        int length)
Converts the passed int value to bytes of Motorola Type (byte[0] is LSB)

Parameters:
result - Output bytes
offset - Start offset to store the result
value - Value to convert
length - Length of bytes required

bn2s

public static byte[] bn2s(int value,
                          int length)
Converts the passed int value to bytes of Motorola Type (byte[0] is LSB)

Parameters:
value - Value to convert
length - Length of bytes required
Returns:
Output bytes stored in a new byte array of size length

isSignature

public static boolean isSignature(byte[] markerData,
                                  int offset,
                                  String signature)
Checks if the bytes in markerData match the signature String.

Parameters:
markerData - Marker Data
offset - Start offset of bytes
signature - Signature String. All the characters in this String are compared with the bytes starting from offset
Returns:
true if the signature matches, false otherwise

skip

public static long skip(InputStream is,
                        long n)
                 throws IOException
Definitely Skips n bytes unless End of Stream is reached. This is unlike the skip method of the InputStream which may skip less than the required number of bytes. This calls the InputStream's skip method repeatedly.

Parameters:
is - Input Stream
n - Number bytes to skip
Returns:
Number of bytes actually skipped this equals n unless End Of Stream is reached.
Throws:
IOException

read

public static int read(InputStream is,
                       byte[] b,
                       int off,
                       int minBytes,
                       int n)
                throws IOException
Attempts to read n bytes and definitely reads minBytes. This is unlike the read method of the InputStream which may read less than than the required number of bytes. This calls the InputStream's read method repeatedly. This method does not return -1 on End Of Stream.

Parameters:
is - Input Stream
b - Byte Array to read into
off - Offset to store data from
minBytes - Minimum bytes to read
n - Number of bytes to try to read
Returns:
Number of bytes actually read. This is >= minBytes and <= n unless End Of Stream is reached in which case it could be < minBytes. The return value is always >= 0.
Throws:
IOException - If n < 0 or if minBytes > n or if is.read(..) throws and Exception.

read

public static int read(InputStream is,
                       byte[] data)
                throws IOException
Definitely Reads data.length bytes unless End of Stream is reached. This is unlike the read method of the InputStream which may read less than the required number of bytes. This calls the InputStream's read method repeatedly. This method does not return -1 on End Of Stream.

Parameters:
is - Input Stream
data - Byte array to read to
Returns:
Number of bytes actually read which equals data.length unless End Of Stream is reached. The return value is always >= 0.
Throws:
IOException

convertLength

public static String convertLength(long l)

asInt

public static int asInt(String str)

asString

public static String asString(int i)