public class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BITS_IN_BYTE_MULTIPLIER |
static int |
KILOBYTE_MULTIPLIER |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
copy(File fromFile,
File toFile)
Copy a File.
|
static void |
copyThrowsOnException(File source,
File destination)
Copy src file to dst file.
|
static String |
getBaseFilenameForTempFile(File file)
Get a base for temp file, this should be long enough so that it easy to work out later what file the temp file
was created for if it is left lying round, but not ridiculously long as this can cause problems with max filename
limits and is not very useful.
|
static String |
getExtension(File f)
Returns the extension of the given file.
|
static int |
getIntBE(ByteBuffer b,
int start,
int end)
Computes a number whereby the 1st byte is the most significant and the last
byte is the least significant.
|
static int |
getIntLE(byte[] b)
Computes a number whereby the 1st byte is the least significant and the last
byte is the most significant.
|
static int |
getIntLE(byte[] b,
int start,
int end)
Computes a number whereby the 1st byte is the least significant and the last
byte is the most significant.
|
static long |
getLongBE(ByteBuffer b,
int start,
int end)
Computes a number whereby the 1st byte is the most significant and the last
byte is the least significant.
|
static long |
getLongLE(ByteBuffer b,
int start,
int end)
Computes a number whereby the 1st byte is the least signifcant and the last
byte is the most significant.
|
static String |
getMagicExtension(File f)
Returns the extension of the given file based on the file signature.
|
static String |
getMinBaseFilenameAllowedForTempFile(File file) |
static short |
getShortBE(ByteBuffer b,
int start,
int end)
Computes a number whereby the 1st byte is the most significant and the last
byte is the least significant.
|
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 String |
getString(ByteBuffer buffer,
Charset encoding)
Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet.
|
static String |
getString(ByteBuffer buffer,
int offset,
int length,
Charset encoding)
Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet.
|
static boolean |
isOddLength(long length) |
static ByteBuffer |
readFileDataIntoBufferBE(FileChannel fc,
int size) |
static ByteBuffer |
readFileDataIntoBufferLE(FileChannel fc,
int size) |
static String |
readFourBytesAsChars(ByteBuffer bytes)
Reads 4 bytes and concatenates them into a String.
|
static String |
readPascalString(ByteBuffer bb)
Convert a byte array to a Pascal string.
|
static String |
readString(DataInput di,
int charsToRead)
Read a string of a specified number of ASCII bytes.
|
static String |
readThreeBytesAsChars(ByteBuffer bytes)
Reads 3 bytes and concatenates them into a String.
|
static int |
readUint16(DataInput di)
Read a 16-bit big-endian unsigned integer.
|
static long |
readUint32(DataInput di)
Read a 32-bit big-endian unsigned integer using a DataInput.
|
static boolean |
rename(File fromFile,
File toFile)
Rename file, and if normal rename fails, try copy and delete instead.
|
static int |
u(byte n)
Used to convert (signed byte) to an integer as if signed byte was unsigned hence allowing
it to represent values 0 -> 255 rather than -128 -> 127.
|
static long |
u(int n)
Used to convert (signed integer) to an long as if signed integer was unsigned hence allowing
it to represent full range of integral values.
|
static int |
u(short n)
Used to convert (signed short) to an integer as if signed short was unsigned hence allowing
it to represent values 0 -> 65536 rather than -32786 -> 32786
|
public static int BITS_IN_BYTE_MULTIPLIER
public static int KILOBYTE_MULTIPLIER
public static String getExtension(File f)
f
- The file whose extension is requestedpublic static String getMagicExtension(File f) throws IOException
f
- The file whose extension is requestedIOException
public static long getLongLE(ByteBuffer b, int start, int end)
b
- The byte array @param start The starting offset in b
(b[offset]). The less significant byte @param end The end index
(included) in b (b[end]). The most significant bytepublic static long getLongBE(ByteBuffer b, int start, int end)
public static int getIntLE(byte[] b)
b
- The byte array. Maximum length for valid results is 4 bytes.public static int getIntLE(byte[] b, int start, int end)
b
- The byte arraystart
- The starting offset in b (b[offset]). The less
significant byteend
- The end index (included) in b (b[end])public static int getIntBE(ByteBuffer b, int start, int end)
b
- The ByteBufferstart
- The starting offset in b. The less
significant byteend
- The end index (included) in bpublic static short getShortBE(ByteBuffer b, int start, int end)
b
- The ByteBufferstart
- The starting offset in b. The less
significant byteend
- The end index (included) in bpublic static byte[] getSizeBEInt32(int size)
size
- public static byte[] getSizeBEInt16(short size)
size
- number to convertpublic static byte[] getSizeLEInt32(int size)
size
- number to convertpublic static String readPascalString(ByteBuffer bb) throws IOException
bb
- IOException
public static String getString(ByteBuffer buffer, int offset, int length, Charset encoding)
buffer
- offset
- offset from current positionlength
- size of data to processencoding
- public static String getString(ByteBuffer buffer, Charset encoding)
buffer
- encoding
- public static long readUint32(DataInput di) throws IOException
IOException
public static int readUint16(DataInput di) throws IOException
IOException
public static String readString(DataInput di, int charsToRead) throws IOException
IOException
public static String getBaseFilenameForTempFile(File file)
file
- public static String getMinBaseFilenameAllowedForTempFile(File file)
file
- public static boolean rename(File fromFile, File toFile)
fromFile
- toFile
- public static boolean copy(File fromFile, File toFile)
fromFile
- The existing FiletoFile
- The new Filetrue
if and only if the renaming succeeded;
false
otherwisepublic static String readFourBytesAsChars(ByteBuffer bytes)
bytes
- IOException
public static String readThreeBytesAsChars(ByteBuffer bytes)
bytes
- public static long u(int n)
n
- public static int u(short n)
n
- public static int u(byte n)
n
- public static ByteBuffer readFileDataIntoBufferLE(FileChannel fc, int size) throws IOException
fc
- size
- IOException
public static ByteBuffer readFileDataIntoBufferBE(FileChannel fc, int size) throws IOException
fc
- size
- IOException
public static void copyThrowsOnException(File source, File destination) throws IOException
source
- source Filedestination
- destination File which will be created or truncated, before copying, if it already existsIOException
- if any error occurSpublic static boolean isOddLength(long length)
length
- Copyright © 2005–2020 jthink.net. All rights reserved.