org.apache.ws.commons.tcpmon.core.filter
Interface Stream

All Known Implementing Classes:
ReadOnlyStream

public interface Stream

Interface used by a filter to access the stream flowing through a pipeline.


Method Summary
 int available()
          Get the number of bytes currently available in the stream.
 byte discard()
          Discard the byte at the current position in the stream.
 void discard(int len)
          Discard a given number of bytes from the stream, starting at the current position.
 void error(String description)
           
 int get()
          Get the byte at the current position in the stream.
 int get(int lookahead)
          Get the byte at a given distance from the current position in the stream.
 void insert(byte b)
          Insert a byte at the current position in the stream.
 void insert(byte[] buffer, int offset, int length)
          Insert a byte sequence at the current position in the stream.
 void insert(ByteBuffer buffer)
          Insert the content of a byte buffer at the current position in the stream.
 boolean isEndOfStream()
          Check if the end of the stream has been reached.
 void popFilter()
           
 void pushFilter(StreamFilter filter)
           
 int read(byte[] buffer, int offset, int length)
          Read data from the stream into a byte array, starting from the current position in the stream.
 int read(ByteBuffer buffer)
          Read data from the stream into a byte buffer, starting from the current position in the stream.
 void readAll(OutputStream out)
          Read all currently available data from the stream and copy it to an OutputStream object.
 byte skip()
          Skip the byte at the current position in the stream.
 void skip(int len)
          Skip a given number of bytes in the stream, starting from the current position.
 void skipAll()
          Skip all the bytes currently available in the stream.
 

Method Detail

available

int available()
Get the number of bytes currently available in the stream.

Returns:
the number of available bytes

isEndOfStream

boolean isEndOfStream()
Check if the end of the stream has been reached.

Returns:
true if the end of the stream has been reached

get

int get()
Get the byte at the current position in the stream. Calling this method will not modify the current position in the stream.

Returns:
the byte at the current position in the stream or -1 if the end of the stream has been reached
Throws:
ArrayIndexOutOfBoundsException - if the byte at the current position is not yet available. This is the case if available() returns 0 and isEndOfStream() is returns false.

get

int get(int lookahead)
Get the byte at a given distance from the current position in the stream.

Parameters:
lookahead - the distance from the current position
Returns:
the byte at the given position, or -1 if the position is past the end of the stream
Throws:
ArrayIndexOutOfBoundsException - if the byte at the given position is not yet available

read

int read(byte[] buffer,
         int offset,
         int length)
Read data from the stream into a byte array, starting from the current position in the stream. Calling this method will not modify the current position in the stream.

Parameters:
buffer - the buffer into which the data is read
offset - the start offset in array buffer at which the data is written
length - the maximum number of bytes to read
Returns:
the total number of bytes read into the buffer

read

int read(ByteBuffer buffer)
Read data from the stream into a byte buffer, starting from the current position in the stream. Calling this method will not modify the current position in the stream. The number of bytes read is only limited by the number of available bytes in the stream and the remaining bytes in the buffer (as returned by Buffer.remaining().

Parameters:
buffer - the buffer into which the data is read
Returns:
the total number of bytes read into the buffer

readAll

void readAll(OutputStream out)
             throws IOException
Read all currently available data from the stream and copy it to an OutputStream object. Calling this method will not modify the current position in the stream.

Parameters:
out - the output stream to write the data to
Throws:
IOException - if an I/O error occurred when writing to the output stream

discard

byte discard()
Discard the byte at the current position in the stream. This method increments the current position without copying the byte to the next filter in the pipeline.

Returns:
the byte at the current position in the stream

discard

void discard(int len)
Discard a given number of bytes from the stream, starting at the current position.

Parameters:
len - the number of bytes to discard

insert

void insert(byte b)
Insert a byte at the current position in the stream. The logical position after invocation of this method will be just after the inserted byte, i.e. the inserted byte can't be read, discarded or skipped.

Parameters:
b - the byte to insert

insert

void insert(byte[] buffer,
            int offset,
            int length)
Insert a byte sequence at the current position in the stream. The logical position after invocation of this method will be just after the last inserted byte.

Parameters:
buffer - a byte array containing the sequence to be inserted in the stream
offset - the start offset in the byte array
length - the number of bytes to insert

insert

void insert(ByteBuffer buffer)
Insert the content of a byte buffer at the current position in the stream. The logical position after invocation of this method will be just after the last inserted byte.

Parameters:
buffer - the byte buffer containing the sequence to be inserted in the stream

skip

byte skip()
Skip the byte at the current position in the stream. This will increment the current position and copy the byte to the next filter.

Returns:
the byte at the current position in the stream

skip

void skip(int len)
Skip a given number of bytes in the stream, starting from the current position.

Parameters:
len - the number of bytes to skip

skipAll

void skipAll()
Skip all the bytes currently available in the stream. The instruction s.skipAll() is equivalent to s.skip(s.available()).


pushFilter

void pushFilter(StreamFilter filter)

popFilter

void popFilter()

error

void error(String description)


Copyright © The Apache Software Foundation. All Rights Reserved.