org.jaudiotagger.audio.generic
Class Utils

java.lang.Object
  extended by org.jaudiotagger.audio.generic.Utils

public class Utils
extends java.lang.Object

Contains various frequently used static functions in the different tag formats

Author:
Raphael Slinckx

Field Summary
static java.util.logging.Logger logger
           
 
Constructor Summary
Utils()
           
 
Method Summary
static void copy(byte[] src, byte[] dst, int dstOffset)
          Copies the bytes of srd to dst at the specified offset.
static boolean copy(java.io.File fromFile, java.io.File toFile)
          Copy a File
static byte[] getDefaultBytes(java.lang.String s, java.lang.String charSet)
          Returns String.getBytes().
static java.lang.String getExtension(java.io.File f)
           
static int getIntBE(byte[] b, int start, int end)
           
static int getIntBE(java.nio.ByteBuffer b, int start, int end)
           
static int getIntLE(byte[] b)
           
static int getIntLE(byte[] b, int start, int end)
           
static long getLongBE(java.nio.ByteBuffer b, int start, int end)
           
static long getLongLE(java.nio.ByteBuffer b, int start, int end)
           
static java.lang.String getMinBaseFilenameAllowedForTempFile(java.io.File file)
           
static short getShortBE(java.nio.ByteBuffer b, int start, int end)
           
static byte[] getSizeBEInt16(short size)
          Convert short to byte representation - Big Endian (as used by mp4)
static byte[] getSizeBEInt32(int size)
          Convert int to byte representation - Big Endian (as used by mp4)
static byte[] getSizeLEInt32(int size)
          Convert int to byte representation - Little Endian (as used by ogg vorbis)
static java.lang.String getString(byte[] b, int offset, int length, java.lang.String encoding)
          Create String starting from offset upto length using encoding
static java.lang.String getString(java.nio.ByteBuffer buffer, int offset, int length, java.lang.String encoding)
          Create String offset from position by offset upto length using encoding, and position of buffer is moved to after position + offset + length
static byte[] getUTF8Bytes(java.lang.String s)
           
static int read(java.nio.ByteBuffer b)
           
static java.lang.String readString(java.io.DataInput di, int charsToRead)
           
static int readUBEInt16(java.nio.ByteBuffer b)
           
static int readUBEInt24(java.nio.ByteBuffer b)
           
static int readUBEInt32(java.nio.ByteBuffer b)
           
static int readUint16(java.io.DataInput di)
           
static long readUint32(java.io.DataInput di)
           
static int readUint32AsInt(java.io.DataInput di)
          Overflow checking since java can't handle unsigned numbers.
static long readUInt64(java.nio.ByteBuffer b)
           
static int readUInt8(java.nio.ByteBuffer b)
           
static boolean rename(java.io.File fromFile, java.io.File toFile)
          Rename file, and if normal rename fails, try copy and delete instead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static java.util.logging.Logger logger
Constructor Detail

Utils

public Utils()
Method Detail

copy

public static void copy(byte[] src,
                        byte[] dst,
                        int dstOffset)
Copies the bytes of srd to dst at the specified offset.

Parameters:
src - The byte to be copied.
dst - The array to copy to
dstOffset - The start offset for the bytes to be copied.

getDefaultBytes

public static byte[] getDefaultBytes(java.lang.String s,
                                     java.lang.String charSet)
Returns String.getBytes().

Parameters:
s - The String to call, decode bytes using the specfied charset
charSet -
Returns:
The bytes.

getExtension

public static java.lang.String getExtension(java.io.File f)

getLongLE

public static long getLongLE(java.nio.ByteBuffer b,
                             int start,
                             int end)

getLongBE

public static long getLongBE(java.nio.ByteBuffer b,
                             int start,
                             int end)

getIntLE

public static int getIntLE(byte[] b)

getIntLE

public static int getIntLE(byte[] b,
                           int start,
                           int end)

getIntBE

public static int getIntBE(byte[] b,
                           int start,
                           int end)

getIntBE

public static int getIntBE(java.nio.ByteBuffer b,
                           int start,
                           int end)

getShortBE

public static short getShortBE(java.nio.ByteBuffer b,
                               int start,
                               int end)

getSizeBEInt32

public static byte[] getSizeBEInt32(int size)
Convert int to byte representation - Big Endian (as used by mp4)

Parameters:
size -
Returns:
byte represenetation

getSizeBEInt16

public static byte[] getSizeBEInt16(short size)
Convert short to byte representation - Big Endian (as used by mp4)

Parameters:
size -
Returns:
byte represenetation

getSizeLEInt32

public static byte[] getSizeLEInt32(int size)
Convert int to byte representation - Little Endian (as used by ogg vorbis)

Parameters:
size -
Returns:
byte represenetation

getString

public static java.lang.String getString(byte[] b,
                                         int offset,
                                         int length,
                                         java.lang.String encoding)
Create String starting from offset upto length using encoding

Parameters:
b -
offset -
length -
encoding -
Returns:
Throws:
java.io.UnsupportedEncodingException

getString

public static java.lang.String getString(java.nio.ByteBuffer buffer,
                                         int offset,
                                         int length,
                                         java.lang.String encoding)
Create String offset from position by offset upto length using encoding, and position of buffer is moved to after position + offset + length

Parameters:
buffer -
offset -
length -
encoding -
Returns:

getUTF8Bytes

public static byte[] getUTF8Bytes(java.lang.String s)
                           throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

readUint32AsInt

public static int readUint32AsInt(java.io.DataInput di)
                           throws java.io.IOException
Overflow checking since java can't handle unsigned numbers.

Parameters:
di -
Returns:
Throws:
java.io.IOException

readUint32

public static long readUint32(java.io.DataInput di)
                       throws java.io.IOException
Throws:
java.io.IOException

readUint16

public static int readUint16(java.io.DataInput di)
                      throws java.io.IOException
Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.DataInput di,
                                          int charsToRead)
                                   throws java.io.IOException
Throws:
java.io.IOException

readUInt64

public static long readUInt64(java.nio.ByteBuffer b)

readUBEInt32

public static int readUBEInt32(java.nio.ByteBuffer b)

readUBEInt24

public static int readUBEInt24(java.nio.ByteBuffer b)

readUBEInt16

public static int readUBEInt16(java.nio.ByteBuffer b)

readUInt8

public static int readUInt8(java.nio.ByteBuffer b)

read

public static int read(java.nio.ByteBuffer b)

getMinBaseFilenameAllowedForTempFile

public static java.lang.String getMinBaseFilenameAllowedForTempFile(java.io.File file)
Parameters:
file -
Returns:
filename with audioformat seperator stripped of, lengthened to ensure not too small for valid tempfile creation.

rename

public static boolean rename(java.io.File fromFile,
                             java.io.File toFile)
Rename file, and if normal rename fails, try copy and delete instead

Parameters:
fromFile -
toFile -
Returns:

copy

public static boolean copy(java.io.File fromFile,
                           java.io.File toFile)
Copy a File

Parameters:
fromFile - The existing File
toFile - The new File
Returns:
true if and only if the renaming succeeded; false otherwise