de.schlichtherle.io.util
Class LEDataOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by de.schlichtherle.io.util.LEDataOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable

public class LEDataOutputStream
extends FilterOutputStream
implements DataOutput

A stream to write data in Little Endian (LE) format.

This class is similar to DataOutputStream, but writes data in Little Endian format to its underlying stream. A noteable difference to DataOutputStream is that the size() method and the written field are respectively return long values and wrap to Long.MAX_VALUE.

Note that this class is not thread safe.

Version:
TrueZIP 6.7
Author:
Christian Schlichtherle

Field Summary
protected  long written
          The number of bytes written to the data output stream so far.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
LEDataOutputStream(OutputStream out)
          Creates a new data output stream to write data to the specified underlying output stream.
 
Method Summary
 long size()
          Returns the current value of the counter written, the number of bytes written to this data output stream so far.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to the underlying output stream.
 void write(int b)
          Writes the specified byte (the low eight bits of the argument b) to the underlying output stream.
 void writeBoolean(boolean b)
          Writes a boolean value to the underlying output stream as a 1-byte value.
 void writeByte(int b)
          Writes a byte value to the underlying output stream as a 1-byte value.
 void writeBytes(String s)
          Writes the string s to the underlying output stream as a sequence of bytes.
 void writeChar(int c)
          Writes a char value to the underlying output stream as a 2-byte value, low byte first.
 void writeChars(String s)
          Writes the string s to the underlying output stream as a sequence of characters.
 void writeDouble(double d)
          Converts the double value d to a long using the doubleToLongBits method in class Double, and then writes that long value to the underlying output stream as an 8-byte quantity, low byte first.
 void writeFloat(float f)
          Converts the float value f to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a 4-byte quantity, low byte first.
 void writeInt(int i)
          Writes the integer value i to the underlying output stream as four bytes, low byte first.
 void writeLong(long l)
          Writes the integer value l to the underlying output stream as eight bytes, low byte first.
 void writeShort(int s)
          Writes the integer value s to the underlying output stream as two bytes, low byte first.
 void writeUTF(String str)
          This method is not implemented.
 
Methods inherited from class java.io.FilterOutputStream
close, flush, 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 volatile long written
The number of bytes written to the data output stream so far. If this counter overflows, it will be wrapped to Long.MAX_VALUE.

Constructor Detail

LEDataOutputStream

public LEDataOutputStream(OutputStream out)
Creates a new data output stream to write data to the specified underlying output stream. The counter written is set to zero.

Parameters:
out - The underlying output stream, to be saved for later use.
Method Detail

write

public void write(int b)
           throws IOException
Writes the specified byte (the low eight bits of the argument b) to the underlying output stream. If no exception is thrown, the counter written is incremented by one.

Implements the write method of OutputStream.

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

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. If no exception is thrown, the counter written is incremented by len.

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

writeBoolean

public final void writeBoolean(boolean b)
                        throws IOException
Writes a boolean value to the underlying output stream as a 1-byte value. The value true is written out as the value (byte)1; the value false is written out as the value (byte)0. If no exception is thrown, the counter written is incremented by one.

Specified by:
writeBoolean in interface DataOutput
Parameters:
b - The boolean value to be written.
Throws:
IOException - If an I/O error occurs.

writeByte

public final void writeByte(int b)
                     throws IOException
Writes a byte value to the underlying output stream as a 1-byte value. If no exception is thrown, the counter written is incremented by one.

Specified by:
writeByte in interface DataOutput
Parameters:
b - The byte value to be written.
Throws:
IOException - If an I/O error occurs.

writeChar

public final void writeChar(int c)
                     throws IOException
Writes a char value to the underlying output stream as a 2-byte value, low byte first. If no exception is thrown, the counter written is incremented by two.

Specified by:
writeChar in interface DataOutput
Parameters:
c - The char value to be written.
Throws:
IOException - If an I/O error occurs.

writeShort

public final void writeShort(int s)
                      throws IOException
Writes the integer value s to the underlying output stream as two bytes, low byte first. If no exception is thrown, the counter written is incremented by two.

Specified by:
writeShort in interface DataOutput
Parameters:
s - The short integer value to be written.
Throws:
IOException - If an I/O error occurs.

writeInt

public final void writeInt(int i)
                    throws IOException
Writes the integer value i to the underlying output stream as four bytes, low byte first. If no exception is thrown, the counter written is incremented by four.

Specified by:
writeInt in interface DataOutput
Parameters:
i - The integer value to be written.
Throws:
IOException - If an I/O error occurs.

writeLong

public final void writeLong(long l)
                     throws IOException
Writes the integer value l to the underlying output stream as eight bytes, low byte first. If no exception is thrown, the counter written is incremented by eight.

Specified by:
writeLong in interface DataOutput
Parameters:
l - The long integer value to be written.
Throws:
IOException - If an I/O error occurs.

writeFloat

public final void writeFloat(float f)
                      throws IOException
Converts the float value f to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a 4-byte quantity, low byte first. If no exception is thrown, the counter written is incremented by 4.

Specified by:
writeFloat in interface DataOutput
Parameters:
f - The float value to be written.
Throws:
IOException - If an I/O error occurs.
See Also:
Float.floatToIntBits(float)

writeDouble

public final void writeDouble(double d)
                       throws IOException
Converts the double value d to a long using the doubleToLongBits method in class Double, and then writes that long value to the underlying output stream as an 8-byte quantity, low byte first. If no exception is thrown, the counter written is incremented by 8.

Specified by:
writeDouble in interface DataOutput
Parameters:
d - The double value to be written.
Throws:
IOException - If an I/O error occurs.
See Also:
Double.doubleToLongBits(double)

writeBytes

public final void writeBytes(String s)
                      throws IOException
Writes the string s 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. If no exception is thrown, the counter written is incremented by the length of s.

Specified by:
writeBytes in interface DataOutput
Parameters:
s - The string of bytes to be written.
Throws:
IOException - If an I/O error occurs.

writeChars

public final void writeChars(String s)
                      throws IOException
Writes the string s to the underlying output stream as a sequence of characters. Each character is written out as if by the writeChar method. If no exception is thrown, the counter written is incremented by twice the length of s.

Specified by:
writeChars in interface DataOutput
Parameters:
s - The String value to be written.
Throws:
IOException - If an I/O error occurs.
See Also:
DataOutputStream.writeChar(int)

writeUTF

public void writeUTF(String str)
              throws IOException
This method is not implemented.

Specified by:
writeUTF in interface DataOutput
Throws:
UnsupportedOperationException - Always.
IOException

size

public final long size()
Returns the current value of the counter written, the number of bytes written to this data output stream so far. If the counter overflows, it will be wrapped to Long.MAX_VALUE.

Returns:
The value of the written field.
See Also:
DataOutputStream.written