com.flagstone.transform.coder
Class SWFDecoder

java.lang.Object
  extended by com.flagstone.transform.coder.SWFDecoder

public final class SWFDecoder
extends Object

SWFDecoder wraps an InputStream with a buffer to reduce the amount of memory required to decode a movie and to improve efficiency by reading data from a file or external source in blocks.


Field Summary
static int BUFFER_SIZE
          The default size, in bytes, for the internal buffer.
 
Constructor Summary
SWFDecoder(InputStream streamIn)
          Create a new SWFDecoder for the underlying InputStream using the default buffer size.
SWFDecoder(InputStream streamIn, int length)
          Create a new SWFDecoder for the underlying InputStream with the specified buffer size.
 
Method Summary
 void alignToByte()
          Changes the location to the next byte boundary.
 int bytesRead()
          Get the number of bytes read from the last saved position.
 void check(int count)
          Compare the number of bytes read since the last saved position and record any difference.
 void fill()
          Fill the internal buffer.
 int getDelta()
          Get the difference from the expected number of bytes from the last call to check().
 int getExpected()
          Get the expected number of bytes from the last call to check().
 int getLocation()
          Get the location recorded for the last call to check().
 int mark()
          Remember the current position.
 int readBits(int numberOfBits, boolean signed)
          Read a bit field.
 int readByte()
          Read an unsigned byte.
 byte[] readBytes(byte[] bytes)
          Reads an array of bytes.
 float readHalf()
          Read a single-precision floating point number.
 int readInt()
          Read an unsigned 32-bit integer.
 int readSignedShort()
          Read an unsigned 16-bit integer.
 String readString()
          Read a null-terminated string using the default character set defined in the decoder.
 String readString(int length)
          Read a string using the default character set defined in the decoder.
 int readUnsignedShort()
          Read an unsigned 16-bit integer.
 int readVarInt()
          Read a 32-bit unsigned integer, encoded using a variable number of bytes.
 void reset()
          Reposition the decoder to the point recorded by the last call to the mark() method.
 int scanBits(int numberOfBits, boolean signed)
          Read-ahead a bit field.
 int scanByte()
          Read an unsigned byte but do not advance the internal pointer.
 int scanUnsignedShort()
          Read an unsigned 16-bit integer.
 void setEncoding(CharacterEncoding enc)
          Sets the character encoding scheme used when encoding or decoding strings.
 void skip(int count)
          Skips over and discards n bytes of data.
 void unmark()
          Discard the last saved position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
The default size, in bytes, for the internal buffer.

See Also:
Constant Field Values
Constructor Detail

SWFDecoder

public SWFDecoder(InputStream streamIn,
                  int length)
Create a new SWFDecoder for the underlying InputStream with the specified buffer size.

Parameters:
streamIn - the stream from which data will be read.
length - the size in bytes of the buffer.

SWFDecoder

public SWFDecoder(InputStream streamIn)
Create a new SWFDecoder for the underlying InputStream using the default buffer size.

Parameters:
streamIn - the stream from which data will be read.
Method Detail

fill

public void fill()
          throws IOException
Fill the internal buffer. Any unread bytes are copied to the start of the buffer and the remaining space is filled with data from the underlying stream.

Throws:
IOException - if an error occurs reading from the underlying input stream.

mark

public int mark()
Remember the current position.

Returns:
the current position.

unmark

public void unmark()
Discard the last saved position.


reset

public void reset()
           throws IOException
Reposition the decoder to the point recorded by the last call to the mark() method.

Throws:
IOException - if the internal buffer was filled after mark() was called.

check

public void check(int count)
Compare the number of bytes read since the last saved position and record any difference.

Parameters:
count - the expected number of bytes read.

getLocation

public int getLocation()
Get the location recorded for the last call to check().

Returns:
the position in the buffer of the call to mark() used by check().

getExpected

public int getExpected()
Get the expected number of bytes from the last call to check().

Returns:
the difference from the expected number of bytes decoded.

getDelta

public int getDelta()
Get the difference from the expected number of bytes from the last call to check().

Returns:
the difference from the expected number of bytes decoded.

bytesRead

public int bytesRead()
Get the number of bytes read from the last saved position.

Returns:
the number of bytes read since the mark() method was last called.

alignToByte

public void alignToByte()
Changes the location to the next byte boundary.


skip

public void skip(int count)
          throws IOException
Skips over and discards n bytes of data.

Parameters:
count - the number of bytes to skip.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readBits

public int readBits(int numberOfBits,
                    boolean signed)
             throws IOException
Read a bit field.

Parameters:
numberOfBits - the number of bits to read.
signed - indicates whether the integer value read is signed.
Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

scanBits

public int scanBits(int numberOfBits,
                    boolean signed)
             throws IOException
Read-ahead a bit field.

Parameters:
numberOfBits - the number of bits to read.
signed - indicates whether the integer value read is signed.
Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

scanByte

public int scanByte()
             throws IOException
Read an unsigned byte but do not advance the internal pointer.

Returns:
an 8-bit unsigned value.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readByte

public int readByte()
             throws IOException
Read an unsigned byte.

Returns:
an 8-bit unsigned value.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readBytes

public byte[] readBytes(byte[] bytes)
                 throws IOException
Reads an array of bytes.

Parameters:
bytes - the array that will contain the bytes read.
Returns:
the array of bytes.
Throws:
IOException - if an error occurs reading from the underlying input stream.

setEncoding

public void setEncoding(CharacterEncoding enc)
Sets the character encoding scheme used when encoding or decoding strings.

Parameters:
enc - the CharacterEncoding that identifies how strings are encoded.

readString

public String readString(int length)
                  throws IOException
Read a string using the default character set defined in the decoder.

Parameters:
length - the number of bytes to read.
Returns:
the decoded string.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readString

public String readString()
                  throws IOException
Read a null-terminated string using the default character set defined in the decoder.

Returns:
the decoded string.
Throws:
IOException - if an error occurs reading from the underlying input stream.

scanUnsignedShort

public int scanUnsignedShort()
                      throws IOException
Read an unsigned 16-bit integer.

Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Read an unsigned 16-bit integer.

Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readSignedShort

public int readSignedShort()
                    throws IOException
Read an unsigned 16-bit integer.

Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readInt

public int readInt()
            throws IOException
Read an unsigned 32-bit integer.

Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readVarInt

public int readVarInt()
               throws IOException
Read a 32-bit unsigned integer, encoded using a variable number of bytes.

Returns:
the value read.
Throws:
IOException - if an error occurs reading from the underlying input stream.

readHalf

public float readHalf()
               throws IOException
Read a single-precision floating point number.

Returns:
the value.
Throws:
IOException - if an error occurs reading from the underlying input stream.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.