|
||||||||||
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
deprecated - used only in DatabaseLookupMessage |
static int |
BOOLEAN_LENGTH
Deprecated. unused |
static byte |
BOOLEAN_TRUE
deprecated - used only in DatabaseLookupMessage |
static byte |
BOOLEAN_UNKNOWN
Deprecated. unused |
static int |
DATE_LENGTH
|
static int |
MAX_COMPRESSION
|
static int |
NO_COMPRESSION
|
Constructor Summary | |
---|---|
DataHelper()
|
Method Summary | |
---|---|
static int |
compareTo(byte[] lhs,
byte[] rhs)
treat bytes as unsigned |
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[] |
compress(byte[] orig,
int offset,
int size,
int level)
|
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)
Deprecated. inefficient |
static boolean |
eq(Collection lhs,
Collection rhs)
Run a deep comparison across the two collections. |
static boolean |
eq(int lhs,
int rhs)
Deprecated. inefficient |
static boolean |
eq(long lhs,
long rhs)
Deprecated. inefficient |
static boolean |
eq(Object lhs,
Object rhs)
Helper util to compare two objects, including null handling. |
static String |
formatDuration(long ms)
|
static String |
formatSize(long bytes)
Caller should append 'B' or 'b' as appropriate |
static String |
formatSize2(long bytes)
Like formatSize but with a non-breaking space after the number Use only in HTML |
static Boolean |
fromBoolean(byte[] data,
int offset)
Deprecated. unused |
static Date |
fromDate(byte[] src,
int offset)
|
static byte[] |
fromHexString(String val)
|
static long |
fromLong(byte[] src,
int offset,
int numBytes)
|
static int |
fromProperties(byte[] source,
int offset,
Properties target)
Deprecated. unused |
static String |
getUTF8(byte[] orig)
|
static String |
getUTF8(byte[] orig,
int offset,
int len)
|
static byte[] |
getUTF8(String orig)
|
static byte[] |
getUTF8(StringBuffer orig)
|
static int |
hashCode(byte[] b)
Calculate the hashcode of the byte array, using 0 for null |
static int |
hashCode(Collection col)
Calculate the hashcode of the collection, using 0 for null |
static int |
hashCode(Date obj)
Calculate the hashcode of the date, using 0 for null |
static int |
hashCode(Object obj)
Calculate the hashcode of the object, using 0 for null |
static void |
loadProps(Properties props,
File file)
A more efficient Properties.load Some of the other differences: - This does not process or drop backslashes - '#' or ';' starts a comment line, but '!' does not - Leading whitespace is not trimmed - '=' is the only key-termination character (not ':' or whitespace) Note that the escaping of \r or \n was probably a mistake and should be taken out. |
static void |
loadProps(Properties props,
File file,
boolean forceLowerCase)
|
static void |
loadProps(Properties props,
InputStream inStr)
|
static void |
loadProps(Properties props,
InputStream inStr,
boolean forceLowerCase)
|
static int |
read(InputStream in,
byte[] target)
|
static int |
read(InputStream in,
byte[] target,
int offset,
int length)
|
static Boolean |
readBoolean(InputStream in)
Deprecated. unused |
static Date |
readDate(InputStream in)
Read in a date from the stream as specified by the I2P data structure spec. |
static String |
readLine(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 Warning - strips \n but not \r Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded |
static String |
readLine(InputStream in,
Sha256Standalone hash)
update the hash along the way Warning - strips \n but not \r Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded |
static boolean |
readLine(InputStream in,
StringBuffer buf)
Deprecated. use StringBuilder version |
static boolean |
readLine(InputStream in,
StringBuffer buf,
Sha256Standalone hash)
Deprecated. use StringBuilder version |
static boolean |
readLine(InputStream in,
StringBuilder buf)
Read in a line, placing it into the buffer (excluding the newline). |
static boolean |
readLine(InputStream in,
StringBuilder buf,
Sha256Standalone hash)
update the hash along the way Warning - strips \n but not \r Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded |
static long |
readLong(InputStream rawStream,
int numBytes)
Read the stream for an integer as defined by the I2P data structure specification. |
static Properties |
readProperties(InputStream rawStream)
Read a mapping from the stream, as defined by the I2P data structure spec, and store it into a Properties object. |
static String |
readString(InputStream in)
Read in a string from the stream as specified by the I2P data structure spec. |
static List<? extends DataStructure> |
sortStructures(Collection<? extends DataStructure> dataStructures)
Sort based on the Hash of the DataStructure Warning - relatively slow. |
static void |
storeProps(Properties props,
File file)
Writes the props to the file, unsorted (unless props is an OrderedProperties) Note that this does not escape the \r or \n that are unescaped in loadProps() above. |
static String |
stripHTML(String orig)
Strip out any HTML (simply removing any less than / greater than symbols) |
static void |
toBoolean(byte[] data,
int offset,
boolean value)
Deprecated. unused |
static void |
toBoolean(byte[] data,
int offset,
Boolean value)
Deprecated. unused |
static void |
toDate(byte[] target,
int offset,
long when)
|
static byte[] |
toDate(Date date)
|
static String |
toDecimalString(byte[] buf,
int len)
|
static 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,
Properties props)
|
static byte[] |
toProperties(Properties opts)
Deprecated. unused |
static String |
toString(byte[] buf)
|
static String |
toString(byte[] buf,
int len)
|
static String |
toString(Collection col)
Pretty print the collection |
static String |
toString(Properties options)
Pretty print the mapping, unsorted (unless the options param is an OrderedProperties) |
static void |
write(OutputStream out,
byte[] data,
Sha256Standalone hash)
|
static void |
writeBoolean(OutputStream out,
Boolean bool)
Deprecated. unused |
static void |
writeDate(OutputStream out,
Date date)
Write out a date to the stream as specified by the I2P data structure spec. |
static void |
writeLong(OutputStream rawStream,
int numBytes,
long value)
Write an integer as defined by the I2P data structure specification to the stream. |
static void |
writeProperties(OutputStream rawStream,
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 |
writeProperties(OutputStream rawStream,
Properties props,
boolean utf8)
Writes the props to the stream, sorted by property name. |
static void |
writeString(OutputStream out,
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
public static final int MAX_COMPRESSION
public static final int NO_COMPRESSION
Constructor Detail |
---|
public DataHelper()
Method Detail |
---|
public static Properties readProperties(InputStream rawStream) throws DataFormatException, IOException
rawStream
- stream to read the mapping from
DataFormatException
- if the format is invalid
IOException
- if there is a problem reading the datapublic static void writeProperties(OutputStream rawStream, Properties props) throws DataFormatException, IOException
rawStream
- stream to write toprops
- properties to write out
DataFormatException
- if either is too long.
DataFormatException
- if there is not enough valid data to write out
IOException
- if there is an IO error writing out the datapublic static void writeProperties(OutputStream rawStream, Properties props, boolean utf8) throws DataFormatException, IOException
DataFormatException
- if either is too long.
jrandom disabled UTF-8 in mid-2004, for performance reasons,
i.e. slow foo.getBytes("UTF-8")
Re-enable it so we can pass UTF-8 tunnel names through the I2CP SessionConfig.
Use utf8 = false for RouterAddress (fast, non UTF-8)
Use utf8 = true for SessionConfig (slow, UTF-8)
IOException
public static int toProperties(byte[] target, int offset, Properties props) throws DataFormatException, IOException
DataFormatException
IOException
public static int fromProperties(byte[] source, int offset, Properties target) throws DataFormatException, IOException
source
- sourcetarget
- returned Properties
DataFormatException
IOException
public static byte[] toProperties(Properties opts)
RuntimeException
- if either is too long.public static String toString(Properties options)
public static void loadProps(Properties props, File file) throws IOException
IOException
public static void loadProps(Properties props, File file, boolean forceLowerCase) throws IOException
IOException
public static void loadProps(Properties props, InputStream inStr) throws IOException
IOException
public static void loadProps(Properties props, InputStream inStr, boolean forceLowerCase) throws IOException
IOException
public static void storeProps(Properties props, File file) throws IOException
IOException
public static String toString(Collection col)
public static String toString(byte[] buf)
public static String toString(byte[] buf, int len)
public static String toDecimalString(byte[] buf, int len)
public static final String toHexString(byte[] data)
public static final byte[] fromHexString(String val)
public static long readLong(InputStream rawStream, int numBytes) throws DataFormatException, 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
IOException
- if there is an IO error reading the numberpublic static void writeLong(OutputStream rawStream, int numBytes, long value) throws DataFormatException, 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
IOException
- if there is an IO error writing to the streampublic static byte[] toLong(int numBytes, long value) throws IllegalArgumentException
IllegalArgumentException
public static void toLong(byte[] target, int offset, int numBytes, long value) throws IllegalArgumentException
IllegalArgumentException
public static long fromLong(byte[] src, int offset, int numBytes)
public static Date readDate(InputStream in) throws DataFormatException, IOException
in
- stream to read from
DataFormatException
- if the stream doesn't contain a validly formatted date
IOException
- if there is an IO error reading the datepublic static void writeDate(OutputStream out, Date date) throws DataFormatException, IOException
out
- stream to write todate
- date to write (can be null)
DataFormatException
- if the date is not valid
IOException
- if there is an IO error writing the datepublic static byte[] toDate(Date date) throws IllegalArgumentException
IllegalArgumentException
public static void toDate(byte[] target, int offset, long when) throws IllegalArgumentException
IllegalArgumentException
public static Date fromDate(byte[] src, int offset) throws DataFormatException
DataFormatException
public static String readString(InputStream in) throws DataFormatException, IOException
in
- stream to read from
DataFormatException
- if the stream doesn't contain a validly formatted string
IOException
- if there is an IO error reading the stringpublic static void writeString(OutputStream out, String string) throws DataFormatException, 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
IOException
- if there is an IO error writing the stringpublic static Boolean readBoolean(InputStream in) throws DataFormatException, IOException
in
- stream to read from
DataFormatException
- if the boolean is not valid
IOException
- if there is an IO error reading the booleanpublic static void writeBoolean(OutputStream out, Boolean bool) throws DataFormatException, IOException
out
- stream to write tobool
- boolean value, or null
DataFormatException
- if the boolean is not valid
IOException
- if there is an IO error writing the booleanpublic static Boolean fromBoolean(byte[] data, int offset)
public static void toBoolean(byte[] data, int offset, boolean value)
public static void toBoolean(byte[] data, int offset, Boolean value)
public static final boolean eq(Object lhs, Object rhs)
public static final boolean eq(Collection lhs, 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(Object obj)
public static int hashCode(Date obj)
public static int hashCode(byte[] b)
public static int hashCode(Collection col)
public static int read(InputStream in, byte[] target) throws IOException
IOException
public static int read(InputStream in, byte[] target, int offset, int length) throws IOException
IOException
public static String readLine(InputStream in) throws IOException
IOException
public static String readLine(InputStream in, Sha256Standalone hash) throws IOException
IOException
public static boolean readLine(InputStream in, StringBuffer buf) throws IOException
IOException
public static boolean readLine(InputStream in, StringBuffer buf, Sha256Standalone hash) throws IOException
IOException
public static boolean readLine(InputStream in, StringBuilder buf) throws IOException
IOException
public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException
IOException
public static void write(OutputStream out, byte[] data, Sha256Standalone hash) throws IOException
IOException
public static List<? extends DataStructure> sortStructures(Collection<? extends DataStructure> dataStructures)
public static String formatDuration(long ms)
public static String formatSize(long bytes)
public static String formatSize2(long bytes)
public static String stripHTML(String orig)
public static byte[] compress(byte[] orig)
public static byte[] compress(byte[] orig, int offset, int size)
public static byte[] compress(byte[] orig, int offset, int size, int level)
public static byte[] decompress(byte[] orig) throws IOException
IOException
public static byte[] decompress(byte[] orig, int offset, int length) throws IOException
IOException
public static byte[] getUTF8(String orig)
public static byte[] getUTF8(StringBuffer orig)
public static String getUTF8(byte[] orig)
public static String getUTF8(byte[] orig, int offset, int len)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |