public class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static long |
DIFF_BETWEEN_ASF_DATE_AND_JAVA_DATE |
static String |
LINE_SEPARATOR
Stores the default line separator of the current underlying system.
|
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static void |
checkStringLengthNullSafe(String value)
This method checks given string will not exceed limit in bytes[] when
converted UTF-16LE encoding (2 bytes per character) and checks whether
the length doesn't exceed 65535 bytes.
|
static void |
copy(InputStream source,
OutputStream dest,
long amount)
effectively copies a specified amount of bytes from one stream to
another.
|
static void |
flush(InputStream source,
OutputStream dest)
Copies all of the source to the destination.
|
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 byte[] |
getBytes(String source,
Charset charset)
Convenience method to convert the given string into a byte sequence which
has the format of the charset given.
|
static GregorianCalendar |
getDateOf(BigInteger fileTime)
Date values in ASF files are given in 100 ns (10 exp -4) steps since first
|
static boolean |
isBlank(String toTest)
Tests if the given string is
null or just contains
whitespace characters. |
static boolean |
isStringLengthValidNullSafe(String value) |
static BigInteger |
readBig64(InputStream stream)
Reads 8 bytes from stream and interprets them as a UINT64 which is
returned as
BigInteger . |
static byte[] |
readBinary(InputStream stream,
long size)
Reads
size bytes from the stream. |
static String |
readCharacterSizedString(InputStream stream)
This method reads a UTF-16 String, which length is given on the number of
characters it consists of.
|
static String |
readFixedSizeUTF16Str(InputStream stream,
int strLen)
This method reads a UTF-16 encoded String.
|
static GUID |
readGUID(InputStream stream)
This Method reads a GUID (which is a 16 byte long sequence) from the
given
raf and creates a wrapper. |
static int |
readUINT16(InputStream stream)
Reads 2 bytes from stream and interprets them as UINT16.
|
static long |
readUINT32(InputStream stream)
Reads 4 bytes from stream and interprets them as UINT32.
|
static long |
readUINT64(InputStream stream)
Reads long as little endian.
|
static String |
readUTF16LEStr(InputStream stream)
This method reads a UTF-16 encoded String, beginning with a 16-bit value
representing the number of bytes needed.
|
static void |
writeUINT16(int number,
OutputStream out)
Writes the given value as UINT16 into the stream.
|
static void |
writeUINT32(long number,
OutputStream out)
Writes the given value as UINT32 into the stream.
|
static void |
writeUINT64(long number,
OutputStream out)
Writes the given value as UINT64 into the stream.
|
public static final long DIFF_BETWEEN_ASF_DATE_AND_JAVA_DATE
public static final String LINE_SEPARATOR
public static void checkStringLengthNullSafe(String value) throws IllegalArgumentException
value
- The string to check.IllegalArgumentException
- If byte representation takes more than 65535 bytes.public static boolean isStringLengthValidNullSafe(String value)
value
- String to check for nullpublic static void copy(InputStream source, OutputStream dest, long amount) throws IOException
source
- stream to read fromdest
- stream to write toamount
- amount of bytes to copyIOException
- on I/O errors, and if the source stream depletes before all
bytes have been copied.public static void flush(InputStream source, OutputStream dest) throws IOException
source
- source to read fromdest
- stream to write toIOException
- on I/O errors.public static byte[] getBytes(long value, int byteCount)
byteCount
and insert the bytes of value
(starting from lowset byte)
into it. value
- The value to be written into the result.byteCount
- The number of bytes the array has got.byteCount
containing the
lower byte values of value
.public static byte[] getBytes(String source, Charset charset)
source
- string to convert.charset
- charset to applypublic static GregorianCalendar getDateOf(BigInteger fileTime)
fileTime
- Time in 100ns since 1 jan 1601public static boolean isBlank(String toTest)
null
or just contains
whitespace characters.toTest
- String to test.public static BigInteger readBig64(InputStream stream) throws IOException
BigInteger
.stream
- stream to readm from.IOException
- if problem reading bytespublic static byte[] readBinary(InputStream stream, long size) throws IOException
size
bytes from the stream.stream
- stream to read from.size
- amount of bytes to read.IOException
- on I/O errors.public static String readCharacterSizedString(InputStream stream) throws IOException
stream
- Input sourceIOException
- read errorspublic static String readFixedSizeUTF16Str(InputStream stream, int strLen) throws IOException
stream
- Input sourcestrLen
- Number of bytes the String may take.IOException
- read errors.public static GUID readGUID(InputStream stream) throws IOException
raf
and creates a wrapper. stream
- Input source.IOException
- happens when the file ends before guid could be extracted.public static int readUINT16(InputStream stream) throws IOException
stream
- stream to read from.IOException
- on I/O Errors.public static long readUINT32(InputStream stream) throws IOException
stream
- stream to read from.IOException
- on I/O Errors.public static long readUINT64(InputStream stream) throws IOException
stream
- Data sourceIOException
- read error, or eof is reached before long is completedpublic static String readUTF16LEStr(InputStream stream) throws IOException
stream
- Input sourceIOException
- read errors.public static void writeUINT16(int number, OutputStream out) throws IOException
number
- value to write.out
- stream to write into.IOException
- On I/O errorspublic static void writeUINT32(long number, OutputStream out) throws IOException
number
- value to write.out
- stream to write into.IOException
- On I/O errorspublic static void writeUINT64(long number, OutputStream out) throws IOException
number
- value to write.out
- stream to write into.IOException
- On I/O errorsCopyright © 2005–2020 jthink.net. All rights reserved.