public class TNEFUtils extends Object
TNEFUtils
class provides utility methods used by the TNEF
processing classes.Constructor and Description |
---|
TNEFUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
attID(int att)
Returns the ID part of a 32-bit combined attribute type and ID value.
|
static int |
attribute(int atp,
int id)
Returns a 32-bit value containing a combined attribute type and ID.
|
static int |
attType(int att)
Returns the type part of a 32-bit combined attribute type and ID value.
|
static int |
calculateChecksum(byte[] data)
Returns the checksum of a given byte array.
|
static int |
calculateChecksum(byte[] data,
int offset,
int length)
Returns the checksum of a range of bytes within a given byte array.
|
static int |
calculateChecksum(RawInputStream ris)
Returns the checksum of all the data in a given RawInputStream.
|
static int |
calculateCRC32(byte[] buf,
int off,
int len)
Deprecated.
|
static String |
createString(byte[] bytes,
int offset,
int length)
Creates a String from a C-style null terminated byte sequence.
|
static String |
createStringUnicode(byte[] bytes,
int offset,
int length)
Creates a String from a C-style null terminated Unicode byte sequence.
|
static byte[] |
decompressRTF(byte[] src)
Deprecated.
use
CompressedRTFInputStream.decompressRTF(byte[]) instead |
static String |
getConstName(Class cls,
String constPrefix,
long value)
Returns the name of a constant which is defined in given Class,
has a name beginning with given prefix, and has given value.
|
static int |
getU16(byte[] buf,
int offset)
Returns an unsigned 16-bit value from little-endian ordered bytes.
|
static int |
getU16(int b1,
int b2)
Returns an unsigned 16-bit value from little-endian ordered bytes.
|
static long |
getU32(byte[] buf,
int offset)
Returns an unsigned 32-bit value from little-endian ordered bytes.
|
static long |
getU32(int b1,
int b2,
int b3,
int b4)
Returns an unsigned 32-bit value from little-endian ordered bytes.
|
static long |
getU64(byte[] buf,
int offset)
Returns a 64-bit value from little-endian ordered bytes.
|
static int |
getU8(byte[] buf,
int offset)
Returns an unsigned 8-bit value from a byte array.
|
static boolean |
isTNEFMimeType(String mimeType)
Checks whether the given string contains a TNEF mime type
|
static int |
read(InputStream in,
byte[] b,
int off,
int min,
int max)
Reads bytes from a stream.
|
static String |
removeTerminatingNulls(String s)
Removes all null characters ('\0') from the end of a given String.
|
static String |
replace(String s,
String search,
String replace)
Replaces all occurrences of given substring within string with a replacement
string.
|
static byte[] |
toGUID(String guid)
Deprecated.
use the GUID class for GUID manipulation
|
static String |
toHexString(byte[] bytes)
Creates a String containing the hexadecimal representation of the given
bytes.
|
static String |
toHexString(byte[] bytes,
int max)
Creates a String containing the hexadecimal representation of the given
bytes.
|
static String |
toHexString(byte[] bytes,
int offset,
int len,
int max)
Creates a String containing the hexadecimal representation of the given
bytes.
|
public static int getU8(byte[] buf, int offset)
buf
- a byte array from which byte value is takenoffset
- the offset within buf from which byte value is takenpublic static int getU16(int b1, int b2)
b1
- first byte valueb2
- second byte valuepublic static int getU16(byte[] buf, int offset)
buf
- a byte array from which byte values are takenoffset
- the offset within buf from which byte values are takenpublic static long getU32(int b1, int b2, int b3, int b4)
b1
- first byte valueb2
- second byte valueb3
- third byte valueb4
- fourth byte valuepublic static long getU32(byte[] buf, int offset)
buf
- a byte array from which byte values are takenoffset
- the offset within buf from which byte values are takenpublic static long getU64(byte[] buf, int offset)
buf
- a byte array from which byte values are takenoffset
- the offset within buf from which byte values are takenpublic static int attribute(int atp, int id)
atp
- the attribute typeid
- the attribute IDpublic static int attID(int att)
att
- the combined attribute type and ID valuepublic static int attType(int att)
att
- the combined attribute type and ID valuepublic static int calculateChecksum(byte[] data)
data
- the byte array on which to calculate the checksumpublic static int calculateChecksum(byte[] data, int offset, int length)
data
- the byte array on which to calculate the checksumoffset
- the offset within the array from which to beginlength
- the number of bytes to calculate checksum onpublic static int calculateChecksum(RawInputStream ris) throws IOException
ris
- the stream from which the data is readIOException
- if an I/O error occurspublic static String getConstName(Class cls, String constPrefix, long value)
cls
- the Class containing the constantconstPrefix
- the prefix of the constant name (used in grouping constants)value
- the constant's valuepublic static String removeTerminatingNulls(String s)
s
- a Stringpublic static String replace(String s, String search, String replace)
s
- the string to be modifiedsearch
- the substring to search forreplace
- the string with which to replace occurrences of the search substringpublic static String createString(byte[] bytes, int offset, int length)
bytes
- a byte array containing a C-style null terminated stringoffset
- the offset within bytes where the string beginslength
- the length of the C-style string in bytes, which may
include any number of terminating null ('\0') characterspublic static String createStringUnicode(byte[] bytes, int offset, int length)
bytes
- a byte array containing a C-style null terminated Unicode stringoffset
- the offset within bytes where the string beginslength
- the length of the C-style string in bytes, which may
include any number of terminating null ('\0') characterspublic static String toHexString(byte[] bytes)
bytes
- a byte array whose content is to be displayedpublic static String toHexString(byte[] bytes, int max)
If max
is non-negative and bytes.length > max
, then the
first max
bytes are returned, followed by a human-readable
indication that there are bytes.length
total bytes of data
including those that are not returned.
bytes
- a byte array whose content is to be displayedmax
- the maximum number of bytes to be displayed (-1 means no limit)public static String toHexString(byte[] bytes, int offset, int len, int max)
If max
is non-negative and len > max
, then the
first max
bytes are returned, followed by a human-readable
indication that there are len
total bytes of data
including those that are not returned.
In particular, offset + len
can extend beyond the array boundaries,
as long as offset + max
is still within them, resulting in
max
bytes returned followed by an indication that there are
len
total data bytes (including those that are not returned).
bytes
- a byte array whose content is to be displayedoffset
- the offset within the byte array to start atlen
- the number of bytesmax
- the maximum number of bytes to be displayed (-1 means no limit)public static boolean isTNEFMimeType(String mimeType)
mimeType
- the mimeType to checkpublic static byte[] toGUID(String guid) throws IllegalArgumentException
guid
- the GUID stringIllegalArgumentException
- if the given string does not
represent a valid GUIDpublic static int calculateCRC32(byte[] buf, int off, int len)
CompressedRTFInputStream.calculateCRC32(byte[], int, int)
insteadbuf
- the byte array to calculate CRC32 onoff
- the offset within buf at which the CRC32 calculation will startlen
- the number of bytes on which to calculate the CRC32public static byte[] decompressRTF(byte[] src)
CompressedRTFInputStream.decompressRTF(byte[])
insteadsrc
- the compressed-RTF data bytesIllegalArgumentException
- if src does not contain valid
compressed-RTF bytespublic static int read(InputStream in, byte[] b, int off, int min, int max) throws IOException
in
- the input stream to read fromb
- the byte array to read intooff
- the offset within the byte array to start reading intomin
- the minimum number of bytes to readmax
- the maximum number of bytes to readIOException
- if an error occurs or there are less
than the minimum number of bytes in the streamThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.