org.jfree.pixie.wmf

Class Buffer

Known Direct Subclasses:
MfHeader, MfRecord

public class Buffer
extends java.lang.Object

A block of raw mmeory. This is used to store various metafile objects as they are read in from file.

Constructor Summary

Buffer()
Default Constructor.
Buffer(int length)
Defines a new buffer with the given initial size in bytes.

Method Summary

int
getByte(int offset)
Return the 8-bit int at the given byte offset.
InputStream
getInputStream(int offset)
Gets an input stream to read from the memory buffer.
int
getInt(int offset)
Return the 32-bit int at the given byte offset.
int
getLength()
The size of the stored data in the memory.
int
getShort(int offset)
Return the 16-bit int at the given byte offset.
String
getString(int offset, int len)
Return the null-terminated string at the given byte offset with the given maximum length.
protected void
move(int sourceoffset, int length, int targetoffset)
Moves the buffer contents from the source offset to the target offset, the areas should not overlap.
void
read(InputStream in, int offset, int len)
Read len bytes into the memory from a stream and stores the read bytes at the given offset.
void
setByte(int offset, int value)
Sets the byte at the given offset.
protected void
setCapacity(int capacity)
Ensures that the buffer has enough space for the given number of bytes.
void
setInt(int offset, int value)
Set the int value as big-endian.
protected void
setLength(int len)
Extends the length to the given new size.
void
setShort(int offset, int shortval)
Stores the given short as BigEndian value.
void
setString(int offset, String str)
Writes the given string as byte stream using the plattforms default encoding.

Constructor Details

Buffer

protected Buffer()
Default Constructor. Defines a buffer without an initial size.

Buffer

protected Buffer(int length)
Defines a new buffer with the given initial size in bytes.
Parameters:
length - the length of the buffer in bytes.

Method Details

getByte

public int getByte(int offset)
Return the 8-bit int at the given byte offset.
Parameters:
offset - the offset from where to read the byte
Returns:
the byte read.

getInputStream

public InputStream getInputStream(int offset)
Gets an input stream to read from the memory buffer.
Parameters:
offset - the offse, from where to read.
Returns:
the InputStream.

getInt

public int getInt(int offset)
Return the 32-bit int at the given byte offset.
Parameters:
offset - the offset where the integer value is stored in the memory
Returns:
the integer.

getLength

public final int getLength()
The size of the stored data in the memory.

getShort

public int getShort(int offset)
Return the 16-bit int at the given byte offset.
Parameters:
offset - the offset from where to read the short.
Returns:
the short.

getString

public String getString(int offset,
                        int len)
Return the null-terminated string at the given byte offset with the given maximum length.
Parameters:
offset - the offset where the string starts
len - the maximum length of the string
Returns:
the null-terminated string read.

move

protected void move(int sourceoffset,
                    int length,
                    int targetoffset)
Moves the buffer contents from the source offset to the target offset, the areas should not overlap.
Parameters:
sourceoffset -
length -
targetoffset -

read

public void read(InputStream in,
                 int offset,
                 int len)
            throws IOException
Read len bytes into the memory from a stream and stores the read bytes at the given offset.
Parameters:
in - the input stream that should be used
offset - the offset
len - the number bytes that should be read.

setByte

public void setByte(int offset,
                    int value)
Sets the byte at the given offset.
Parameters:
offset - the offset.
value - the byte that should be set.

setCapacity

protected void setCapacity(int capacity)
Ensures that the buffer has enough space for the given number of bytes.
Parameters:
capacity - the new capacity that should be ensured.

setInt

public void setInt(int offset,
                   int value)
Set the int value as big-endian.
Parameters:
offset - the offset where to set the int value.
value - the integer value that should be set.

setLength

protected void setLength(int len)
Extends the length to the given new size.
Parameters:
len - the new length.

setShort

public void setShort(int offset,
                     int shortval)
Stores the given short as BigEndian value.
Parameters:
offset - the offset.
shortval - the shortvalue.

setString

public void setString(int offset,
                      String str)
Writes the given string as byte stream using the plattforms default encoding.
Parameters:
offset - the offset, where to store the string.
str - the string that should be stored in the Wmf.