Interface ByteArrayDataOutput
- 
- All Superinterfaces:
- DataOutput
 
 @GwtIncompatible public interface ByteArrayDataOutput extends DataOutput An extension ofDataOutputfor writing to in-memory byte arrays; its methods offer identical functionality but do not throwIOException.- Since:
- 1.0
- Author:
- Jayaprabhakar Kadarkarai
 
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description byte[]toByteArray()Returns the contents that have been written to this instance, as a byte array.voidwrite(byte[] b)Writes to the output stream all the bytes in arrayb.voidwrite(byte[] b, int off, int len)Writeslenbytes from arrayb, in order, to the output stream.voidwrite(int b)Writes to the output stream the eight low-order bits of the argumentb.voidwriteBoolean(boolean v)Writes abooleanvalue to this output stream.voidwriteByte(int v)Writes to the output stream the eight low- order bits of the argumentv.voidwriteBytes(String s)Deprecated.This method is dangerous as it discards the high byte of every character.voidwriteChar(int v)Writes acharvalue, which is comprised of two bytes, to the output stream.voidwriteChars(String s)Writes every character in the strings, to the output stream, in order, two bytes per character.voidwriteDouble(double v)Writes adoublevalue, which is comprised of eight bytes, to the output stream.voidwriteFloat(float v)Writes afloatvalue, which is comprised of four bytes, to the output stream.voidwriteInt(int v)Writes anintvalue, which is comprised of four bytes, to the output stream.voidwriteLong(long v)Writes alongvalue, which is comprised of eight bytes, to the output stream.voidwriteShort(int v)Writes two bytes to the output stream to represent the value of the argument.voidwriteUTF(String s)Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the strings.
 
- 
- 
- 
Method Detail- 
writevoid write(int b) Description copied from interface:java.io.DataOutputWrites to the output stream the eight low-order bits of the argumentb. The 24 high-order bits ofbare ignored.- Specified by:
- writein interface- DataOutput
- Parameters:
- b- the byte to be written.
 
 - 
writevoid write(byte[] b) Description copied from interface:java.io.DataOutputWrites to the output stream all the bytes in arrayb. Ifbisnull, aNullPointerExceptionis thrown. Ifb.lengthis zero, then no bytes are written. Otherwise, the byteb[0]is written first, thenb[1], and so on; the last byte written isb[b.length-1].- Specified by:
- writein interface- DataOutput
- Parameters:
- b- the data.
 
 - 
writevoid write(byte[] b, int off, int len) Description copied from interface:java.io.DataOutputWriteslenbytes from arrayb, in order, to the output stream. Ifbisnull, aNullPointerExceptionis thrown. Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arrayb, then anIndexOutOfBoundsExceptionis thrown. Iflenis zero, then no bytes are written. Otherwise, the byteb[off]is written first, thenb[off+1], and so on; the last byte written isb[off+len-1].- Specified by:
- writein interface- DataOutput
- Parameters:
- b- the data.
- off- the start offset in the data.
- len- the number of bytes to write.
 
 - 
writeBooleanvoid writeBoolean(boolean v) Description copied from interface:java.io.DataOutputWrites abooleanvalue to this output stream. If the argumentvistrue, the value(byte)1is written; ifvisfalse, the value(byte)0is written. The byte written by this method may be read by thereadBooleanmethod of interfaceDataInput, which will then return abooleanequal tov.- Specified by:
- writeBooleanin interface- DataOutput
- Parameters:
- v- the boolean to be written.
 
 - 
writeBytevoid writeByte(int v) Description copied from interface:java.io.DataOutputWrites to the output stream the eight low- order bits of the argumentv. The 24 high-order bits ofvare ignored. (This means thatwriteBytedoes exactly the same thing aswritefor an integer argument.) The byte written by this method may be read by thereadBytemethod of interfaceDataInput, which will then return abyteequal to(byte)v.- Specified by:
- writeBytein interface- DataOutput
- Parameters:
- v- the byte value to be written.
 
 - 
writeShortvoid writeShort(int v) Description copied from interface:java.io.DataOutputWrites 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 readShortmethod of interfaceDataInput, which will then return ashortequal to(short)v.- Specified by:
- writeShortin interface- DataOutput
- Parameters:
- v- the- shortvalue to be written.
 
 - 
writeCharvoid writeChar(int v) Description copied from interface:java.io.DataOutputWrites acharvalue, 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 readCharmethod of interfaceDataInput, which will then return acharequal to(char)v.- Specified by:
- writeCharin interface- DataOutput
- Parameters:
- v- the- charvalue to be written.
 
 - 
writeIntvoid writeInt(int v) Description copied from interface:java.io.DataOutputWrites anintvalue, 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 readIntmethod of interfaceDataInput, which will then return anintequal tov.- Specified by:
- writeIntin interface- DataOutput
- Parameters:
- v- the- intvalue to be written.
 
 - 
writeLongvoid writeLong(long v) Description copied from interface:java.io.DataOutputWrites alongvalue, 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 readLongmethod of interfaceDataInput, which will then return alongequal tov.- Specified by:
- writeLongin interface- DataOutput
- Parameters:
- v- the- longvalue to be written.
 
 - 
writeFloatvoid writeFloat(float v) Description copied from interface:java.io.DataOutputWrites afloatvalue, which is comprised of four bytes, to the output stream. It does this as if it first converts thisfloatvalue to anintin exactly the manner of theFloat.floatToIntBitsmethod and then writes theintvalue in exactly the manner of thewriteIntmethod. The bytes written by this method may be read by thereadFloatmethod of interfaceDataInput, which will then return afloatequal tov.- Specified by:
- writeFloatin interface- DataOutput
- Parameters:
- v- the- floatvalue to be written.
 
 - 
writeDoublevoid writeDouble(double v) Description copied from interface:java.io.DataOutputWrites adoublevalue, which is comprised of eight bytes, to the output stream. It does this as if it first converts thisdoublevalue to alongin exactly the manner of theDouble.doubleToLongBitsmethod and then writes thelongvalue in exactly the manner of thewriteLongmethod. The bytes written by this method may be read by thereadDoublemethod of interfaceDataInput, which will then return adoubleequal tov.- Specified by:
- writeDoublein interface- DataOutput
- Parameters:
- v- the- doublevalue to be written.
 
 - 
writeCharsvoid writeChars(String s) Description copied from interface:java.io.DataOutputWrites every character in the strings, to the output stream, in order, two bytes per character. Ifsisnull, aNullPointerExceptionis thrown. Ifs.lengthis zero, then no characters are written. Otherwise, the characters[0]is written first, thens[1], and so on; the last character written iss[s.length-1]. For each character, two bytes are actually written, high-order byte first, in exactly the manner of thewriteCharmethod.- Specified by:
- writeCharsin interface- DataOutput
- Parameters:
- s- the string value to be written.
 
 - 
writeUTFvoid writeUTF(String s) Description copied from interface:java.io.DataOutputWrites two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the strings. Ifsisnull, aNullPointerExceptionis thrown. Each character in the stringsis converted to a group of one, two, or three bytes, depending on the value of the character.If a character cis in the range\u0001through\u007f, it is represented by one byte:(byte)c If a character cis\u0000or is in the range\u0080through\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 cis in the range\u0800throughuffff, 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 sis calculated. If this number is larger than65535, then aUTFDataFormatExceptionis thrown. Otherwise, this length is written to the output stream in exactly the manner of thewriteShortmethod; after this, the one-, two-, or three-byte representation of each character in the stringsis written.The bytes written by this method may be read by the readUTFmethod of interfaceDataInput, which will then return aStringequal tos.- Specified by:
- writeUTFin interface- DataOutput
- Parameters:
- s- the string value to be written.
 
 - 
writeBytes@Deprecated void writeBytes(String s) Deprecated.This method is dangerous as it discards the high byte of every character. For UTF-8, usewrite(s.getBytes(StandardCharsets.UTF_8)).Description copied from interface:java.io.DataOutputWrites a string to the output stream. For every character in the strings, taken in order, one byte is written to the output stream. Ifsisnull, aNullPointerExceptionis thrown.If s.lengthis zero, then no bytes are written. Otherwise, the characters[0]is written first, thens[1], and so on; the last character written iss[s.length-1]. For each character, one byte is written, the low-order byte, in exactly the manner of thewriteBytemethod . The high-order eight bits of each character in the string are ignored.- Specified by:
- writeBytesin interface- DataOutput
- Parameters:
- s- the string of bytes to be written.
 
 - 
toByteArraybyte[] toByteArray() Returns the contents that have been written to this instance, as a byte array.
 
- 
 
-