java.io
Class DataOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--java.io.DataOutputStream
All Implemented Interfaces:
DataOutput

public class DataOutputStream
extends FilterOutputStream
implements DataOutput

This class lets you write primitive Java data types to a stream in a portable way. Primitive data types are well understood types with associated operations. For example, an Integer is considered to be a good primitive data type. The data can be converted back using a DataInputStream.


Field Summary
protected  int written
          The number of bytes written so far.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
DataOutputStream(OutputStream out)
          Creates a new DataOutputStream.
 
Method Summary
 void flush()
          Flushes the stream.
 int size()
          Returns the number of bytes written.
 void write(byte[] b, int off, int len)
          Writes a sub array of bytes.
 void write(int b)
          Writes a byte.
 void writeBoolean(boolean v)
          Writes a boolean.
 void writeByte(int v)
          Writes an 8 bit byte.
 void writeBytes(String s)
          Writes a String as a sequence of bytes.
 void writeChar(int v)
          Writes a 16 bit char.
 void writeChars(String s)
          Writes a String as a sequence of chars.
 void writeDouble(double v)
          Writes a 64 bit double.
 void writeFloat(float v)
          Writes a 32 bit float.
 void writeInt(int v)
          Writes a 32 bit int.
 void writeLong(long v)
          Writes a 64 bit long.
 void writeShort(int v)
          Writes a 16 bit short.
 void writeUTF(String str)
          Writes a String in UTF format.
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataOutput
write
 

Field Detail

written

protected int written
The number of bytes written so far.

Constructor Detail

DataOutputStream

public DataOutputStream(OutputStream out)
Creates a new DataOutputStream.

Parameters:
out - the output stream
Method Detail

write

public void write(int b)
           throws IOException
Writes a byte. Will block until the byte is actually written.

Specified by:
write in interface DataOutput
Overrides:
write in class FilterOutputStream
Parameters:
b - the byte to be written
Throws:
IOException - If an I/O error has occurred.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes a sub array of bytes.

Specified by:
write in interface DataOutput
Overrides:
write in class FilterOutputStream
Parameters:
b - the data to be written
off - the start offset in the data
len - the number of bytes that are written
Throws:
IOException - If an I/O error has occurred.

flush

public void flush()
           throws IOException
Flushes the stream. This will write any buffered output bytes.

Overrides:
flush in class FilterOutputStream
Throws:
IOException - If an I/O error has occurred.

writeBoolean

public final void writeBoolean(boolean v)
                        throws IOException
Writes a boolean.

Specified by:
writeBoolean in interface DataOutput
Parameters:
v - the boolean to be written
IOException

writeByte

public final void writeByte(int v)
                     throws IOException
Writes an 8 bit byte.

Specified by:
writeByte in interface DataOutput
Parameters:
v - the byte value to be written
IOException

writeShort

public final void writeShort(int v)
                      throws IOException
Writes a 16 bit short.

Specified by:
writeShort in interface DataOutput
Parameters:
v - the short value to be written
IOException

writeChar

public final void writeChar(int v)
                     throws IOException
Writes a 16 bit char.

Specified by:
writeChar in interface DataOutput
Parameters:
v - the char value to be written
IOException

writeInt

public final void writeInt(int v)
                    throws IOException
Writes a 32 bit int.

Specified by:
writeInt in interface DataOutput
Parameters:
v - the integer value to be written
IOException

writeLong

public final void writeLong(long v)
                     throws IOException
Writes a 64 bit long.

Specified by:
writeLong in interface DataOutput
Parameters:
v - the long value to be written
IOException

writeFloat

public final void writeFloat(float v)
                      throws IOException
Writes a 32 bit float.

Specified by:
writeFloat in interface DataOutput
Parameters:
v - the float value to be written
IOException

writeDouble

public final void writeDouble(double v)
                       throws IOException
Writes a 64 bit double.

Specified by:
writeDouble in interface DataOutput
Parameters:
v - the double value to be written
IOException

writeBytes

public final void writeBytes(String s)
                      throws IOException
Writes a String as a sequence of bytes.

Specified by:
writeBytes in interface DataOutput
Parameters:
s - the String of bytes to be written
IOException

writeChars

public final void writeChars(String s)
                      throws IOException
Writes a String as a sequence of chars.

Specified by:
writeChars in interface DataOutput
Parameters:
s - the String of chars to be written
IOException

writeUTF

public final void writeUTF(String str)
                    throws IOException
Writes a String in UTF format.

Specified by:
writeUTF in interface DataOutput
Parameters:
str - the String in UTF format
IOException

size

public final int size()
Returns the number of bytes written.

Returns:
the number of bytes written thus far.