entagged.audioformats.asf.util
Class Utils

java.lang.Object
  extended by entagged.audioformats.asf.util.Utils

public class Utils
extends Object

Some static Methods which are used in several Classes.

Author:
Christian Laireiter

Field Summary
static String LINE_SEPARATOR
          Stores the default line seperator of the current underlying system.
 
Constructor Summary
Utils()
           
 
Method Summary
static void checkStringLengthNullSafe(String value)
          This method converts the given string into a byte[] in UTF-16LE encoding and checks whether the length doesn't exceed 65535 bytes.
static void fillChars(char[] chars, RandomAccessFile raf)
          Reads chars out of raf until chars is filled.
static byte[] getBytes(long value, int byteCount)
          This method will create a byte[] at the size of byteCount and insert the bytes of value (starting from lowset byte) into it.
static GregorianCalendar getDateOf(BigInteger fileTime)
          Since date values in asf files are given in 100 ns steps since first january of 1601 a little conversion must be done.
static int read7Bit(RandomAccessFile raf)
          This method reads one byte from raf and creates an unsigned value of it.
static BigInteger readBig64(RandomAccessFile raf)
          This method reads 8 bytes, interprets them as an unsigned number and creates a BigInteger
static String readCharacterSizedString(RandomAccessFile raf)
          This method reads a UTF-16 String, which legth is given on the number of characters it consits of.
static GUID readGUID(RandomAccessFile raf)
          This Method reads a GUID (which is a 16 byte long sequence) from the given raf and creates a wrapper.
static int readUINT16(RandomAccessFile raf)
           
static long readUINT32(RandomAccessFile raf)
           
static long readUINT64(RandomAccessFile raf)
          Reads long as little endian.
static String readUTF16LEStr(RandomAccessFile raf)
          This method reads a UTF-16 encoded String, beginning with a 16-bit value representing the number of bytes needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static final String LINE_SEPARATOR
Stores the default line seperator of the current underlying system.

Constructor Detail

Utils

public Utils()
Method Detail

fillChars

public static void fillChars(char[] chars,
                             RandomAccessFile raf)
                      throws IOException
Reads chars out of raf until chars is filled.

Parameters:
chars - to be filled
raf - to be read
Throws:
IOException - read error, or file at end before chars is filled.

getBytes

public static byte[] getBytes(long value,
                              int byteCount)
This method will create a byte[] at the size of byteCount and insert the bytes of value (starting from lowset byte) into it.
You can easily create a Word (16-bit), DWORD (32-bit), QWORD (64 bit) out of the value, ignoring the original type of value, since java automatically performs transformations.
Warning: This method works with unsigned numbers only.

Parameters:
value - The value to be written into the result.
byteCount - The number of bytes the array has got.
Returns:
A byte[] with the size of byteCount containing the lower byte values of value.

getDateOf

public static GregorianCalendar getDateOf(BigInteger fileTime)
Since date values in asf files are given in 100 ns steps since first january of 1601 a little conversion must be done.
This method converts a date given in described manner to a calendar.

Parameters:
fileTime - Time in 100ns since 1 jan 1601
Returns:
Calendar holding the date representation.

read7Bit

public static int read7Bit(RandomAccessFile raf)
                    throws IOException
This method reads one byte from raf and creates an unsigned value of it.

Parameters:
raf - The file to read from.
Returns:
next 7 bits as number.
Throws:
IOException - read errors.

readBig64

public static BigInteger readBig64(RandomAccessFile raf)
                            throws IOException
This method reads 8 bytes, interprets them as an unsigned number and creates a BigInteger

Parameters:
raf - Input source
Returns:
8 bytes unsigned number
Throws:
IOException - read errors.

readCharacterSizedString

public static String readCharacterSizedString(RandomAccessFile raf)
                                       throws IOException
This method reads a UTF-16 String, which legth is given on the number of characters it consits of.
The filepointer of raf must be at the number of characters. This number contains the terminating zero character (UINT16).

Parameters:
raf - Input source
Returns:
String
Throws:
IOException - read errors

readGUID

public static GUID readGUID(RandomAccessFile raf)
                     throws IOException
This Method reads a GUID (which is a 16 byte long sequence) from the given raf and creates a wrapper.
Warning :
There is no way of telling if a byte sequence is a guid or not. The next 16 bytes will be interpreted as a guid, whether it is or not.

Parameters:
raf - Input source.
Returns:
A class wrapping the guid.
Throws:
IOException - happens when the file ends before guid could be extracted.

readUINT16

public static int readUINT16(RandomAccessFile raf)
                      throws IOException
Parameters:
raf -
Returns:
number
Throws:
IOException
See Also:
readUINT64(RandomAccessFile)

readUINT32

public static long readUINT32(RandomAccessFile raf)
                       throws IOException
Parameters:
raf -
Returns:
number
Throws:
IOException
See Also:
readUINT64(RandomAccessFile)

readUINT64

public static long readUINT64(RandomAccessFile raf)
                       throws IOException
Reads long as little endian.

Parameters:
raf - Data source
Returns:
long value
Throws:
IOException - read error, or eof is reached before long is completed

readUTF16LEStr

public static String readUTF16LEStr(RandomAccessFile raf)
                             throws IOException
This method reads a UTF-16 encoded String, beginning with a 16-bit value representing the number of bytes needed. The String is terminated with as 16-bit ZERO.

Parameters:
raf - Input source
Returns:
read String.
Throws:
IOException - read errors.

checkStringLengthNullSafe

public static void checkStringLengthNullSafe(String value)
                                      throws IllegalArgumentException
This method converts the given string into a byte[] in UTF-16LE encoding and checks whether the length doesn't exceed 65535 bytes.

Parameters:
value - The string to check.
Throws:
IllegalArgumentException - If byte representation takes more than 65535 bytes.


Copyright © 2007-2008. All Rights Reserved.