Skip to content

Most visited

Recently visited

navigation
Added in API level 1

DataOutputStream

public class DataOutputStream
extends FilterOutputStream implements DataOutput

java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.FilterOutputStream
       ↳ java.io.DataOutputStream


Wraps an existing 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.

See also:

Summary

Fields

protected int written

The number of bytes written out so far.

Inherited fields

From class java.io.FilterOutputStream

Public constructors

DataOutputStream(OutputStream out)

Constructs a new DataOutputStream on the OutputStream out.

Public methods

void flush()

Flushes this stream to ensure all pending data is sent out to the target stream.

final int size()

Returns the total number of bytes written to the target stream so far.

void write(int oneByte)

Writes a byte to the target stream.

void write(byte[] buffer, int offset, int count)

Writes count bytes from the byte array buffer starting at offset to the target stream.

final void writeBoolean(boolean val)

Writes a boolean to the target stream.

final void writeByte(int val)

Writes an 8-bit byte to the target stream.

final void writeBytes(String str)

Writes the low order 8-bit bytes from the specified string.

final void writeChar(int val)

Writes the specified 16-bit character in big-endian order.

final void writeChars(String str)

Writes the 16-bit characters contained in str in big-endian order.

final void writeDouble(double val)

Writes the specified 64-bit double in big-endian order.

final void writeFloat(float val)

Writes the specified 32-bit float in big-endian order.

final void writeInt(int val)

Writes the specified 32-bit int in big-endian order.

final void writeLong(long val)

Writes the specified 64-bit long in big-endian order.

final void writeShort(int val)

Writes the specified 16-bit short in big-endian order.

final void writeUTF(String str)

Writes the specified string encoded in modified UTF-8.

Inherited methods

From class java.io.FilterOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.io.DataOutput
From interface java.lang.AutoCloseable

Fields

written

Added in API level 1
int written

The number of bytes written out so far.

Public constructors

DataOutputStream

Added in API level 1
DataOutputStream (OutputStream out)

Constructs a new 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.

Parameters
out OutputStream: the target stream for writing.

Public methods

flush

Added in API level 1
void flush ()

Flushes this stream to ensure all pending data is sent out to the target stream. This implementation then also flushes the target stream.

Throws
IOException if an error occurs attempting to flush this stream.

size

Added in API level 1
int size ()

Returns the total number of bytes written to the target stream so far.

Returns
int the number of bytes written to the target stream.

write

Added in API level 1
void write (int oneByte)

Writes a byte to the target stream. Only the least significant byte of the integer oneByte is written.

Parameters
oneByte int: the byte to write to the target stream.
Throws
IOException if an error occurs while writing to the target stream.

See also:

write

Added in API level 1
void write (byte[] buffer, 
                int offset, 
                int count)

Writes count bytes from the byte array buffer starting at offset to the target stream.

Parameters
buffer byte: the buffer to write to the target stream.
offset int: the index of the first byte in buffer to write.
count int: the number of bytes from the buffer to write.
Throws
IOException if an error occurs while writing to the target stream.
NullPointerException if buffer is null.

writeBoolean

Added in API level 1
void writeBoolean (boolean val)

Writes a boolean to the target stream.

Parameters
val boolean: the boolean value to write to the target stream.
Throws
IOException if an error occurs while writing to the target stream.

See also:

writeByte

Added in API level 1
void writeByte (int val)

Writes an 8-bit byte to the target stream. Only the least significant byte of the integer val is written.

Parameters
val int: the byte value to write to the target stream.
Throws
IOException if an error occurs while writing to the target stream.

See also:

writeBytes

Added in API level 1
void writeBytes (String str)

Writes the low order 8-bit bytes from the specified string.

Parameters
str String: the string containing the bytes to write.
Throws
IOException

writeChar

Added in API level 1
void writeChar (int val)

Writes the specified 16-bit character in big-endian order. Only the two least significant bytes of the integer oneByte are written.

Parameters
val int: the character to write.
Throws
IOException

writeChars

Added in API level 1
void writeChars (String str)

Writes the 16-bit characters contained in str in big-endian order.

Parameters
str String: the string that contains the characters to write.
Throws
IOException

writeDouble

Added in API level 1
void writeDouble (double val)

Writes the specified 64-bit double in big-endian order. The resulting output is the eight bytes returned by doubleToLongBits(double).

Parameters
val double: the double to write.
Throws
IOException

writeFloat

Added in API level 1
void writeFloat (float val)

Writes the specified 32-bit float in big-endian order. The resulting output is the four bytes returned by floatToIntBits(float).

Parameters
val float: the float to write.
Throws
IOException

writeInt

Added in API level 1
void writeInt (int val)

Writes the specified 32-bit int in big-endian order.

Parameters
val int: the int to write.
Throws
IOException

writeLong

Added in API level 1
void writeLong (long val)

Writes the specified 64-bit long in big-endian order.

Parameters
val long: the long to write.
Throws
IOException

writeShort

Added in API level 1
void writeShort (int val)

Writes the specified 16-bit short in big-endian order. Only the lower two bytes of val are written.

Parameters
val int: the short to write.
Throws
IOException

writeUTF

Added in API level 1
void writeUTF (String str)

Writes the specified string encoded in modified UTF-8.

Parameters
str String: the string to write encoded in modified UTF-8.
Throws
IOException
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.