8.69. File tom/StreamBuffer

class tom.BufferedStream

inherits

State supers: StreamStream, InputOutputStream, Conditions

variables

const DEFAULT_BUFFER_SIZE = 8192;

The default value of the default size for the buffers of our instances.

static int default_buffer_size;

The default size for the buffers of our instances. If anyone sets this to a negative number, s/he should be ni'd.

methods


void
  load MutableArray arguments;

Undocumented.

instance tom.BufferedStream

variables

MutableByteArray buffer;

The buffer we use.

int num;

The number of elements in the buffer.

int next;

The index of the first character not yet handled (i.e. read or written).

methods


id
  init Stream s;

Initialize the newly allocated instance to buffer the stream s with a buffer sized the default_buffer_size.


id
        init Stream s
  bufferSize int cap;

Designated initializer. Initialize the newly allocated instance to buffer the stream s with a buffer sized cap.


int
  peek;

Return the value of the next byte to be returned by read, or -1 upon an error or end-of-file. This does not actually read the byte.


void
  unget byte b;

Stuff the byte b back (sort-of) into the stream. It will be the next byte to be read.


id
  flushOutput;

Flush any bytes buffered to the stream this instance is buffering.


void
  write byte b;

Write the byte b, raising a stream-error on error.


int
  write byte b;

Write the byte b, returning 1 upon success.


int
  writeBytes int length
        from pointer address;

Write to this stream the length bytes residing in memory at address.


byte
  read;

Return the next byte, raising a stream-eos upon an error or end-of-file.


int
  read;

Return the value of the next byte read, or -1 upon an error or end-of-file.


int (num_read)
  readRange (int, int) (start, length)
       into MutableByteArray destination;

Read at most length bytes into the destination, writing them from start. Return the number of bytes actually read.


protected int
  readBuffer;

Fill the buffer by reading more bytes from the stream. Return the number of bytes read.


protected int
  writeBuffer;

Write any bytes needing to be output to the stream. Return the number of bytes written.