com.kirkwarez.kirkpack.io
Class EndianOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended bycom.kirkwarez.kirkpack.io.EndianOutputStream
All Implemented Interfaces:
DataOutput

public class EndianOutputStream
extends FilterOutputStream
implements DataOutput

This stream behaves about exactly as DataOutputStream, it writes primitive and some non-primitive data types to the underlying stream. The reason it doesn't extend DataOutputStream is because all methods in that class are declared final. This class does implement DataOutput.

The big difference is that this class takes a byte order on construction, and guarantees that the primitives' bytes will be written out using that byte order.

The non-primitive methods from this class are delegated to a DataOutputStream.

Since:
3.00
Version:
3.00
Author:
Berend "Kirk" Wouda

Field Summary
static int BIG_ENDIAN
          The Big Endian byte order.
protected  int byteorder
          The byte order used by this stream.
protected  DataOutputStream cache
          The OutputStream that FilterOutputStream parent class delegates to, only uncast.
static int LITTLE_ENDIAN
          The Little Endian byte order.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
EndianOutputStream(OutputStream output, int byteorder)
          Constucts a new stream that writes out primitives using the given byte order.
 
Method Summary
 int getByteorder()
          Returns the byte order.
protected  void setByteorder(int byteorder)
          Sets the byte order.
 void writeBoolean(boolean value)
          See the general contract of DataOutput.
 void writeByte(byte value)
          Writes a byte to the underlying stream.
 void writeByte(int value)
          See the general contract of DataOutput.
 void writeBytes(String string)
          See the general contract of DataOutput.
 void writeChar(char value)
          Symmerty method for EndianInputStream.
 void writeChar(int value)
          See the general contract of DataOutput.
 void writeChars(String string)
          See the general contract of DataOutput.
 void writeDouble(double value)
          See the general contract of DataOutput.
 void writeFloat(float value)
          See the general contract of DataOutput.
 void writeInt(int value)
          See the general contract of DataOutput.
 void writeLong(long value)
          See the general contract of DataOutput.
 void writeShort(int value)
          See the general contract of DataOutput.
 void writeShort(short value)
          Writes a short to the underlying stream.
 void writeUnsignedByte(int value)
          Writes an unsigned byte to the underlying stream.
 void writeUnsignedInt(long value)
          Writes an unsigned int to the underlying stream.
 void writeUnsignedShort(int value)
          Writes an unsigned short to the underlying stream.
 void writeUTF(String string)
          See the general contract of DataOutput.
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write, write, 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, write, write
 

Field Detail

cache

protected DataOutputStream cache
The OutputStream that FilterOutputStream parent class delegates to, only uncast.


byteorder

protected int byteorder
The byte order used by this stream.


BIG_ENDIAN

public static final int BIG_ENDIAN
The Big Endian byte order.

See Also:
Constant Field Values

LITTLE_ENDIAN

public static final int LITTLE_ENDIAN
The Little Endian byte order.

See Also:
Constant Field Values
Constructor Detail

EndianOutputStream

public EndianOutputStream(OutputStream output,
                          int byteorder)
Constucts a new stream that writes out primitives using the given byte order.

Parameters:
output - The stream to write to.
byteorder - The byte order. This is either BIG_ENDIAN or LITTLE_ENDIAN.
Method Detail

writeBoolean

public void writeBoolean(boolean value)
                  throws IOException
See the general contract of DataOutput.

Specified by:
writeBoolean in interface DataOutput
Parameters:
value - The next boolean to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeBoolean(boolean)

writeByte

public void writeByte(int value)
               throws IOException
See the general contract of DataOutput.

Specified by:
writeByte in interface DataOutput
Parameters:
value - The next byte to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeByte(int)

writeByte

public void writeByte(byte value)
               throws IOException
Writes a byte to the underlying stream. It's not DataOutput stuff, but it provides symmetry with EndianInputStream.

Parameters:
value - The next real byte to be written to this stream.
Throws:
IOException - When IO errors happen.

writeUnsignedByte

public void writeUnsignedByte(int value)
                       throws IOException
Writes an unsigned byte to the underlying stream. It's not DataOutput stuff, but it provides symmetry with EndianInputStream.

Parameters:
value - The next unsigned byte to be written to this stream.
Throws:
IOException - When IO errors happen.

writeShort

public void writeShort(int value)
                throws IOException
See the general contract of DataOutput.

Specified by:
writeShort in interface DataOutput
Parameters:
value - The next short to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeShort(int)

writeShort

public void writeShort(short value)
                throws IOException
Writes a short to the underlying stream. It's not DataOutput stuff, but it provides symmetry with EndianInputStream.

Parameters:
value - The next real short to be written to this stream.
Throws:
IOException - When IO errors happen.

writeUnsignedShort

public void writeUnsignedShort(int value)
                        throws IOException
Writes an unsigned short to the underlying stream. It's not DataOutput stuff, but it provides symmetry with EndianInputStream.

Parameters:
value - The next unsigned short to be written to this stream.
Throws:
IOException - When IO errors happen.

writeChar

public void writeChar(int value)
               throws IOException
See the general contract of DataOutput. This doesn't use byte ordering, cause no one writes out his Unicode like this :P

Specified by:
writeChar in interface DataOutput
Parameters:
value - The next char to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeChar(int)

writeChar

public void writeChar(char value)
               throws IOException
Symmerty method for EndianInputStream. This doesn't use byte ordering, cause no one writes out his Unicode like this :P

Parameters:
value - The next char to be written to this stream.
Throws:
IOException - When IO errors happen.

writeInt

public void writeInt(int value)
              throws IOException
See the general contract of DataOutput.

Specified by:
writeInt in interface DataOutput
Parameters:
value - The next int to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeInt(int)

writeUnsignedInt

public void writeUnsignedInt(long value)
                      throws IOException
Writes an unsigned int to the underlying stream. It's not DataOutput stuff, but it provides symmetry with EndianInputStream.

Parameters:
value - The next unsigned byte to be written to this stream.
Throws:
IOException - When IO errors happen.

writeLong

public void writeLong(long value)
               throws IOException
See the general contract of DataOutput.

Specified by:
writeLong in interface DataOutput
Parameters:
value - The next long to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeLong(long)

writeFloat

public void writeFloat(float value)
                throws IOException
See the general contract of DataOutput.

Specified by:
writeFloat in interface DataOutput
Parameters:
value - The next float to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeFloat(float)

writeDouble

public void writeDouble(double value)
                 throws IOException
See the general contract of DataOutput.

Specified by:
writeDouble in interface DataOutput
Parameters:
value - The next double to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeDouble(double)

writeBytes

public void writeBytes(String string)
                throws IOException
See the general contract of DataOutput.

Specified by:
writeBytes in interface DataOutput
Parameters:
string - The next string to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeBytes(String)

writeChars

public void writeChars(String string)
                throws IOException
See the general contract of DataOutput.

Specified by:
writeChars in interface DataOutput
Parameters:
string - The next string to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeChars(String)

writeUTF

public void writeUTF(String string)
              throws IOException
See the general contract of DataOutput.

Specified by:
writeUTF in interface DataOutput
Parameters:
string - The next string to be written to this stream.
Throws:
IOException - When IO errors happen.
See Also:
DataOutput.writeUTF(String)

getByteorder

public int getByteorder()
Returns the byte order.

Returns:
The byte order used by this stream.

setByteorder

protected void setByteorder(int byteorder)
Sets the byte order.

Parameters:
byteorder - The byte order used by this stream.