com.voytechs.jnetstream.io
Class ProtocolDataOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.voytechs.jnetstream.io.ProtocolDataOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
PacketOutputStream

public class ProtocolDataOutputStream
extends java.io.OutputStream

Writes native JAVA types into the stream. Also allows bit by bit writes with several methods that extend the default OutpuStream methods.


Field Summary
protected  int bitsLeft
           
protected  int cachedByte
           
protected  java.io.OutputStream out
           
 
Constructor Summary
protected ProtocolDataOutputStream()
          A empty constructor that can only be called on by sub-classes.
  ProtocolDataOutputStream(java.io.OutputStream out)
           
 
Method Summary
 void flush()
          Flushes all unwritten data, including bit by bit data.
static void main(java.lang.String[] args)
          Test function for ProtocolDataOutputStream
 void unloadCachedByte()
          Writes (unloads) the cached by to output stream.
 void write(byte[] b)
          Write an array of bytes to the stream starting at current bit and byte positions.
 void write(int b)
          Write a single byte to the stream starting at current bit and byte positions.
 void write(int b, int bits)
          Writes any number of bits into the stream.
 void write(long b, int bits)
          Writes any number of bits into the stream.
 void writeByte(byte v)
          Writes out a signed byte to the output stream.
 void writeInt(int v)
          Writes out a signed int to the output stream.
 void writeL(int b, int bits)
          Writes any number of bits into the stream.
 void writeLByte(byte v)
          Writes out a signed byte to the output stream.
 void writeLInt(int v)
          Writes out a signed int to the output stream.
 void writeLLong(long v)
          Writes out a signed long to the output stream.
 void writeLong(long v)
          Writes out a signed long to the output stream.
 void writeLShort(int v)
          Writes out a signed short to the output stream.
 void writeShort(int v)
          Writes out a signed short to the output stream.
 void writeUByte(byte v)
          Writes out a unsigned byte to the output stream.
 void writeUInt(int v)
          Writes out a unsigned int to the output stream.
 void writeULByte(byte v)
          Writes out a unsigned byte to the output stream.
 void writeULInt(int v)
          Writes out a unsigned int to the output stream.
 void writeULLong(long v)
          Writes out a unsigned long to the output stream.
 void writeULong(long v)
          Writes out a signed long to the output stream.
 void writeULShort(int v)
          Writes out a unsigned int to the output stream.
 void writeUShort(int v)
          Writes out a unsigned short to the output stream.
 
Methods inherited from class java.io.OutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.OutputStream out

bitsLeft

protected int bitsLeft

cachedByte

protected int cachedByte
Constructor Detail

ProtocolDataOutputStream

protected ProtocolDataOutputStream()
A empty constructor that can only be called on by sub-classes. The object is not initialized and has to be intitialized post Constructor method.


ProtocolDataOutputStream

public ProtocolDataOutputStream(java.io.OutputStream out)
Parameters:
out - OutputStream to write to.
Throws:
Method Detail

write

public void write(int b)
           throws java.io.IOException
Write a single byte to the stream starting at current bit and byte positions.

Specified by:
write in class java.io.OutputStream
Parameters:
b - Byte to write to the stream.
Throws:
java.io.IOException - Any IO errors

write

public void write(byte[] b)
           throws java.io.IOException
Write an array of bytes to the stream starting at current bit and byte positions.

Overrides:
write in class java.io.OutputStream
Parameters:
b - Byte array to write to the stream.
Throws:
java.io.IOException - Any IO errors

write

public void write(int b,
                  int bits)
           throws java.io.IOException
Writes any number of bits into the stream. Max bits is 32 bits.

Bits are retrieved and written in BIG endian byte order.

Parameters:
b - Interger variable to write to the stream.
bits - Number of bits to write from "b", pivoting at the least significan bit
Throws:
java.io.IOException

write

public void write(long b,
                  int bits)
           throws java.io.IOException
Writes any number of bits into the stream. Max bits is 64 bits.

Bits are retrieved and written in BIG endian byte order.

Parameters:
b - Interger variable to write to the stream.
bits - Number of bits to write from "b", pivoting at the least significan bit
Throws:
java.io.IOException

writeL

public void writeL(int b,
                   int bits)
            throws java.io.IOException
Writes any number of bits into the stream. Max bits is 32 bits.

Bits are retrieved and written in LITTLE endian byte order.

Parameters:
b - Interger variable to write to the stream.
bits - Number of bits to write from "b", pivoting at the least significan bit
Throws:
java.io.IOException

unloadCachedByte

public void unloadCachedByte()
                      throws java.io.IOException
Writes (unloads) the cached by to output stream.

Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes all unwritten data, including bit by bit data. Because the flush writes to a real that does not support sub-byte positioning, the bit position is reset.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

writeByte

public void writeByte(byte v)
               throws java.io.IOException
Writes out a signed byte to the output stream.

Parameters:
v - Byte to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeShort

public void writeShort(int v)
                throws java.io.IOException
Writes out a signed short to the output stream. Uses BIG endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeInt

public void writeInt(int v)
              throws java.io.IOException
Writes out a signed int to the output stream. Uses BIG endian encoding.

Parameters:
v - Int to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeLong

public void writeLong(long v)
               throws java.io.IOException
Writes out a signed long to the output stream. Uses BIG endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeUByte

public void writeUByte(byte v)
                throws java.io.IOException
Writes out a unsigned byte to the output stream.

Parameters:
v - Byte to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeUInt

public void writeUInt(int v)
               throws java.io.IOException
Writes out a unsigned int to the output stream. Uses BIG endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeUShort

public void writeUShort(int v)
                 throws java.io.IOException
Writes out a unsigned short to the output stream. Uses BIG endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeULong

public void writeULong(long v)
                throws java.io.IOException
Writes out a signed long to the output stream. Uses BIG endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeLByte

public void writeLByte(byte v)
                throws java.io.IOException
Writes out a signed byte to the output stream.

Parameters:
v - Byte to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeLShort

public void writeLShort(int v)
                 throws java.io.IOException
Writes out a signed short to the output stream. Uses LITTLE endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeLInt

public void writeLInt(int v)
               throws java.io.IOException
Writes out a signed int to the output stream. Uses LITTLE endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeLLong

public void writeLLong(long v)
                throws java.io.IOException
Writes out a signed long to the output stream. Uses LITTLE endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeULByte

public void writeULByte(byte v)
                 throws java.io.IOException
Writes out a unsigned byte to the output stream.

Parameters:
v - Byte to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeULShort

public void writeULShort(int v)
                  throws java.io.IOException
Writes out a unsigned int to the output stream. Uses LITTLE endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeULInt

public void writeULInt(int v)
                throws java.io.IOException
Writes out a unsigned int to the output stream. Uses LITTLE endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

writeULLong

public void writeULLong(long v)
                 throws java.io.IOException
Writes out a unsigned long to the output stream. Uses LITTLE endian encoding.

Parameters:
v - Short to value to be written.
Throws:
java.io.IOException - if an I/O error occurs.

main

public static void main(java.lang.String[] args)
Test function for ProtocolDataOutputStream

Parameters:
args - command line arguments