libperun

Class std.io.Buffer

Synopsis

public final class Buffer

A container for arbitrary data.

Fields

Constructors

public Buffer();

Construct an empty buffer.

public Buffer(int size);

Construct a buffer of the specified initial size.

The contents are initially all zeroes.

Methods

public int size();

Get the current size of the buffer.

public void resize(int newSize);

Change the size of the buffer.

If the new size is shorter than the current size, then data at the end is truncated; if the new size is larger, then the buffer is padded with zero bytes at the end.

Arguments
newSizeThe desired new size in bytes.
public void put(int pos,byte_t[] bytes);

Update buffer contents.

The contents of the specified byte array are written at the specified byte position in the buffer. If the buffer is too small to fit the data there, it is automatically expanded to accomodate it.

Arguments
posByte offset into the buffer where the array will be written.
bytesByte array to copy from.
public int get(int pos,byte_t[] out);

Read buffer contents.

The specified byte array will contain the data which has been read. This method begins reading at the specified position within the buffer, and contains until either the given byte array is full, or the end of the buffer was reached. It returns the number of bytes successfully read and places in the array.

Arguments
posByte offset into the buffer where reading will begin.
bytesByte array to fill.
Returns

The number of bytes read.