com.flagstone.transform.coder
Class SWFEncoder

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

public final class SWFEncoder
extends Object

SWFEncoder wraps an OutputStream with a buffer to reduce the amount of memory required to encode a movie and to improve efficiency by writing data to a file or external source in blocks.


Field Summary
static int BUFFER_SIZE
          The default size, in bytes, for the internal buffer.
 
Constructor Summary
SWFEncoder(OutputStream streamOut)
          Create a new SWFEncoder for the underlying InputStream using the default buffer size.
SWFEncoder(OutputStream streamOut, int length)
          Create a new SWFEncoder for the underlying InputStream with the specified buffer size.
 
Method Summary
 void alignToByte()
          Changes the location to the next byte boundary.
 void check(int expected)
          Compare the number of bytes read with the expected number and throw an exception if there is a difference.
 void flush()
          Write the data currently stored in the buffer to the underlying stream.
 int mark()
          Remember the current position.
 void setEncoding(CharacterEncoding enc)
          Sets the character encoding scheme used when encoding or decoding strings.
 void unmark()
          Discard the last saved position.
 void writeBits(int value, int numberOfBits)
          Write a value to bit field.
 void writeByte(int value)
          Write a byte.
 int writeBytes(byte[] bytes)
          Write an array of bytes.
 void writeHalf(float value)
          Write a single-precision floating point number.
 void writeInt(int value)
          Write a 32-bit integer.
 void writeShort(int value)
          Write a 16-bit integer.
 void writeString(String str)
          Write a string using the default character set defined in the encoder.
 void writeVarInt(int value)
          Write a 32-bit unsigned integer, encoded in a variable number of bytes.
 
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

SWFEncoder

public SWFEncoder(OutputStream streamOut,
                  int length)
Create a new SWFEncoder for the underlying InputStream with the specified buffer size.

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

SWFEncoder

public SWFEncoder(OutputStream streamOut)
Create a new SWFEncoder for the underlying InputStream using the default buffer size.

Parameters:
streamOut - the stream from which data will be written.
Method Detail

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.

mark

public int mark()
Remember the current position.

Returns:
the current position.

unmark

public void unmark()
Discard the last saved position.


check

public void check(int expected)
           throws CoderException
Compare the number of bytes read with the expected number and throw an exception if there is a difference.

Parameters:
expected - the expected number of bytes read.
Throws:
CoderException - if the number of bytes read is different from the expected number.

alignToByte

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


flush

public void flush()
           throws IOException
Write the data currently stored in the buffer to the underlying stream.

Throws:
IOException - if an error occurs while writing the data to the stream.

writeBits

public void writeBits(int value,
                      int numberOfBits)
               throws IOException
Write a value to bit field.

Parameters:
value - the value.
numberOfBits - the (least significant) number of bits that will be written.
Throws:
IOException - if there is an error writing data to the underlying stream.

writeByte

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

Parameters:
value - the value to be written - only the least significant byte will be written.
Throws:
IOException - if there is an error writing data to the underlying stream.

writeBytes

public int writeBytes(byte[] bytes)
               throws IOException
Write an array of bytes.

Parameters:
bytes - the array to be written.
Returns:
the number of bytes written.
Throws:
IOException - if there is an error reading data from the underlying stream.

writeString

public void writeString(String str)
                 throws IOException
Write a string using the default character set defined in the encoder.

Parameters:
str - the string.
Throws:
IOException - if there is an error reading data from the underlying stream.

writeShort

public void writeShort(int value)
                throws IOException
Write a 16-bit integer.

Parameters:
value - an integer containing the value to be written.
Throws:
IOException - if there is an error reading data from the underlying stream.

writeInt

public void writeInt(int value)
              throws IOException
Write a 32-bit integer.

Parameters:
value - an integer containing the value to be written.
Throws:
IOException - if there is an error reading data from the underlying stream.

writeVarInt

public void writeVarInt(int value)
                 throws IOException
Write a 32-bit unsigned integer, encoded in a variable number of bytes.

Parameters:
value - an integer containing the value to be written.
Throws:
IOException - if there is an error reading data from the underlying stream.

writeHalf

public void writeHalf(float value)
               throws IOException
Write a single-precision floating point number.

Parameters:
value - the value to be written.
Throws:
IOException - if there is an error reading data from the underlying stream.


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