|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.i2p.data.DataHelper
public class DataHelper
Defines some simple IO routines for dealing with marshalling data structures
Field Summary | |
---|---|
static byte |
BOOLEAN_FALSE
|
static int |
BOOLEAN_LENGTH
|
static byte |
BOOLEAN_TRUE
|
static byte |
BOOLEAN_UNKNOWN
|
static int |
DATE_LENGTH
|
Constructor Summary | |
---|---|
DataHelper()
|
Method Summary | |
---|---|
static int |
compareTo(byte[] lhs,
byte[] rhs)
|
static byte[] |
compress(byte[] orig)
compress the data and return a new GZIP compressed array |
static byte[] |
compress(byte[] orig,
int offset,
int size)
|
static byte[] |
decompress(byte[] orig)
decompress the GZIP compressed data (returning null on error) |
static byte[] |
decompress(byte[] orig,
int offset,
int length)
|
static boolean |
eq(byte[] lhs,
byte[] rhs)
Run a comparison on the byte arrays, byte by byte. |
static boolean |
eq(byte[] lhs,
int offsetLeft,
byte[] rhs,
int offsetRight,
int length)
|
static boolean |
eq(byte lhs,
byte rhs)
Compare two bytes, really just for consistency. |
static boolean |
eq(java.util.Collection lhs,
java.util.Collection rhs)
Run a deep comparison across the two collections. |
static boolean |
eq(int lhs,
int rhs)
Compare two integers, really just for consistency. |
static boolean |
eq(long lhs,
long rhs)
Compare two longs, really just for consistency. |
static boolean |
eq(java.lang.Object lhs,
java.lang.Object rhs)
Helper util to compare two objects, including null handling. |
static java.lang.String |
formatDuration(long ms)
|
static java.lang.Boolean |
fromBoolean(byte[] data,
int offset)
|
static java.util.Date |
fromDate(byte[] src,
int offset)
|
static byte[] |
fromHexString(java.lang.String val)
|
static long |
fromLong(byte[] src,
int offset,
int numBytes)
|
static int |
fromProperties(byte[] source,
int offset,
java.util.Properties target)
|
static java.lang.String |
getUTF8(byte[] orig)
|
static java.lang.String |
getUTF8(byte[] orig,
int offset,
int len)
|
static byte[] |
getUTF8(java.lang.String orig)
|
static byte[] |
getUTF8(java.lang.StringBuffer orig)
|
static int |
hashCode(byte[] b)
Calculate the hashcode of the byte array, using 0 for null |
static int |
hashCode(java.util.Collection col)
Calculate the hashcode of the collection, using 0 for null |
static int |
hashCode(java.util.Date obj)
Calculate the hashcode of the date, using 0 for null |
static int |
hashCode(java.lang.Object obj)
Calculate the hashcode of the object, using 0 for null |
static void |
loadProps(java.util.Properties props,
java.io.File file)
A more efficient Properties.load |
static void |
loadProps(java.util.Properties props,
java.io.File file,
boolean forceLowerCase)
|
static void |
loadProps(java.util.Properties props,
java.io.InputStream inStr)
|
static void |
loadProps(java.util.Properties props,
java.io.InputStream inStr,
boolean forceLowerCase)
|
static int |
read(java.io.InputStream in,
byte[] target)
|
static int |
read(java.io.InputStream in,
byte[] target,
int offset,
int length)
|
static java.lang.Boolean |
readBoolean(java.io.InputStream in)
Read in a boolean as specified by the I2P data structure spec. |
static java.util.Date |
readDate(java.io.InputStream in)
Read in a date from the stream as specified by the I2P data structure spec. |
static java.lang.String |
readLine(java.io.InputStream in)
Read a newline delimited line from the stream, returning the line (without the newline), or null if EOF reached before the newline was found |
static java.lang.String |
readLine(java.io.InputStream in,
Sha256Standalone hash)
update the hash along the way |
static boolean |
readLine(java.io.InputStream in,
java.lang.StringBuffer buf)
Read in a line, placing it into the buffer (excluding the newline). |
static boolean |
readLine(java.io.InputStream in,
java.lang.StringBuffer buf,
Sha256Standalone hash)
update the hash along the way |
static long |
readLong(java.io.InputStream rawStream,
int numBytes)
Read the stream for an integer as defined by the I2P data structure specification. |
static java.util.Properties |
readProperties(java.io.InputStream rawStream)
Read a mapping from the stream, as defined by the I2P data structure spec, and store it into a Properties object. |
static java.lang.String |
readString(java.io.InputStream in)
Read in a string from the stream as specified by the I2P data structure spec. |
static java.util.List |
sortStructures(java.util.Collection dataStructures)
|
static void |
storeProps(java.util.Properties props,
java.io.File file)
|
static java.lang.String |
stripHTML(java.lang.String orig)
Strip out any HTML (simply removing any less than / greater than symbols) |
static void |
toBoolean(byte[] data,
int offset,
boolean value)
|
static void |
toBoolean(byte[] data,
int offset,
java.lang.Boolean value)
|
static void |
toDate(byte[] target,
int offset,
long when)
|
static byte[] |
toDate(java.util.Date date)
|
static java.lang.String |
toDecimalString(byte[] buf,
int len)
|
static java.lang.String |
toHexString(byte[] data)
|
static void |
toLong(byte[] target,
int offset,
int numBytes,
long value)
|
static byte[] |
toLong(int numBytes,
long value)
|
static int |
toProperties(byte[] target,
int offset,
java.util.Properties props)
|
static byte[] |
toProperties(java.util.Properties opts)
|
static java.lang.String |
toString(byte[] buf)
|
static java.lang.String |
toString(byte[] buf,
int len)
|
static java.lang.String |
toString(java.util.Collection col)
Pretty print the collection |
static java.lang.String |
toString(java.util.Properties options)
Pretty print the mapping |
static void |
write(java.io.OutputStream out,
byte[] data,
Sha256Standalone hash)
|
static void |
writeBoolean(java.io.OutputStream out,
java.lang.Boolean bool)
Write out a boolean as specified by the I2P data structure spec. |
static void |
writeDate(java.io.OutputStream out,
java.util.Date date)
Write out a date to the stream as specified by the I2P data structure spec. |
static void |
writeLong(java.io.OutputStream rawStream,
int numBytes,
long value)
Write an integer as defined by the I2P data structure specification to the stream. |
static void |
writeProperties(java.io.OutputStream rawStream,
java.util.Properties props)
Write a mapping to the stream, as defined by the I2P data structure spec, and store it into a Properties object. |
static void |
writeString(java.io.OutputStream out,
java.lang.String string)
Write out a string to the stream as specified by the I2P data structure spec. |
static byte[] |
xor(byte[] lhs,
byte[] rhs)
|
static void |
xor(byte[] lhs,
int startLeft,
byte[] rhs,
int startRight,
byte[] out,
int startOut,
int len)
xor the lhs with the rhs, storing the result in out. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DATE_LENGTH
public static final byte BOOLEAN_TRUE
public static final byte BOOLEAN_FALSE
public static final byte BOOLEAN_UNKNOWN
public static final int BOOLEAN_LENGTH
Constructor Detail |
---|
public DataHelper()
Method Detail |
---|
public static java.util.Properties readProperties(java.io.InputStream rawStream) throws DataFormatException, java.io.IOException
rawStream
- stream to read the mapping from
DataFormatException
- if the format is invalid
java.io.IOException
- if there is a problem reading the datapublic static void writeProperties(java.io.OutputStream rawStream, java.util.Properties props) throws DataFormatException, java.io.IOException
rawStream
- stream to write toprops
- properties to write out
DataFormatException
- if there is not enough valid data to write out
java.io.IOException
- if there is an IO error writing out the datapublic static int toProperties(byte[] target, int offset, java.util.Properties props) throws DataFormatException, java.io.IOException
DataFormatException
java.io.IOException
public static int fromProperties(byte[] source, int offset, java.util.Properties target) throws DataFormatException, java.io.IOException
DataFormatException
java.io.IOException
public static byte[] toProperties(java.util.Properties opts)
public static java.lang.String toString(java.util.Properties options)
public static void loadProps(java.util.Properties props, java.io.File file) throws java.io.IOException
java.io.IOException
public static void loadProps(java.util.Properties props, java.io.File file, boolean forceLowerCase) throws java.io.IOException
java.io.IOException
public static void loadProps(java.util.Properties props, java.io.InputStream inStr) throws java.io.IOException
java.io.IOException
public static void loadProps(java.util.Properties props, java.io.InputStream inStr, boolean forceLowerCase) throws java.io.IOException
java.io.IOException
public static void storeProps(java.util.Properties props, java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String toString(java.util.Collection col)
public static java.lang.String toString(byte[] buf)
public static java.lang.String toString(byte[] buf, int len)
public static java.lang.String toDecimalString(byte[] buf, int len)
public static final java.lang.String toHexString(byte[] data)
public static final byte[] fromHexString(java.lang.String val)
public static long readLong(java.io.InputStream rawStream, int numBytes) throws DataFormatException, java.io.IOException
rawStream
- stream to read fromnumBytes
- number of bytes to read and format into a number
DataFormatException
- if the stream doesn't contain a validly formatted number of that many bytes
java.io.IOException
- if there is an IO error reading the numberpublic static void writeLong(java.io.OutputStream rawStream, int numBytes, long value) throws DataFormatException, java.io.IOException
value
- value to write outrawStream
- stream to write tonumBytes
- number of bytes to write the number into (padding as necessary)
DataFormatException
- if the stream doesn't contain a validly formatted number of that many bytes
java.io.IOException
- if there is an IO error writing to the streampublic static byte[] toLong(int numBytes, long value) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void toLong(byte[] target, int offset, int numBytes, long value) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static long fromLong(byte[] src, int offset, int numBytes)
public static java.util.Date readDate(java.io.InputStream in) throws DataFormatException, java.io.IOException
in
- stream to read from
DataFormatException
- if the stream doesn't contain a validly formatted date
java.io.IOException
- if there is an IO error reading the datepublic static void writeDate(java.io.OutputStream out, java.util.Date date) throws DataFormatException, java.io.IOException
out
- stream to write todate
- date to write (can be null)
DataFormatException
- if the date is not valid
java.io.IOException
- if there is an IO error writing the datepublic static byte[] toDate(java.util.Date date) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void toDate(byte[] target, int offset, long when) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static java.util.Date fromDate(byte[] src, int offset) throws DataFormatException
DataFormatException
public static java.lang.String readString(java.io.InputStream in) throws DataFormatException, java.io.IOException
in
- stream to read from
DataFormatException
- if the stream doesn't contain a validly formatted string
java.io.IOException
- if there is an IO error reading the stringpublic static void writeString(java.io.OutputStream out, java.lang.String string) throws DataFormatException, java.io.IOException
out
- stream to write stringstring
- string to write out: null strings are perfectly valid, but strings of excess length will
cause a DataFormatException to be thrown
DataFormatException
- if the string is not valid
java.io.IOException
- if there is an IO error writing the stringpublic static java.lang.Boolean readBoolean(java.io.InputStream in) throws DataFormatException, java.io.IOException
in
- stream to read from
DataFormatException
- if the boolean is not valid
java.io.IOException
- if there is an IO error reading the booleanpublic static void writeBoolean(java.io.OutputStream out, java.lang.Boolean bool) throws DataFormatException, java.io.IOException
out
- stream to write tobool
- boolean value, or null
DataFormatException
- if the boolean is not valid
java.io.IOException
- if there is an IO error writing the booleanpublic static java.lang.Boolean fromBoolean(byte[] data, int offset)
public static void toBoolean(byte[] data, int offset, boolean value)
public static void toBoolean(byte[] data, int offset, java.lang.Boolean value)
public static final boolean eq(java.lang.Object lhs, java.lang.Object rhs)
public static final boolean eq(java.util.Collection lhs, java.util.Collection rhs)
public static final boolean eq(byte[] lhs, byte[] rhs)
public static final boolean eq(int lhs, int rhs)
public static final boolean eq(long lhs, long rhs)
public static final boolean eq(byte lhs, byte rhs)
public static final boolean eq(byte[] lhs, int offsetLeft, byte[] rhs, int offsetRight, int length)
public static final int compareTo(byte[] lhs, byte[] rhs)
public static final byte[] xor(byte[] lhs, byte[] rhs)
public static final void xor(byte[] lhs, int startLeft, byte[] rhs, int startRight, byte[] out, int startOut, int len)
lhs
- one of the source arraysstartLeft
- starting index in the lhs array to begin the xorrhs
- the other source arraystartRight
- starting index in the rhs array to begin the xorout
- output arraystartOut
- starting index in the out array to store the resultlen
- how many bytes into the various arrays to xorpublic static int hashCode(java.lang.Object obj)
public static int hashCode(java.util.Date obj)
public static int hashCode(byte[] b)
public static int hashCode(java.util.Collection col)
public static int read(java.io.InputStream in, byte[] target) throws java.io.IOException
java.io.IOException
public static int read(java.io.InputStream in, byte[] target, int offset, int length) throws java.io.IOException
java.io.IOException
public static java.lang.String readLine(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static java.lang.String readLine(java.io.InputStream in, Sha256Standalone hash) throws java.io.IOException
java.io.IOException
public static boolean readLine(java.io.InputStream in, java.lang.StringBuffer buf) throws java.io.IOException
java.io.IOException
public static boolean readLine(java.io.InputStream in, java.lang.StringBuffer buf, Sha256Standalone hash) throws java.io.IOException
java.io.IOException
public static void write(java.io.OutputStream out, byte[] data, Sha256Standalone hash) throws java.io.IOException
java.io.IOException
public static java.util.List sortStructures(java.util.Collection dataStructures)
public static java.lang.String formatDuration(long ms)
public static java.lang.String stripHTML(java.lang.String orig)
public static byte[] compress(byte[] orig)
public static byte[] compress(byte[] orig, int offset, int size)
public static byte[] decompress(byte[] orig) throws java.io.IOException
java.io.IOException
public static byte[] decompress(byte[] orig, int offset, int length) throws java.io.IOException
java.io.IOException
public static byte[] getUTF8(java.lang.String orig)
public static byte[] getUTF8(java.lang.StringBuffer orig)
public static java.lang.String getUTF8(byte[] orig)
public static java.lang.String getUTF8(byte[] orig, int offset, int len)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |