saker.util Documentation TaskDoc JavaDoc Packages
public class DataOutputUnsyncByteArrayOutputStream extends UnsyncByteArrayOutputStream implements DataOutputByteSink
UnsyncByteArrayOutputStream subclass that also implements DataOutput to write binary formatted data to the output buffer.
Constructors
public
Creates a new instance with the default buffer size.
public
Creates a new instance with the argument buffer size.
public
Creates a new instance that is directly backed by the argument buffer, and currently contains count number of valid bytes.
Methods
public final void
replaceInt(int v, int offset)
Replaces an int in the stream at the given offset.
public final void
write(char[] b)
Writes an array of chars to the stream.
public final void
write(char[] b, int offset, int length)
Writes a range of chars from the specified array to the stream.
public final void
write(double[] b)
Writes an array of doubles to the stream.
public final void
write(double[] b, int offset, int length)
Writes a range of doubles from the specified array to the stream.
public final void
write(float[] b)
Writes an array of floats to the stream.
public final void
write(float[] b, int offset, int length)
Writes a range of floats from the specified array to the stream.
public final void
write(int[] b)
Writes an array of ints to the stream.
public final void
write(int[] b, int offset, int length)
Writes a range of ints from the specified array to the stream.
public final void
write(long[] b)
Writes an array of longs to the stream.
public final void
write(long[] b, int offset, int length)
Writes a range of longs from the specified array to the stream.
public final void
write(short[] b)
Writes an array of shorts to the stream.
public final void
write(short[] b, int offset, int length)
Writes a range of shorts from the specified array to the stream.
public final void
write(boolean[] b)
Writes an array of booleans to the stream.
public final void
write(boolean[] b, int offset, int length)
Writes a range of booleans from the specified array to the stream.
public final void
writeBoolean(boolean v)
Writes a boolean value to this output stream.
public final void
writeByte(int v)
Writes to the output stream the eight low- order bits of the argument v.
public final void
Writes a string to the output stream.
public final void
writeChar(char v)
Same as writeChar(int), but takes a char parameter.
public final void
writeChar(int v)
Writes a char value, which is comprised of two bytes, to the output stream.
public final void
Writes the characters in the argument sequence to the stream.
public final void
Writes every character in the string s, to the output stream, in order, two bytes per character.
public final void
writeDouble(double v)
Writes a double value, which is comprised of eight bytes, to the output stream.
public final void
writeFloat(float v)
Writes a float value, which is comprised of four bytes, to the output stream.
public final void
writeInt(int v)
Writes an int value, which is comprised of four bytes, to the output stream.
public final void
writeLong(long v)
Writes a long value, which is comprised of eight bytes, to the output stream.
public final void
writeShort(int v)
Writes two bytes to the output stream to represent the value of the argument.
public final void
writeShort(short v)
Same as writeShort(int), but takes a short parameter.
public final void
Writes the number of characters and the actual characters to the stream.
public final void
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s.
Creates a new instance with the argument buffer size.
sizeThe size.
NegativeArraySizeExceptionIf the size is negative.
Creates a new instance that is directly backed by the argument buffer, and currently contains count number of valid bytes.

If more bytes are written to the stream, it may grow accordingly.

bufThe backing buffer.
countThe number of valid bytes in the buffer.
IllegalArgumentExceptionIf the count is negative, or greater than the buffer length.
public final void replaceInt(int v, int offset)
Replaces an int in the stream at the given offset.

The capacity and the size of the stream is modified accordingly, so the offset will always point to a valid region. The buffer size and the valid number of bytes will be the maximum of the current size, and offset + 4.

The replaced int is in the same format as writeInt(int).

vThe int to write at the given offset.
offsetThe offset at which the underlying byte array should be modified.
public final void write(char[] b) throws NullPointerException
Writes an array of chars to the stream.

The chars will be written in the same format as writeChar(char).

bThe array of chars.
NullPointerExceptionIf the array is null.
public final void write(char[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of chars from the specified array to the stream.

The chars will be written in the same format as writeChar(char).

bThe array of chars.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void write(double[] b) throws NullPointerException
Writes an array of doubles to the stream.

The doubles will be written in the same format as writeDouble(double).

bThe array of doubles.
NullPointerExceptionIf the array is null.
public final void write(double[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of doubles from the specified array to the stream.

The doubles will be written in the same format as writeDouble(double).

bThe array of doubles.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void write(float[] b) throws NullPointerException
Writes an array of floats to the stream.

The floats will be written in the same format as writeFloat(float).

bThe array of floats.
NullPointerExceptionIf the array is null.
public final void write(float[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of floats from the specified array to the stream.

The floats will be written in the same format as writeFloat(float).

bThe array of floats.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void write(int[] b) throws NullPointerException
Writes an array of ints to the stream.

The ints will be written in the same format as writeInt(int).

bThe array of ints.
NullPointerExceptionIf the array is null.
public final void write(int[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of ints from the specified array to the stream.

The ints will be written in the same format as writeInt(int).

bThe array of ints.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void write(long[] b) throws NullPointerException
Writes an array of longs to the stream.

The longs will be written in the same format as writeLong(long).

bThe array of longs.
NullPointerExceptionIf the array is null.
public final void write(long[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of longs from the specified array to the stream.

The longs will be written in the same format as writeLong(long).

bThe array of longs.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void write(short[] b) throws NullPointerException
Writes an array of shorts to the stream.

The shorts will be written in the same format as writeShort(short).

bThe array of shorts.
NullPointerExceptionIf the array is null.
public final void write(short[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of shorts from the specified array to the stream.

The shorts will be written in the same format as writeShort(short).

bThe array of shorts.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void write(boolean[] b) throws NullPointerException
Writes an array of booleans to the stream.

The booleans will be written in the same format as writeBoolean(boolean).

bThe array of booleans.
NullPointerExceptionIf the array is null.
public final void write(boolean[] b, int offset, int length) throws NullPointerException, IndexOutOfBoundsException
Writes a range of booleans from the specified array to the stream.

The booleans will be written in the same format as writeBoolean(boolean).

bThe array of booleans.
offsetThe starting index of the range. (inclusive)
lengthThe number of elements to read.
NullPointerExceptionIf the array is null.
IndexOutOfBoundsExceptionIf the specified range is not within the array.
public final void writeBoolean(boolean v)
Overridden from: DataOutput
Writes a boolean value to this output stream. If the argument v is true, the value (byte)1 is written; if v is false, the value (byte)0 is written. The byte written by this method may be read by the readBoolean method of interface DataInput, which will then return a boolean equal to v.
vthe boolean to be written.
public final void writeByte(int v)
Overridden from: DataOutput
Writes to the output stream the eight low- order bits of the argument v. The 24 high-order bits of v are ignored. (This means that writeByte does exactly the same thing as write for an integer argument.) The byte written by this method may be read by the readByte method of interface DataInput, which will then return a byte equal to (byte)v.
vthe byte value to be written.
public final void writeBytes(String s)
Overridden from: DataOutput
Writes a string to the output stream. For every character in the string s, taken in order, one byte is written to the output stream. If s is null, a NullPointerException is thrown.

If s.length is zero, then no bytes are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1]. For each character, one byte is written, the low-order byte, in exactly the manner of the writeByte method . The high-order eight bits of each character in the string are ignored.

sthe string of bytes to be written.
public final void writeChar(char v)
Same as writeChar(int), but takes a char parameter.
vThe value to write.
public final void writeChar(int v)
Overridden from: DataOutput
Writes a char value, which is comprised of two bytes, to the output stream. The byte values to be written, in the order shown, are:

 (byte)(0xff & (v >> 8))
 (byte)(0xff & v)
 

The bytes written by this method may be read by the readChar method of interface DataInput , which will then return a char equal to (char)v.

vthe char value to be written.
public final void writeChars(CharSequence s) throws NullPointerException
Writes the characters in the argument sequence to the stream.

Unline writeStringLengthChars(CharSequence), the length of the character sequence is not written to the stream, only the characters in the same format as writeChar(char).

sThe char sequence to write.
NullPointerExceptionIf the argument is null.
public final void writeChars(String s)
Overridden from: DataOutput
Writes every character in the string s, to the output stream, in order, two bytes per character. If s is null, a NullPointerException is thrown. If s.length is zero, then no characters are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1]. For each character, two bytes are actually written, high-order byte first, in exactly the manner of the writeChar method.
sthe string value to be written.
public final void writeDouble(double v)
Overridden from: DataOutput
Writes a double value, which is comprised of eight bytes, to the output stream. It does this as if it first converts this double value to a long in exactly the manner of the Double.doubleToLongBits method and then writes the long value in exactly the manner of the writeLong method. The bytes written by this method may be read by the readDouble method of interface DataInput, which will then return a double equal to v.
vthe double value to be written.
public final void writeFloat(float v)
Overridden from: DataOutput
Writes a float value, which is comprised of four bytes, to the output stream. It does this as if it first converts this float value to an int in exactly the manner of the Float.floatToIntBits method and then writes the int value in exactly the manner of the writeInt method. The bytes written by this method may be read by the readFloat method of interface DataInput, which will then return a float equal to v.
vthe float value to be written.
public final void writeInt(int v)
Overridden from: DataOutput
Writes an int value, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:

 (byte)(0xff & (v >> 24))
 (byte)(0xff & (v >> 16))
 (byte)(0xff & (v >>  8))
 (byte)(0xff & v)
 

The bytes written by this method may be read by the readInt method of interface DataInput , which will then return an int equal to v.

vthe int value to be written.
public final void writeLong(long v)
Overridden from: DataOutput
Writes a long value, which is comprised of eight bytes, to the output stream. The byte values to be written, in the order shown, are:

 (byte)(0xff & (v >> 56))
 (byte)(0xff & (v >> 48))
 (byte)(0xff & (v >> 40))
 (byte)(0xff & (v >> 32))
 (byte)(0xff & (v >> 24))
 (byte)(0xff & (v >> 16))
 (byte)(0xff & (v >>  8))
 (byte)(0xff & v)
 

The bytes written by this method may be read by the readLong method of interface DataInput , which will then return a long equal to v.

vthe long value to be written.
public final void writeShort(int v)
Overridden from: DataOutput
Writes two bytes to the output stream to represent the value of the argument. The byte values to be written, in the order shown, are:

 (byte)(0xff & (v >> 8))
 (byte)(0xff & v)
 

The bytes written by this method may be read by the readShort method of interface DataInput , which will then return a short equal to (short)v.

vthe short value to be written.
public final void writeShort(short v)
Same as writeShort(int), but takes a short parameter.
vThe value to write.
Writes the number of characters and the actual characters to the stream.

Same as:

 writeInt(s.length());
 writeChars(s);
 
sThe character sequence.
NullPointerExceptionIf the argument is null.
public final void writeUTF(String str) throws UTFDataFormatException
Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s.If s is null, a NullPointerException is thrown. Each character in the string s is converted to a group of one, two, or three bytes, depending on the value of the character.

If a character c is in the range \u0001 through \u007f, it is represented by one byte:

(byte)c 

If a character c is \u0000 or is in the range \u0080 through \u07ff, then it is represented by two bytes, to be written in the order shown:


 (byte)(0xc0 | (0x1f & (c >> 6)))
 (byte)(0x80 | (0x3f & c))
 

If a character c is in the range \u0800 through uffff, then it is represented by three bytes, to be written in the order shown:


 (byte)(0xe0 | (0x0f & (c >> 12)))
 (byte)(0x80 | (0x3f & (c >>  6)))
 (byte)(0x80 | (0x3f & c))
 

First, the total number of bytes needed to represent all the characters of s is calculated. If this number is larger than 65535, then a UTFDataFormatException is thrown. Otherwise, this length is written to the output stream in exactly the manner of the writeShort method; after this, the one-, two-, or three-byte representation of each character in the string s is written.

The bytes written by this method may be read by the readUTF method of interface DataInput , which will then return a String equal to s.

UTFDataFormatExceptionIf the encoded string is longer than 65536 bytes.