public class DataOutputStream extends FilterOutputStream implements DataOutput
OutputStream and writes big-endian typed data to it.
Typically, this stream can be read in by DataInputStream. Types that can be
written include byte, 16-bit short, 32-bit int, 32-bit float, 64-bit long,
64-bit double, byte strings, and MUTF-8 encoded strings.DataInputStream| Modifier and Type | Field and Description |
|---|---|
protected int |
written
The number of bytes written out so far.
|
out| Constructor and Description |
|---|
DataOutputStream(OutputStream out)
Constructs a new
DataOutputStream on the OutputStream
out. |
| Modifier and Type | Method and Description |
|---|---|
void |
flush()
Flushes this stream to ensure all pending data is sent out to the target
stream.
|
int |
size()
Returns the total number of bytes written to the target stream so far.
|
void |
write(byte[] buffer,
int offset,
int count)
Writes
count bytes from the byte array buffer starting at
offset to the target stream. |
void |
write(int oneByte)
Writes a byte to the target stream.
|
void |
writeBoolean(boolean val)
Writes a boolean to the target stream.
|
void |
writeByte(int val)
Writes an 8-bit byte to the target stream.
|
void |
writeBytes(String str)
Writes the low order 8-bit bytes from the specified string.
|
void |
writeChar(int val)
Writes the specified 16-bit character in big-endian order.
|
void |
writeChars(String str)
Writes the 16-bit characters contained in
str in big-endian order. |
void |
writeDouble(double val)
Writes the specified 64-bit double in big-endian order.
|
void |
writeFloat(float val)
Writes the specified 32-bit float in big-endian order.
|
void |
writeInt(int val)
Writes the specified 32-bit int in big-endian order.
|
void |
writeLong(long val)
Writes the specified 64-bit long in big-endian order.
|
void |
writeShort(int val)
Writes the specified 16-bit short in big-endian order.
|
void |
writeUTF(String str)
Writes the specified string encoded in
modified UTF-8. |
closenullOutputStream, writeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitwritepublic DataOutputStream(OutputStream out)
DataOutputStream on the OutputStream
out. Note that data written by this stream is not in a human
readable form but can be reconstructed by using a DataInputStream
on the resulting output.out - the target stream for writing.public void flush()
throws IOException
flush in interface Flushableflush in class FilterOutputStreamIOException - if an error occurs attempting to flush this stream.public final int size()
public void write(byte[] buffer,
int offset,
int count)
throws IOException
count bytes from the byte array buffer starting at
offset to the target stream.write in interface DataOutputwrite in class FilterOutputStreambuffer - the buffer to write to the target stream.offset - the index of the first byte in buffer to write.count - the number of bytes from the buffer to write.IOException - if an error occurs while writing to the target stream.NullPointerException - if buffer is null.public void write(int oneByte)
throws IOException
oneByte is written.write in interface DataOutputwrite in class FilterOutputStreamoneByte - the byte to write to the target stream.IOException - if an error occurs while writing to the target stream.DataInputStream.readByte()public final void writeBoolean(boolean val)
throws IOException
writeBoolean in interface DataOutputval - the boolean value to write to the target stream.IOException - if an error occurs while writing to the target stream.DataInputStream.readBoolean()public final void writeByte(int val)
throws IOException
val is written.writeByte in interface DataOutputval - the byte value to write to the target stream.IOException - if an error occurs while writing to the target stream.DataInputStream.readByte(),
DataInputStream.readUnsignedByte()public final void writeBytes(String str) throws IOException
DataOutputwriteBytes in interface DataOutputstr - the string containing the bytes to write.IOException - if an I/O error occurs while writing.public final void writeChar(int val)
throws IOException
DataOutputoneByte are written.writeChar in interface DataOutputval - the character to write.IOException - if an I/O error occurs while writing.DataInput.readChar()public final void writeChars(String str) throws IOException
DataOutputstr in big-endian order.writeChars in interface DataOutputstr - the string that contains the characters to write.IOException - if an I/O error occurs while writing.DataInput.readChar()public final void writeDouble(double val)
throws IOException
DataOutputDouble.doubleToLongBits(double).writeDouble in interface DataOutputval - the double to write.IOException - if an I/O error occurs while writing.DataInput.readDouble()public final void writeFloat(float val)
throws IOException
DataOutputFloat.floatToIntBits(float).writeFloat in interface DataOutputval - the float to write.IOException - if an I/O error occurs while writing.DataInput.readFloat()public final void writeInt(int val)
throws IOException
DataOutputwriteInt in interface DataOutputval - the int to write.IOException - if an I/O error occurs while writing.DataInput.readInt()public final void writeLong(long val)
throws IOException
DataOutputwriteLong in interface DataOutputval - the long to write.IOException - if an I/O error occurs while writing.DataInput.readLong()public final void writeShort(int val)
throws IOException
DataOutputval are written.writeShort in interface DataOutputval - the short to write.IOException - if an I/O error occurs while writing.DataInput.readShort(),
DataInput.readUnsignedShort()public final void writeUTF(String str) throws IOException
DataOutputmodified UTF-8.writeUTF in interface DataOutputstr - the string to write encoded in modified UTF-8.IOException - if an I/O error occurs while writing.DataInput.readUTF()