org.freehep.util.io
Class ByteOrderOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.freehep.util.io.CompressableOutputStream
              extended by org.freehep.util.io.BitOutputStream
                  extended by org.freehep.util.io.ByteOrderOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable, FinishableOutputStream
Direct Known Subclasses:
ByteCountOutputStream

public class ByteOrderOutputStream
extends BitOutputStream
implements DataOutput

Class to write bytes and pairs of bytes in both little and big endian order.

Version:
$Id: ByteOrderOutputStream.java 8584 2006-08-10 23:06:37Z duns $
Author:
Mark Donszelmann, Charles Loomis

Field Summary
protected  boolean little
           
protected  int written
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ByteOrderOutputStream(OutputStream out)
          Create a (Big Endian) Byte Order output stream from given stream
ByteOrderOutputStream(OutputStream out, boolean littleEndian)
          Create a Byte Order output stream from the given stream
 
Method Summary
 int size()
           
 void write(int b)
           
 void writeAsciiZString(String s)
          Write an ascii-z (0 terminated c-string).
 void writeBoolean(boolean b)
           
 void writeByte(byte[] bytes)
          Writes array of bytes
 void writeByte(int b)
          Write a signed byte.
 void writeBytes(String s)
           
 void writeChar(int c)
           
 void writeChars(String s)
           
 void writeDouble(double d)
           
 void writeFloat(float f)
           
 void writeInt(int i)
          Write a signed integer.
 void writeInt(int[] ints)
          Write an array of ints
 void writeLong(long l)
           
 void writeShort(int s)
          Write a signed short.
 void writeShort(short[] shorts)
          Write an array of shorts.
 void writeString(String s)
          Write a string (UTF)
 void writeUnsignedByte(int ub)
          Write an unsigned byte.
 void writeUnsignedByte(int[] bytes)
          Write an array of unsigned bytes.
 void writeUnsignedInt(long i)
          Write an unsigned integer.
 void writeUnsignedInt(long[] ints)
          Write an array of unsigned ints
 void writeUnsignedShort(int s)
          Write an unsigned short.
 void writeUnsignedShort(int[] shorts)
          Write an array of unsigned shorts.
 void writeUTF(String s)
           
static void writeUTF(String s, DataOutput dos)
          Write a UTF string to the data output stream.
 
Methods inherited from class org.freehep.util.io.BitOutputStream
byteAlign, close, finish, flushByte, minBits, minBits, minBits, writeBitFlag, writeFBits, writeSBits, writeUBits
 
Methods inherited from class org.freehep.util.io.CompressableOutputStream
startCompressing, write
 
Methods inherited from class java.io.FilterOutputStream
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, write
 

Field Detail

little

protected boolean little

written

protected int written
Constructor Detail

ByteOrderOutputStream

public ByteOrderOutputStream(OutputStream out)
Create a (Big Endian) Byte Order output stream from given stream

Parameters:
out - stream to write to

ByteOrderOutputStream

public ByteOrderOutputStream(OutputStream out,
                             boolean littleEndian)
Create a Byte Order output stream from the given stream

Parameters:
out - stream to write to
littleEndian - true if stream should be little endian
Method Detail

size

public int size()
         throws IOException
Returns:
number of written bytes
Throws:
IOException - if write fails FIXME, should this throw an exception ?

write

public void write(int b)
           throws IOException
Specified by:
write in interface DataOutput
Overrides:
write in class BitOutputStream
Throws:
IOException

writeBoolean

public void writeBoolean(boolean b)
                  throws IOException
Specified by:
writeBoolean in interface DataOutput
Throws:
IOException

writeChar

public void writeChar(int c)
               throws IOException
Specified by:
writeChar in interface DataOutput
Throws:
IOException

writeByte

public void writeByte(int b)
               throws IOException
Write a signed byte.

Specified by:
writeByte in interface DataOutput
Throws:
IOException

writeByte

public void writeByte(byte[] bytes)
               throws IOException
Writes array of bytes

Parameters:
bytes - byte array to be written
Throws:
IOException - if write fails

writeUnsignedByte

public void writeUnsignedByte(int ub)
                       throws IOException
Write an unsigned byte.

Parameters:
ub - byte to write
Throws:
IOException - if write fails

writeUnsignedByte

public void writeUnsignedByte(int[] bytes)
                       throws IOException
Write an array of unsigned bytes.

Parameters:
bytes - int array to write as bytes
Throws:
IOException - if write fails

writeShort

public void writeShort(int s)
                throws IOException
Write a signed short.

Specified by:
writeShort in interface DataOutput
Throws:
IOException

writeShort

public void writeShort(short[] shorts)
                throws IOException
Write an array of shorts.

Parameters:
shorts - short array to write
Throws:
IOException - if write fails

writeUnsignedShort

public void writeUnsignedShort(int s)
                        throws IOException
Write an unsigned short.

Parameters:
s - int to write as unsigned short
Throws:
IOException - if write fails

writeUnsignedShort

public void writeUnsignedShort(int[] shorts)
                        throws IOException
Write an array of unsigned shorts.

Parameters:
shorts - int array to write as unsigned shorts
Throws:
IOException - if write fails

writeInt

public void writeInt(int i)
              throws IOException
Write a signed integer.

Specified by:
writeInt in interface DataOutput
Throws:
IOException

writeInt

public void writeInt(int[] ints)
              throws IOException
Write an array of ints

Parameters:
ints - int array to write
Throws:
IOException - if write fails

writeUnsignedInt

public void writeUnsignedInt(long i)
                      throws IOException
Write an unsigned integer.

Parameters:
i - long to write as unsigned int
Throws:
IOException - if write fails

writeUnsignedInt

public void writeUnsignedInt(long[] ints)
                      throws IOException
Write an array of unsigned ints

Parameters:
ints - long array to write as unsigned ints
Throws:
IOException - if write fails

writeLong

public void writeLong(long l)
               throws IOException
Specified by:
writeLong in interface DataOutput
Throws:
IOException

writeFloat

public void writeFloat(float f)
                throws IOException
Specified by:
writeFloat in interface DataOutput
Throws:
IOException

writeDouble

public void writeDouble(double d)
                 throws IOException
Specified by:
writeDouble in interface DataOutput
Throws:
IOException

writeBytes

public void writeBytes(String s)
                throws IOException
Specified by:
writeBytes in interface DataOutput
Throws:
IOException

writeChars

public void writeChars(String s)
                throws IOException
Specified by:
writeChars in interface DataOutput
Throws:
IOException

writeString

public void writeString(String s)
                 throws IOException
Write a string (UTF)

Parameters:
s - string to write
Throws:
IOException - if write fails

writeUTF

public void writeUTF(String s)
              throws IOException
Specified by:
writeUTF in interface DataOutput
Throws:
IOException

writeAsciiZString

public void writeAsciiZString(String s)
                       throws IOException
Write an ascii-z (0 terminated c-string).

Parameters:
s - string to write
Throws:
IOException - if write fails

writeUTF

public static void writeUTF(String s,
                            DataOutput dos)
                     throws IOException
Write a UTF string to the data output stream. This method should have been in DataOutputStream, but is not visible.

Parameters:
s - string to write
dos - stream to write to
Throws:
IOException - if write fails


Copyright © 2000-2007 FreeHEP. All Rights Reserved.