|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.io.Data
public final class Data
The class Data contains some useful static functions to manipulate data.
| Field Summary | |
|---|---|
static int |
BUFFER_SIZE
standard buffer size used (2048) |
static OutputStream |
SINK
implements an outputstream that writes nowhere |
| Method Summary | |
|---|---|
static byte[] |
asByteArray(InputStream stream)
transfers the given stream into a ByteArrayOutputStream and returns its embedded array; all streams will be closed. |
static int |
count(InputStream stream,
byte[] pattern)
returns how many times the given byte pattern occurs within the file |
static long |
countEqualBytes(InputStream stream1,
InputStream stream2)
returns the number of bytes that are equal in both streams; -1 is returned if both streams are equal until both ends. |
static long |
countEqualBytes(InputStream stream1,
InputStream stream2,
long maxBytes)
if maxBytes <=0, the streams are tested to their ends |
static long |
countEqualChars(Reader reader1,
Reader reader2)
returns the number of characters that are equal in both readers; -1 is returned if both readers are equal until both ends. |
static long |
countEqualChars(Reader reader1,
Reader reader2,
long maxChars)
if maxChars <=0, the readers are tested to their ends |
static void |
decodeBase64(InputStream in,
OutputStream out)
|
static byte[] |
decodeBase64(String s)
|
static Object |
deserialize(byte[] bytes)
de-serializes the given serialized bytes back to an object |
static byte[] |
digest(InputStream stream,
String algorithm)
returns a hashed value of the given stream based on the given algorithm |
static byte[] |
digestMD5(InputStream stream)
digests the stream using MD5 |
static byte[] |
digestSHA1(InputStream stream)
digests the stream using SHA1 |
static String |
encodeBase64(byte[] b)
|
static void |
encodeBase64(InputStream in,
OutputStream out)
|
static boolean |
equals(InputStream stream1,
InputStream stream2)
compares the content of the two streams and returns true only if both streams have equal content |
static boolean |
equals(InputStream stream1,
InputStream stream2,
long maxBytes)
compares the content of the two streams and returns true only if both streams have equal content for maxByte number of bytes. |
static String |
getConsoleInput()
reads a line from the console and returns the keyboard input as a string after 'Enter' was pressed |
static String |
getConsoleInput(String question)
prints the given question and returns getConsoleInput() |
static long |
getSerialVersionUID(Class c)
|
static long |
getSerialVersionUID(Object obj)
|
static int |
indexOf(byte[] source,
byte[] pattern)
returns indexOf(source, pattern, 0, source.length) |
static int |
indexOf(byte[] source1,
byte[] source2,
byte[] pattern)
searches for an occurrence of the given byte pattern only within the 'intersection' of the given two byte sources. |
static int |
indexOf(byte[] source,
byte[] pattern,
int beginIndex,
int endIndex)
searches for the first occurrence of the given byte pattern within the given byte source. |
static int |
indexOf(char[] source,
char[] pattern)
returns indexOf(source, pattern, 0, source.length) |
static int |
indexOf(char[] source1,
char[] source2,
char[] pattern)
searches for an occurrence of the given byte pattern only within the 'intersection' of the given two byte sources. |
static int |
indexOf(char[] source,
char[] pattern,
int beginIndex,
int endIndex)
searches for the first occurrence of the given character pattern within the given byte source. |
static long |
indexOf(InputStream in,
byte[] pattern)
|
static byte[] |
serialize(Object obj)
serializes the given object and returnes the serialized data as byte array |
static long |
transfer(InputStream from,
OutputStream to)
returns number of bytes transfered; closes both streams and flushes |
static long |
transfer(InputStream from,
OutputStream to,
boolean flushAndClose)
transfers the inputstream to the outputstream |
static long |
transfer(InputStream from,
OutputStream to,
byte[] buffer,
boolean flushAndClose)
transfers the inputstream to the outputstream |
static long |
transfer(InputStream from,
OutputStream to,
long maxBytes)
transfers the given number of bytes from one stream to the other |
static long |
transfer(InputStream from,
OutputStream to,
long maxBytes,
boolean flushAndClose)
|
static long |
transfer(InputStream from,
OutputStream to,
long maxBytes,
byte[] buffer,
boolean flushAndClose)
transfers the bytes from the given inputstream to the outputstream. |
static long |
transfer(Reader from,
Writer to)
transfers the reader to the writer. |
static long |
transfer(Reader from,
Writer to,
long maxChars,
char[] buffer,
boolean flushAndClose)
transfers the characters from the given reader to the writer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final OutputStream SINK
public static final int BUFFER_SIZE
| Method Detail |
|---|
public static String getConsoleInput()
public static String getConsoleInput(String question)
public static Object deserialize(byte[] bytes)
throws ClassNotFoundException,
IOException
ClassNotFoundException
IOException
public static byte[] serialize(Object obj)
throws IOException
obj - must be Serializable
IOException
public static byte[] digestMD5(InputStream stream)
throws IOException
IOExceptiondigest(java.io.InputStream, String)
public static byte[] digestSHA1(InputStream stream)
throws IOException
IOExceptiondigest(java.io.InputStream, String)
public static byte[] digest(InputStream stream,
String algorithm)
throws IOException,
NoSuchAlgorithmException
IOException
NoSuchAlgorithmException
public static int indexOf(byte[] source,
byte[] pattern)
indexOf(source, pattern, 0, source.length)
indexOf(byte[], byte[], int, int)
public static int indexOf(byte[] source,
byte[] pattern,
int beginIndex,
int endIndex)
source - a byte array containing the data that is searched for the
occurrence of a patternpattern - a (non-empty) byte array containing the search patternbeginIndex - the index to begin the pattern search within the source array
(between 0 and source pattern length and smaller than endIndex)endIndex - the index to end the pattern search within the source array
(between 0 and source pattern length and greater than beginIndex)
ArrayIndexOutOfBoundsException - if the parameter pattern is an
empty array
NullPointerException - if any of the given parameters are null
public static int indexOf(byte[] source1,
byte[] source2,
byte[] pattern)
ArrayIndexOutOfBoundsException - if the parameter pattern is an
empty array
NullPointerException - if any of the given parameters are nullindexOf(byte[], byte[])
public static int indexOf(char[] source,
char[] pattern)
indexOf(source, pattern, 0, source.length)
indexOf(char[], char[], int, int)
public static int indexOf(char[] source,
char[] pattern,
int beginIndex,
int endIndex)
source - a byte array containing the data that is searched for the
occurrence of a patternpattern - a (non-empty) character array containing the search patternbeginIndex - the index to begin the pattern search within the source array
(between 0 and source pattern length and smaller than endIndex)endIndex - the index to end the pattern search within the source array
(between 0 and source pattern length and greater than beginIndex)
ArrayIndexOutOfBoundsException - if the parameter pattern is an
empty array
NullPointerException - if any of the given parameters are null
public static int indexOf(char[] source1,
char[] source2,
char[] pattern)
ArrayIndexOutOfBoundsException - if the parameter pattern is an
empty array
NullPointerException - if any of the given parameters are nullindexOf(byte[], byte[])
public static long indexOf(InputStream in,
byte[] pattern)
throws IOException
IOException
public static long transfer(InputStream from,
OutputStream to)
throws IOException
IOException
public static long transfer(InputStream from,
OutputStream to,
boolean flushAndClose)
throws IOException
IOException
public static long transfer(InputStream from,
OutputStream to,
byte[] buffer,
boolean flushAndClose)
throws IOException
IOException
public static long transfer(InputStream from,
OutputStream to,
long maxBytes)
throws IOException
IOException
public static long transfer(InputStream from,
OutputStream to,
long maxBytes,
boolean flushAndClose)
throws IOException
IOException
public static long transfer(InputStream from,
OutputStream to,
long maxBytes,
byte[] buffer,
boolean flushAndClose)
throws IOException
from - the InputStream from which to read the datato - the OutputStream to which to write the databuffer - the byte buffer to be used; must have a length greater than zeroflushAndClose - if true, the method also flushes and closes both streamsmaxBytes - maximum number of bytes to be transfered;
if less than 1, the entire inputstream is transfered
IOException
public static long transfer(Reader from,
Writer to)
throws IOException
IOException
public static long transfer(Reader from,
Writer to,
long maxChars,
char[] buffer,
boolean flushAndClose)
throws IOException
from - the Reader from which to read the datato - the Writer to which to write the databuffer - the char buffer to be used; must have a length greater than zeroflushAndClose - if true, the method also flushes and closes both: reader and writermaxChars - maximum number of characters to be transfered;
if less than 1, the entire inputstream is transfered
IOException
public static byte[] asByteArray(InputStream stream)
throws IOException
IOException
public static boolean equals(InputStream stream1,
InputStream stream2)
throws IOException
IOException
public static boolean equals(InputStream stream1,
InputStream stream2,
long maxBytes)
throws IOException
IOException
public static int count(InputStream stream,
byte[] pattern)
throws IOException
IOException
public static long countEqualBytes(InputStream stream1,
InputStream stream2)
throws IOException
markSupported() method returns true on both streams,
the method uses the mark(int) method to allow to reset
both streams to the point where both streams were still equal;
otherwise, both streams have already read the first unequal byte when
the method returns - or they are at the end of one or both streams.
If both streams have equal content but one stream is longer than the other,
the length of the shorter stream is returned.
IOException
public static long countEqualBytes(InputStream stream1,
InputStream stream2,
long maxBytes)
throws IOException
IOException
public static long countEqualChars(Reader reader1,
Reader reader2)
throws IOException
markSupported() method returns true on both readers,
the method uses the mark(int) method to allow to reset
both readers to the point where both readers were still equal;
otherwise, both readers have already read the first unequal character when
the method returns - or they are at the end of one or both readers.
If both readers have equal content but one reader is longer than the other,
the length of the shorter reader is returned.
IOException
public static long countEqualChars(Reader reader1,
Reader reader2,
long maxChars)
throws IOException
IOException
public static void encodeBase64(InputStream in,
OutputStream out)
throws IOException
IOException
public static void decodeBase64(InputStream in,
OutputStream out)
throws IOException
IOExceptionpublic static String encodeBase64(byte[] b)
public static byte[] decodeBase64(String s)
throws IOException
IOExceptionpublic static long getSerialVersionUID(Object obj)
public static long getSerialVersionUID(Class c)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||