pt.tumba.parser.swf
Class OutStream

java.lang.Object
  extended by pt.tumba.parser.swf.OutStream

public class OutStream
extends java.lang.Object

Output Stream Wrapper

Author:
unknown

Field Summary
protected  int bitBuf
          Description of the Field
protected  int bitPos
          Description of the Field
protected  long bytesWritten
          Description of the Field
protected  java.io.OutputStream out
          Description of the Field
 
Constructor Summary
OutStream(java.io.OutputStream out)
          Constructor for the OutStream object
 
Method Summary
 void close()
          Description of the Method
static int determineSignedBitSize(int value)
          Determine the minimum number of bits required to hold the given signed value
static int determineUnsignedBitSize(long value)
          Determine the minimum number of bits required to hold the given unsigned value (may be zero)
 void flush()
          Description of the Method
 void flushBits()
          Flush the bit buffer to the output stream and reset values
static boolean getBit(int bitNum, long value)
          Get the given bit (where lowest bit is numbered 1)
 long getBytesWritten()
          Gets the bytesWritten attribute of the OutStream object
static int getStringLength(byte[] string)
          Calculate the byte length of a string as it would be written to the output stream
static int getStringLength(java.lang.String string)
          Calculate the byte length of a string as it would be written to the output stream using the default character encoding
protected  void initBits()
          Reset the bit buffer
static int setBit(int bitNum, int value)
          Set the given bit (where lowest bit is numbered 1)
 void setBytesWritten(long written)
          Sets the bytesWritten attribute of the OutStream object
static byte[] sintTo2Bytes(int value)
          Util to convert a signed int to 2 bytes
static byte[] uintTo2Bytes(int value)
          Util to convert an unsigned int to 2 bytes
static byte[] uintTo4Bytes(int value)
          Util to convert an unsigned int to 4 bytes
static byte uintToByte(int value2)
          Util to convert an unsigned int to an unsigned byte
 void write(byte[] bytes)
          Write the given bytes to the output stream
 void write(byte[] bytes, int start, int length)
          Write the given bytes to the output stream
 void writeDouble(double value)
          Write a double value
 void writeFloat(float value)
          Write a float value
 void writeSBits(int numBits, int value)
          Write a signed value to the output stream in the given number of bits.
 void writeSI16(short value)
          Write a 16 bit signed value to the out stream
 void writeSI32(int value)
          Write a 32 bit signed value
 void writeString(byte[] string)
          Write a string to the output stream and add terminating null
 void writeString(java.lang.String s2)
          Write a string to the output stream using the default encoding and add terminating null
 void writeUBits(int numBits, long value)
          Write an unsigned value to the output stream in the given number of bits
 void writeUI16(int value)
          Write a 16 bit unsigned value to the out stream
 void writeUI32(long value)
          Write a 32 bit unsigned value to the out stream
 void writeUI8(int value)
          Write an 8 bit unsigned value to the out stream
 
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
Description of the Field


bytesWritten

protected long bytesWritten
Description of the Field


bitBuf

protected int bitBuf
Description of the Field


bitPos

protected int bitPos
Description of the Field

Constructor Detail

OutStream

public OutStream(java.io.OutputStream out)
Constructor for the OutStream object

Parameters:
out - Description of the Parameter
Method Detail

getBytesWritten

public long getBytesWritten()
Gets the bytesWritten attribute of the OutStream object

Returns:
The bytesWritten value

setBytesWritten

public void setBytesWritten(long written)
Sets the bytesWritten attribute of the OutStream object

Parameters:
written - The new bytesWritten value

writeSBits

public void writeSBits(int numBits,
                       int value)
                throws java.io.IOException
Write a signed value to the output stream in the given number of bits. The value must actually fit in that number of bits or it will be garbled

Parameters:
numBits - Description of the Parameter
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

flush

public void flush()
           throws java.io.IOException
Description of the Method

Throws:
java.io.IOException - Description of the Exception

close

public void close()
           throws java.io.IOException
Description of the Method

Throws:
java.io.IOException - Description of the Exception

flushBits

public void flushBits()
               throws java.io.IOException
Flush the bit buffer to the output stream and reset values

Throws:
java.io.IOException - Description of the Exception

writeUBits

public void writeUBits(int numBits,
                       long value)
                throws java.io.IOException
Write an unsigned value to the output stream in the given number of bits

Parameters:
numBits - Description of the Parameter
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

getBit

public static boolean getBit(int bitNum,
                             long value)
Get the given bit (where lowest bit is numbered 1)

Parameters:
bitNum - Description of the Parameter
value - Description of the Parameter
Returns:
The bit value

setBit

public static int setBit(int bitNum,
                         int value)
Set the given bit (where lowest bit is numbered 1)

Parameters:
bitNum - The new bit value
value - The new bit value
Returns:
Description of the Return Value

write

public void write(byte[] bytes)
           throws java.io.IOException
Write the given bytes to the output stream

Parameters:
bytes - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

write

public void write(byte[] bytes,
                  int start,
                  int length)
           throws java.io.IOException
Write the given bytes to the output stream

Parameters:
bytes - Description of the Parameter
start - Description of the Parameter
length - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeUI8

public void writeUI8(int value)
              throws java.io.IOException
Write an 8 bit unsigned value to the out stream

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeUI16

public void writeUI16(int value)
               throws java.io.IOException
Write a 16 bit unsigned value to the out stream

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeSI16

public void writeSI16(short value)
               throws java.io.IOException
Write a 16 bit signed value to the out stream

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeUI32

public void writeUI32(long value)
               throws java.io.IOException
Write a 32 bit unsigned value to the out stream

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeString

public void writeString(java.lang.String s2)
                 throws java.io.IOException
Write a string to the output stream using the default encoding and add terminating null

Parameters:
s - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeString

public void writeString(byte[] string)
                 throws java.io.IOException
Write a string to the output stream and add terminating null

Parameters:
string - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

getStringLength

public static int getStringLength(byte[] string)
Calculate the byte length of a string as it would be written to the output stream

Parameters:
string - Description of the Parameter
Returns:
The stringLength value

getStringLength

public static int getStringLength(java.lang.String string)
Calculate the byte length of a string as it would be written to the output stream using the default character encoding

Parameters:
string - Description of the Parameter
Returns:
The stringLength value

initBits

protected void initBits()
Reset the bit buffer


determineSignedBitSize

public static int determineSignedBitSize(int value)
Determine the minimum number of bits required to hold the given signed value

Parameters:
value - Description of the Parameter
Returns:
Description of the Return Value

determineUnsignedBitSize

public static int determineUnsignedBitSize(long value)
Determine the minimum number of bits required to hold the given unsigned value (may be zero)

Parameters:
value - Description of the Parameter
Returns:
Description of the Return Value

writeFloat

public void writeFloat(float value)
                throws java.io.IOException
Write a float value

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeDouble

public void writeDouble(double value)
                 throws java.io.IOException
Write a double value

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

writeSI32

public void writeSI32(int value)
               throws java.io.IOException
Write a 32 bit signed value

Parameters:
value - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

sintTo2Bytes

public static byte[] sintTo2Bytes(int value)
Util to convert a signed int to 2 bytes

Parameters:
value - Description of the Parameter
Returns:
Description of the Return Value

uintTo2Bytes

public static byte[] uintTo2Bytes(int value)
Util to convert an unsigned int to 2 bytes

Parameters:
value - Description of the Parameter
Returns:
Description of the Return Value

uintTo4Bytes

public static byte[] uintTo4Bytes(int value)
Util to convert an unsigned int to 4 bytes

Parameters:
value - Description of the Parameter
Returns:
Description of the Return Value

uintToByte

public static byte uintToByte(int value2)
Util to convert an unsigned int to an unsigned byte

Parameters:
value - Description of the Parameter
Returns:
Description of the Return Value