Package java.io Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class DataOutputStream

Fields , Constructors , Methods

public  class  java.io.DataOutputStream
    extends  java.io.FilterOutputStream  
    implements java.io.DataOutput  
{
        // Fields
    protected int written;	

        // Constructors
    public DataOutputStream(OutputStream  out);	


        // Methods
    public void flush();	
    public final int size();	
    public void write(byte  b[], int  off, int  len);	
    public void write(int  b);	
    public final void writeBoolean(boolean  v);	
    public final void writeByte(int  v);	
    public final void writeBytes(String  s);	
    public final void writeChar(int  v);	
    public final void writeChars(String  s);	
    public final void writeDouble(double  v);	
    public final void writeFloat(float  v);	
    public final void writeInt(int  v);	
    public final void writeLong(long  v);	
    public final void writeShort(int  v);	
    public final void writeUTF(String  str);	
}

A data input stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in.


Fields


written

protected int written 

The number of bytes written to the data output stream.


Constructors


DataOutputStream

public DataOutputStream(OutputStream  out) 

Creates a new data output stream to write data to the specified underlying output stream .

ParameterDescription
out the underlying output stream


Methods


flush

public void flush() 
throws IOException 

Flushes this data output stream. This forces any buffered output bytes to be written out to the stream.

The flush method of DataOuputStream calls the flush method of its underlying output stream .

Throw:

IOException

If an I/O error occurs.

Overrides:

flush in class FilterOutputStream .


size

public final int size() 

Determines the number of bytes written to this data output stream.

Return Value:

Returns The value of the written field .


write

public void write(byte  b[], int  off, int  len) 
throws IOException 

Writes len bytes from the specified byte array starting at offset off to the underlying output stream .

ParameterDescription
b the data
off the start offset in the data
len the number of bytes to write

Throw:

IOException

If an I/O error occurs.

Overrides:

write in class FilterOutputStream .


write

public void write(int  b) 
throws IOException 

Writes the specified byte to the underlying output stream .

ParameterDescription
b the byte to be written

Throw:

IOException

If an I/O error occurs.

Overrides:

write in class FilterOutputStream .


writeBoolean

public final void writeBoolean(boolean  v) 
throws IOException 

Writes a boolean to the underlying output stream as a one-byte value. The value true is written out as the value (byte)1; the value false is written out as the value (byte)0.

ParameterDescription
v a boolean value to be written

Throw:

IOException

If an I/O error occurs.


writeByte

public final void writeByte(int  v) 
throws IOException 

Writes out a byte to the underlying output stream as a one-byte value.

ParameterDescription
v a byte value to be written

Throw:

IOException

If an I/O error occurs.


writeBytes

public final void writeBytes(String  s) 
throws IOException 

Writes out the string to the underlying output stream as a sequence of bytes. Each character in the string is written out, in sequence, by discarding its high eight bits.

ParameterDescription
s a string of bytes to be written

Throw:

IOException

If an I/O error occurs.


writeChar

public final void writeChar(int  v) 
throws IOException 

Writes a char to the underlying output stream as a two-byte value, high byte first.

ParameterDescription
v a char value to be written

Throw:

IOException

If an I/O error occurs.


writeChars

public final void writeChars(String  s) 
throws IOException 

Writes a string to the underlying output stream as a sequence of characters. Each character is written to the data output stream as if by the writeChar method .

ParameterDescription
s a String value to be written

Throw:

IOException

If an I/O error occurs.


writeDouble

public final void writeDouble(double  v) 
throws IOException 

Converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the underlying output stream as an eight-byte quantity, high-byte first.

ParameterDescription
v a double value to be written

Throw:

IOException

If an I/O error occurs.


writeFloat

public final void writeFloat(float  v) 
throws IOException 

Converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a four-byte quantity, high-byte first

ParameterDescription
v a float value to be written

Throw:

IOException

If an I/O error occurs.


writeInt

public final void writeInt(int  v) 
throws IOException 

Writes an int to the underlying output stream as four bytes, high-byte first.

ParameterDescription
v an int to be written

Throw:

IOException

If an I/O error occurs.


writeLong

public final void writeLong(long  v) 
throws IOException 

Writes a long to the underlying output stream as eight bytes, high-byte first.

ParameterDescription
v a long to be written

Throw:

IOException

If an I/O error occurs.


writeShort

public final void writeShort(int  v) 
throws IOException 

Writes a short to the underlying output stream as two bytes, high-byte first.

ParameterDescription
v a short to be written

Throw:

IOException

If an I/O error occurs.


writeUTF

public final void writeUTF(String  str) 
throws IOException 

Writes out a string to the underlying output stream using UTF-8 encoding in a machine-independent manner.

First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for each character.

ParameterDescription
str a string to be written

Throw:

IOException

If an I/O error occurs.



Top© 1996 Sun Microsystems, Inc. All rights reserved.