saker.util Documentation TaskDoc JavaDoc Packages
public class StreamUtils
Utility class containing functions related to manipulating streams and related classes.
Fields
public static final int
The size of the allocated buffers for I/O operations if the caller didn't specify it.
Methods
public static ByteSink
Close protects the argument byte sink.
public static ByteSource
Close protects the argument byte source.
public static InputStream
Close protects the argument input stream.
public static OutputStream
Close protects the argument output stream.
public static long
Consumes the argument input stream by reading it until no more data is available.
public static long
consumeStream(InputStream in, byte[] consumebuffer)
Consumes the argument input stream by reading it until no more data is available, using the given buffer.
public static long
Copies the bytes from argument input to the specified output.
public static long
copyStream(InputStream in, DataOutput out, int buffersize)
Copies the bytes from argument input to the specified output using a buffer with the specified buffer size.
public static long
copyStream(InputStream in, DataOutput out, byte[] buffer)
Copies the bytes from argument input to the specified output using the specified buffer.
public static long
Copies the bytes from argument input to the specified output.
public static long
copyStream(InputStream in, OutputStream out, int buffersize)
Copies the bytes from argument input to the specified output using a buffer with the specified buffer size.
public static long
copyStream(InputStream in, OutputStream out, byte[] buffer)
Copies the bytes from argument input to the specified output using the specified buffer.
public static long
Copies the bytes from argument input and updates the given message digest with it.
public static long
copyStream(InputStream in, MessageDigest digest, int buffersize)
Copies the bytes from argument input and updates the given message digest with it using a buffer with the specified buffer size.
public static long
copyStream(InputStream in, MessageDigest digest, byte[] buffer)
Copies the bytes from argument input and updates the given message digest with it using the specified buffer.
public static long
Copies the bytes from argument input and updates the given signature with it.
public static long
copyStream(InputStream in, Signature signature, int buffersize)
Copies the bytes from argument input and updates the given signature with it using a buffer with the specified buffer size.
public static long
copyStream(InputStream in, Signature signature, byte[] buffer)
Copies the bytes from argument input and updates the given signature with it using the specified buffer.
public static ByteSink
Gets a byte sink that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static ByteSink
Gets a byte sink that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static ByteSource
Gets a byte source that forwards its calls to the argument, nd every method of it is locked using an internal Lock.
public static ByteSource
Gets a byte source that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static InputStream
Gets an input stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static InputStream
Gets an input stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static OutputStream
Gets an output stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static OutputStream
Gets an output stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
public static Appendable
Gets a null Appendable that throws away any data written to it.
public static ByteSink
Gets a null ByteSink that throws away any data written to it.
public static ByteSource
Gets a null ByteSource that never returns any data.
public static DataInput
Gets a null DataInput that never returns any data.
public static DataOutput
Gets a null DataOutput that throws away any data written to it.
public static InputStream
Gets a null InputStream that never returns any data.
public static ObjectInput
Gets a null ObjectInput that never returns any data.
public static ObjectOutput
Gets a null ObjectOutput that throws away any data written to it.
public static OutputStream
Gets a null OutputStream that throws away any data written to it.
public static PrintStream
Gets a null PrintStream that throws away any data written to it.
public static PrintWriter
Gets a null PrintWriter that throws away any data written to it.
public static Readable
Gets a null Readable that never returns any data.
public static Reader
Gets a null Reader that never returns any data.
public static Writer
Gets a null Writer that throws away any data written to it.
public static int
Reads bytes from the input into the argument buffer until either the buffer is filled, or no more bytes are available.
public static int
readFillObjectInputBytes(ObjectInput in, byte[] buffer, int offset, int length)
Reads bytes from the input into the argument buffer with the given range until either the range is filled, or no more bytes are available.
public static int
readFillSourceBytes(ByteSource in, byte[] buffer)
Reads bytes from the input into the argument buffer until either the buffer is filled, or no more bytes are available.
public static int
readFillSourceBytes(ByteSource in, byte[] buffer, int offset, int length)
Reads bytes from the input into the argument buffer with the given range until either the range is filled, or no more bytes are available.
public static int
readFillStreamBytes(InputStream in, byte[] buffer)
Reads bytes from the input into the argument buffer until either the buffer is filled, or no more bytes are available.
public static int
readFillStreamBytes(InputStream in, byte[] buffer, int offset, int length)
Reads bytes from the input into the argument buffer with the given range until either the range is filled, or no more bytes are available.
public static int
Reads bytes from the given input and puts then into the argument buffer.
public static int
Reads bytes from the given input and puts then into the argument buffer.
public static CharSequence
Reads the argument readable input fully, and returns the read characters as a CharSequence.
public static String
Reads the argument readable input fully, and returns the read characters as a String.
public static byte[]
Reads exactly the specified number of bytes from the given input or throws an EOFException if failed.
public static void
Reads the argument buffer fully or throws an EOFException if not enough bytes are available.
public static void
readSourceBytesExactly(ByteSource in, byte[] buffer, int offset, int length)
Reads exactly the specified number of bytes into the argument buffer with the given offset or throws an EOFException if not enough bytes are available.
public static ByteArrayRegion
Reads the argument input fully, and returns the read bytes.
public static String
Reads the argument input fully, and decodes the bytes using UTF-8.
public static String
Reads the argument input fully, and decodes the bytes using the given charset.
public static byte[]
Reads exactly the specified number of bytes from the given input or throws an EOFException if not enough bytes are available.
public static void
Reads the argument buffer fully or throws an EOFException if not enough bytes are available.
public static void
readStreamBytesExactly(InputStream in, byte[] buffer, int offset, int length)
Reads exactly the specified number of bytes into the argument buffer with the given offset or throws an EOFException if not enough bytes are available.
public static ByteArrayRegion
Reads the argument input fully, and returns the read bytes.
public static String
Reads the argument input fully, and decodes the bytes using UTF-8.
public static String
Reads the argument input fully, and decodes the bytes using the given charset.
public static long
Skips the specified number of bytes from the input by reading the given number of bytes from it.
public static void
Skips the argument number of bytes from the given input, throwing an EOFException if the operation fails.
public static long
Skips the specified number of bytes from the input by reading the given number of bytes from it.
public static void
Skips the argument number of bytes from the given input, throwing an EOFException if the operation fails.
public static ByteSink
Gets a byte sink that forwards its calls to the argument, and every method of it is synchronized on this.
public static ByteSink
Gets a byte sink that forwards its calls to the argument, and every method of it is synchronized on this.
public static ByteSource
Gets a byte source that forwards its calls to the argument, and every method of it is synchronized on this.
public static ByteSource
Gets a byte source that forwards its calls to the argument, and every method of it is synchronized on this.
public static InputStream
Gets an input stream that forwards its calls to the argument, and every method of it is synchronized on this.
public static InputStream
Gets an input stream that forwards its calls to the argument, and every method of it is synchronized on this.
public static OutputStream
Gets an output stream that forwards its calls to the argument, and every method of it is synchronized on this.
public static OutputStream
Gets an output stream that forwards its calls to the argument, and every method of it is synchronized on this.
public static ByteSink
Converts the argument DataOutput to a ByteSink.
public static ByteSink
Converts the argument MessageDigest to an ByteSink.
public static ByteSink
Converts the argument Signature to a ByteSink.
public static ByteSink
Converts the argument Mac to an ByteSink.
public static InputStream
Converts the argument ObjectInput to an InputStream.
public static OutputStream
Converts the argument ObjectOutput to an OutputStream.
public static OutputStream
Converts the argument MessageDigest to an OutputStream.
public static OutputStream
Converts the argument Signature to an OutputStream.
public static OutputStream
Converts the argument Mac to an OutputStream.
public static final int DEFAULT_BUFFER_SIZE = 8192
The size of the allocated buffers for I/O operations if the caller didn't specify it.
Close protects the argument byte sink.

Calling ByteSink.close() on the returned sink will not close the argument sink.

outThe byte sink.
The close protected sink, or null if the argument is null.
Close protects the argument byte source.

Calling ByteSource.close() on the returned source will not close the argument source.

inThe byte source.
The close protected source, or null if the argument is null.
Close protects the argument input stream.

Calling InputStream.close() on the returned stream will not close the argument stream.

inThe input stream.
The close protected stream, or null if the argument is null.
Close protects the argument output stream.

Calling OutputStream.close() on the returned stream will not close the argument stream.

outThe output stream.
The close protected stream, or null if the argument is null.
Consumes the argument input stream by reading it until no more data is available.

An internal work buffer is allocated with the size of DEFAULT_BUFFER_SIZE.

inThe input.
The number of bytes consumed from the stream.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the argument is null.
public static long consumeStream(InputStream in, byte[] consumebuffer) throws IOException, NullPointerException
Consumes the argument input stream by reading it until no more data is available, using the given buffer.

The method will use the argument buffer to read the input to it. It is recommended that callers do not share the argument buffer for concurrent readings.

inThe input.
consumebufferThe work buffer to use.
The number of bytes consumed from the stream.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Copies the bytes from argument input to the specified output.

A buffer with the size of DEFAULT_BUFFER_SIZE will be allocated for copying.

inThe input to copy.
outThe output to write the bytes.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
public static long copyStream(InputStream in, DataOutput out, int buffersize) throws IOException, NullPointerException, NegativeArraySizeException
Copies the bytes from argument input to the specified output using a buffer with the specified buffer size.
inThe input to copy.
outThe output to write the bytes.
buffersizeThe size of the buffer to allocate for copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
NegativeArraySizeExceptionIf the buffer size is negative.
public static long copyStream(InputStream in, DataOutput out, byte[] buffer) throws IOException, NullPointerException
Copies the bytes from argument input to the specified output using the specified buffer.
inThe input to copy.
outThe output to write the bytes.
bufferThe buffer to use when copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Copies the bytes from argument input to the specified output.

A buffer with the size of DEFAULT_BUFFER_SIZE will be allocated for copying.

inThe input to copy.
outThe output to write the bytes.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Copies the bytes from argument input to the specified output using a buffer with the specified buffer size.
inThe input to copy.
outThe output to write the bytes.
buffersizeThe size of the buffer to allocate for copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
NegativeArraySizeExceptionIf the buffer size is negative.
public static long copyStream(InputStream in, OutputStream out, byte[] buffer) throws IOException, NullPointerException
Copies the bytes from argument input to the specified output using the specified buffer.
inThe input to copy.
outThe output to write the bytes.
bufferThe buffer to use when copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
public static long copyStream(InputStream in, MessageDigest digest) throws IOException, NullPointerException
Copies the bytes from argument input and updates the given message digest with it.

A buffer with the size of DEFAULT_BUFFER_SIZE will be allocated for copying.

inThe input to copy.
digestThe digest to update with the bytes.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
public static long copyStream(InputStream in, MessageDigest digest, int buffersize) throws IOException, NullPointerException, NegativeArraySizeException
Copies the bytes from argument input and updates the given message digest with it using a buffer with the specified buffer size.
inThe input to copy.
digestThe digest to update with the bytes.
buffersizeThe size of the buffer to allocate for copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
NegativeArraySizeExceptionIf the buffer size is negative.
public static long copyStream(InputStream in, MessageDigest digest, byte[] buffer) throws IOException, NullPointerException
Copies the bytes from argument input and updates the given message digest with it using the specified buffer.
inThe input to copy.
digestThe digest to update with the bytes.
bufferThe buffer to use when copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Copies the bytes from argument input and updates the given signature with it.

A buffer with the size of DEFAULT_BUFFER_SIZE will be allocated for copying.

inThe input to copy.
signatureThe signature to update with the bytes.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
SignatureExceptionIf the updating of the signature fails.
Copies the bytes from argument input and updates the given signature with it using a buffer with the specified buffer size.
inThe input to copy.
signatureThe signature to update with the bytes.
buffersizeThe size of the buffer to allocate for copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
NegativeArraySizeExceptionIf the buffer size is negative.
SignatureExceptionIf the updating of the signature fails.
public static long copyStream(InputStream in, Signature signature, byte[] buffer) throws IOException, NullPointerException, SignatureException
Copies the bytes from argument input and updates the given signature with it using the specified buffer.
inThe input to copy.
signatureThe signature to update with the bytes.
bufferThe buffer to use when copying.
The number of bytes copied.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
SignatureExceptionIf the updating of the signature fails.
Gets a byte sink that forwards its calls to the argument, and every method of it is locked using an internal Lock.
outThe output stream.
The locked byte sink, or null if the argument is null.
saker.util 0.8.2
public static ByteSink lockedByteSink(ByteSink out)
Gets a byte sink that forwards its calls to the argument, and every method of it is locked using an internal Lock.
outThe byte sink.
The locked byte sink, or null if the argument is null.
saker.util 0.8.2
Gets a byte source that forwards its calls to the argument, nd every method of it is locked using an internal Lock.
inThe input stream.
The locked byte source, or null if the argument is null.
saker.util 0.8.2
Gets a byte source that forwards its calls to the argument, and every method of it is locked using an internal Lock.
inThe byte source.
The locked byte source, or null if the argument is null.
saker.util 0.8.2
Gets an input stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
inThe input stream.
The locked input stream, or null if the argument is null.
saker.util 0.8.2
Gets an input stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
inThe byte source.
The locked input stream, or null if the argument is null.
saker.util 0.8.2
Gets an output stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
outThe output stream.
The locked output stream, or null if the argument is null.
saker.util 0.8.2
Gets an output stream that forwards its calls to the argument, and every method of it is locked using an internal Lock.
outThe byte sink.
The locked output stream, or null if the argument is null.
saker.util 0.8.2
public static Appendable nullAppendable()
Gets a null Appendable that throws away any data written to it.
The appendable.
public static ByteSink nullByteSink()
Gets a null ByteSink that throws away any data written to it.
The byte sink.
public static ByteSource nullByteSource()
Gets a null ByteSource that never returns any data.
The byte source.
public static DataInput nullDataInput()
Gets a null DataInput that never returns any data.
The data input.
public static DataOutput nullDataOutput()
Gets a null DataOutput that throws away any data written to it.
The data output.
Gets a null InputStream that never returns any data.
The input stream.
Gets a null ObjectInput that never returns any data.
The object input.
Gets a null ObjectOutput that throws away any data written to it.
The object output.
Gets a null OutputStream that throws away any data written to it.
The output stream.
Gets a null PrintStream that throws away any data written to it.
The stream.
Gets a null PrintWriter that throws away any data written to it.
The writer.
public static Readable nullReadable()
Gets a null Readable that never returns any data.
The readable.
public static Reader nullReader()
Gets a null Reader that never returns any data.
The reader.
public static Writer nullWriter()
Gets a null Writer that throws away any data written to it.
The writer.
public static int readFillObjectInputBytes(ObjectInput in, byte[] buffer) throws IOException, NullPointerException
Reads bytes from the input into the argument buffer until either the buffer is filled, or no more bytes are available.

This method works like readStreamBytesExactly(InputStream, byte[]), but doesn't throw an EOFException if not enough bytes are available to fill the buffer, just returns.

inThe input.
bufferThe buffer to put the read bytes in.
The number of bytes read.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input or the buffer is null.
public static int readFillObjectInputBytes(ObjectInput in, byte[] buffer, int offset, int length) throws IOException, NullPointerException, IndexOutOfBoundsException
Reads bytes from the input into the argument buffer with the given range until either the range is filled, or no more bytes are available.

This method works like readStreamBytesExactly(InputStream, byte[]), but doesn't throw an EOFException if not enough bytes are available to fill the buffer, just returns.

inThe input.
bufferThe buffer to put the read bytes in.
offsetThe offset index at which to start putting the bytes. (inclusive)
lengthThe number of bytes to read.
The number of bytes read.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input or the buffer is null.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
public static int readFillSourceBytes(ByteSource in, byte[] buffer) throws IOException, NullPointerException
Reads bytes from the input into the argument buffer until either the buffer is filled, or no more bytes are available.

This method works like readStreamBytesExactly(InputStream, byte[]), but doesn't throw an EOFException if not enough bytes are available to fill the buffer, just returns.

inThe input.
bufferThe buffer to put the read bytes in.
The number of bytes read.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input or the buffer is null.
public static int readFillSourceBytes(ByteSource in, byte[] buffer, int offset, int length) throws IOException, NullPointerException, IndexOutOfBoundsException
Reads bytes from the input into the argument buffer with the given range until either the range is filled, or no more bytes are available.

This method works like readStreamBytesExactly(InputStream, byte[]), but doesn't throw an EOFException if not enough bytes are available to fill the buffer, just returns.

inThe input.
bufferThe buffer to put the read bytes in.
offsetThe offset index at which to start putting the bytes. (inclusive)
lengthThe number of bytes to read.
The number of bytes read.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input or the buffer is null.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
public static int readFillStreamBytes(InputStream in, byte[] buffer) throws IOException, NullPointerException
Reads bytes from the input into the argument buffer until either the buffer is filled, or no more bytes are available.

This method works like readStreamBytesExactly(InputStream, byte[]), but doesn't throw an EOFException if not enough bytes are available to fill the buffer, just returns.

inThe input.
bufferThe buffer to put the read bytes in.
The number of bytes read.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input or the buffer is null.
public static int readFillStreamBytes(InputStream in, byte[] buffer, int offset, int length) throws IOException, NullPointerException, IndexOutOfBoundsException
Reads bytes from the input into the argument buffer with the given range until either the range is filled, or no more bytes are available.

This method works like readStreamBytesExactly(InputStream, byte[]), but doesn't throw an EOFException if not enough bytes are available to fill the buffer, just returns.

inThe input.
bufferThe buffer to put the read bytes in.
offsetThe offset index at which to start putting the bytes. (inclusive)
lengthThe number of bytes to read.
The number of bytes read.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input or the buffer is null.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
Reads bytes from the given input and puts then into the argument buffer.

This method will efficiently handle the case when the buffer is an instance of ByteArrayRegion, and read directly into the backing array.

In other cases it will allocate a work buffer that will serve as a temporary work memory region. It will be lated put into the argument buffer via ByteRegion.put(int, ByteArrayRegion).

inThe input.
bufferThe buffer to read into.
The number of bytes read into the buffer.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Reads bytes from the given input and puts then into the argument buffer.

This method will efficiently handle the case when the buffer is an instance of ByteArrayRegion, and read directly into the backing array.

In other cases it will allocate a work buffer that will serve as a temporary work memory region. It will be lated put into the argument buffer via ByteRegion.put(int, ByteArrayRegion).

inThe input.
bufferThe buffer to read into.
The number of bytes read into the buffer.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Reads the argument readable input fully, and returns the read characters as a CharSequence.
inThe input.
The read char sequence.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads the argument readable input fully, and returns the read characters as a String.

This method is the same as readReadableCharSequenceFully(Readable), but calls CharSequence.toString() on the result.

inThe input.
The read string.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads exactly the specified number of bytes from the given input or throws an EOFException if failed.

Warning: If the argument input is capable of blocking, this method may never return unless external intervention is made. If less than count bytes are available when this method is called, the reading will block, until either more bytes, or no more are available.

E.g. in case of a network TCP stream, if one wants to read 10 bytes, and only 5 is available right now, this method will block, until the other endpoint of the connection sends 5 more bytes, or the connection is closed.

inThe input.
countThe number of bytes to read.
The read bytes.
IOExceptionIn case of I/O error.
EOFExceptionIf not enough bytes are available from the input.
NegativeArraySizeExceptionIf the specified number of bytes to read is neagive.
NullPointerExceptionIf the input is null.
public static void readSourceBytesExactly(ByteSource in, byte[] buffer) throws IOException, EOFException, NullPointerException
Reads the argument buffer fully or throws an EOFException if not enough bytes are available.

Warning: If the argument input is capable of blocking, this method may never return unless external intervention is made. If less than buffer.length bytes are available when this method is called, the reading will block, until either more bytes, or no more are available.

E.g. in case of a network TCP stream, if one wants to read 10 bytes, and only 5 is available right now, this method will block, until the other endpoint of the connection sends 5 more bytes, or the connection is closed.

inThe input.
bufferThe buffer to put the read bytes in.
IOExceptionIn case of I/O error.
EOFExceptionIf not enough bytes are available from the input.
NullPointerExceptionIf the input or the buffer is null.
public static void readSourceBytesExactly(ByteSource in, byte[] buffer, int offset, int length) throws IOException, EOFException, NullPointerException, IndexOutOfBoundsException
Reads exactly the specified number of bytes into the argument buffer with the given offset or throws an EOFException if not enough bytes are available.

Warning: If the argument input is capable of blocking, this method may never return unless external intervention is made. If less than count bytes are available when this method is called, the reading will block, until either more bytes, or no more are available.

E.g. in case of a network TCP stream, if one wants to read 10 bytes, and only 5 is available right now, this method will block, until the other endpoint of the connection sends 5 more bytes, or the connection is closed.

inThe input.
bufferThe buffer to put the read bytes in.
offsetThe offset index at which to start putting the bytes. (inclusive)
lengthThe number of bytes to read.
IOExceptionIn case of I/O error.
EOFExceptionIf not enough bytes are available from the input.
NullPointerExceptionIf the input or the buffer is null.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
Reads the argument input fully, and returns the read bytes.
inThe input.
The read bytes.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads the argument input fully, and decodes the bytes using UTF-8.
inThe input.
The decoded string.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads the argument input fully, and decodes the bytes using the given charset.
inThe input.
charsetThe charset to use when decoding the bytes.
The decoded string.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
Reads exactly the specified number of bytes from the given input or throws an EOFException if not enough bytes are available.

Warning: If the argument input is capable of blocking, this method may never return unless external intervention is made. If less than count bytes are available when this method is called, the reading will block, until either more bytes, or no more are available.

E.g. in case of a network TCP stream, if one wants to read 10 bytes, and only 5 is available right now, this method will block, until the other endpoint of the connection sends 5 more bytes, or the connection is closed.

inThe input.
countThe number of bytes to read.
The read bytes.
IOExceptionIn case of I/O error.
EOFExceptionIf not enough bytes are available from the input.
NegativeArraySizeExceptionIf the specified number of bytes to read is neagive.
NullPointerExceptionIf the input is null.
public static void readStreamBytesExactly(InputStream in, byte[] buffer) throws IOException, EOFException, NullPointerException
Reads the argument buffer fully or throws an EOFException if not enough bytes are available.

Warning: If the argument input is capable of blocking, this method may never return unless external intervention is made. If less than buffer.length bytes are available when this method is called, the reading will block, until either more bytes, or no more are available.

E.g. in case of a network TCP stream, if one wants to read 10 bytes, and only 5 is available right now, this method will block, until the other endpoint of the connection sends 5 more bytes, or the connection is closed.

inThe input.
bufferThe buffer to put the read bytes in.
IOExceptionIn case of I/O error.
EOFExceptionIf not enough bytes are available from the input.
NullPointerExceptionIf the input or the buffer is null.
public static void readStreamBytesExactly(InputStream in, byte[] buffer, int offset, int length) throws IOException, EOFException, NullPointerException, IndexOutOfBoundsException
Reads exactly the specified number of bytes into the argument buffer with the given offset or throws an EOFException if not enough bytes are available.

Warning: If the argument input is capable of blocking, this method may never return unless external intervention is made. If less than count bytes are available when this method is called, the reading will block, until either more bytes, or no more are available.

E.g. in case of a network TCP stream, if one wants to read 10 bytes, and only 5 is available right now, this method will block, until the other endpoint of the connection sends 5 more bytes, or the connection is closed.

inThe input.
bufferThe buffer to put the read bytes in.
offsetThe offset index at which to start putting the bytes. (inclusive)
lengthThe number of bytes to read.
IOExceptionIn case of I/O error.
EOFExceptionIf not enough bytes are available from the input.
NullPointerExceptionIf the input or the buffer is null.
IndexOutOfBoundsExceptionIf the specified range is out of bounds.
Reads the argument input fully, and returns the read bytes.
inThe input.
The read bytes.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads the argument input fully, and decodes the bytes using UTF-8.
inThe input.
The decoded string.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Reads the argument input fully, and decodes the bytes using the given charset.
inThe input.
charsetThe charset to use when decoding the bytes.
The decoded string.
IOExceptionIn case of I/O error.
NullPointerExceptionIf any of the arguments are null.
public static long skipSourceByReading(ByteSource in, long n) throws IOException, NullPointerException
Skips the specified number of bytes from the input by reading the given number of bytes from it.

This method will always read the bytes from the input, and never calls ByteSource.skip(long).

If the number of bytes to skip is zero or negative, this method will always succeed and return 0.

inThe input.
nThe number of bytes to skip.
The actual number of bytes skipped.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Skips the argument number of bytes from the given input, throwing an EOFException if the operation fails.

This method will try to skip the given number amount of bytes. It will first try to use the ByteSource.skip(long) method. If that returns zero or negative, then the method will try to directly read bytes from the input into an allocated work buffer. If after all not enough bytes are skipped, an EOFException will be thrown with a message containing the remaining amount of bytes.

If the number of bytes to skip is zero or negative, this method will always succeed.

inThe input.
nThe number of bytes to skip.
IOExceptionIn case of I/O error.
EOFExceptionIf the method failed to skip over the specified number of bytes.
NullPointerExceptionIf the input is null.
public static long skipStreamByReading(InputStream in, long n) throws IOException, NullPointerException
Skips the specified number of bytes from the input by reading the given number of bytes from it.

This method will always read the bytes from the input, and never calls InputStream.skip(long).

If the number of bytes to skip is zero or negative, this method will always succeed and return 0.

inThe input.
nThe number of bytes to skip.
The actual number of bytes skipped.
IOExceptionIn case of I/O error.
NullPointerExceptionIf the input is null.
Skips the argument number of bytes from the given input, throwing an EOFException if the operation fails.

This method will try to skip the given number amount of bytes. It will first try to use the InputStream.skip(long) method. If that returns zero or negative, then the method will try to directly read bytes from the input into an allocated work buffer. If after all not enough bytes are skipped, an EOFException will be thrown with a message containing the remaining amount of bytes.

If the number of bytes to skip is zero or negative, this method will always succeed.

inThe input.
nThe number of bytes to skip.
IOExceptionIn case of I/O error.
EOFExceptionIf the method failed to skip over the specified number of bytes.
NullPointerExceptionIf the input is null.
Gets a byte sink that forwards its calls to the argument, and every method of it is synchronized on this.
outThe output stream.
The synchronized byte sink, or null if the argument is null.
Gets a byte sink that forwards its calls to the argument, and every method of it is synchronized on this.
outThe byte sink.
The synchronized byte sink, or null if the argument is null.
Gets a byte source that forwards its calls to the argument, and every method of it is synchronized on this.
inThe input stream.
The synchronized byte source, or null if the argument is null.
Gets a byte source that forwards its calls to the argument, and every method of it is synchronized on this.
inThe byte source.
The synchronized byte source, or null if the argument is null.
Gets an input stream that forwards its calls to the argument, and every method of it is synchronized on this.
inThe input stream.
The synchronized input stream, or null if the argument is null.
Gets an input stream that forwards its calls to the argument, and every method of it is synchronized on this.
inThe byte source.
The synchronized input stream, or null if the argument is null.
Gets an output stream that forwards its calls to the argument, and every method of it is synchronized on this.
outThe output stream.
The synchronized output stream, or null if the argument is null.
Gets an output stream that forwards its calls to the argument, and every method of it is synchronized on this.
outThe byte sink.
The synchronized output stream, or null if the argument is null.
Converts the argument DataOutput to a ByteSink.

Closing the returned sink will not close the data output. (As the DataOutput interface doesn't extends Closeable.)

This method is similar to ByteSink.valueOf methods, but works in a different way, therefore it was included in this utility class instead of the ByteSink interface.

osThe data output.
A byte sink that uses the argument data output, or null if the argument is null.
NullPointerExceptionIf the argument is null.
public static ByteSink toByteSink(MessageDigest digest)
Converts the argument MessageDigest to an ByteSink.

All the bytes written to the byte sink will result in a call to MessageDigest.update(byte[], int, int) or related methods.

Closing the returned sink will have no effect on the argument message digest.

digestThe message digest.
The digest as a byte sink, or null if the argument is null.
public static ByteSink toByteSink(Signature signature)
Converts the argument Signature to a ByteSink.

All the bytes written to the output stream will result in a call to Signature.update(byte[], int, int) or related methods.

Closing the returned stream will have no effect on the argument signature object.

Any SignatureExceptions thrown by the argument will be wrapped in an IOException.

signatureThe signature.
The signature as a byte sink, or null if the argument is null.
public static ByteSink toByteSink(Mac mac)
Converts the argument Mac to an ByteSink.

All the bytes written to the byte sink will result in a call to Mac.update(byte[], int, int) or related methods.

Closing the returned sink will have no effect on the argument Mac.

macThe mac.
The mac as a byte sink, or null if the argument is null.
Converts the argument ObjectInput to an InputStream.

If the argument is already an instace of InputStream, it will be simply returned.

Closing the returned stream will close the argument object input.

inputThe object input.
The input stream backed by the argument input, or null if the argument is null.
Converts the argument ObjectOutput to an OutputStream.

If the argument is already an instace of OutputStream, it will be simply returned.

Closing the returned stream will close the argument object output.

outputThe object output.
The output stream backed by the argument output, or null if the argument is null.
Converts the argument MessageDigest to an OutputStream.

All the bytes written to the output stream will result in a call to MessageDigest.update(byte[], int, int) or related methods.

Closing the returned stream will have no effect on the argument message digest.

digestThe message digest.
The digest as an output stream, or null if the argument is null.
public static OutputStream toOutputStream(Signature signature)
Converts the argument Signature to an OutputStream.

All the bytes written to the output stream will result in a call to Signature.update(byte[], int, int) or related methods.

Closing the returned stream will have no effect on the argument signature object.

Any SignatureExceptions thrown by the argument will be relayed in an IOException.

signatureThe signature.
The signature as an output stream, or null if the argument is null.
public static OutputStream toOutputStream(Mac mac)
Converts the argument Mac to an OutputStream.

All the bytes written to the output stream will result in a call to Mac.update(byte[], int, int) or related methods.

Closing the returned stream will have no effect on the argument Mac.

macThe mac.
The mac as an output stream, or null if the argument is null.