org.apache.geronimo.javamail.store.imap.connection
Class IMAPResponseBuffer

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by org.apache.geronimo.javamail.store.imap.connection.IMAPResponseBuffer
All Implemented Interfaces:
Closeable, Flushable

public class IMAPResponseBuffer
extends ByteArrayOutputStream

Simple extension to the ByteArrayOutputStream to allow inspection of the data while it is being accumulated.


Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
IMAPResponseBuffer()
           
 
Method Summary
 int getLiteralLength()
          Retrieve an IMAP literal length value from the buffer.
 int lastByte()
          Return the last byte written to the output stream.
 int lastIndex(byte target)
          Search backwards through the buffer for a given byte.
 int read(byte[] buffer, int offset, int length)
          Read a buffer of data from the output stream's accumulator buffer.
 int read(int index)
          Read a character from the byte array output stream buffer at the give position.
 
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IMAPResponseBuffer

public IMAPResponseBuffer()
Method Detail

read

public int read(int index)
Read a character from the byte array output stream buffer at the give position.

Parameters:
index - The requested index.
Returns:
The byte at the target index, or -1 if the index is out of bounds.

read

public int read(byte[] buffer,
                int offset,
                int length)
Read a buffer of data from the output stream's accumulator buffer. This will copy the data into a target byte arrain.

Parameters:
buffer - The target byte array for returning the data.
offset - The offset of the source data within the output stream buffer.
length - The desired length.
Returns:
The count of bytes transferred into the buffer.

lastIndex

public int lastIndex(byte target)
Search backwards through the buffer for a given byte.

Parameters:
target - The search character.
Returns:
The index relative to the buffer start of the given byte. Returns -1 if not found.

lastByte

public int lastByte()
Return the last byte written to the output stream. Returns -1 if the stream is empty.

Returns:
The last byte written (or -1 if the stream is empty).

getLiteralLength

public int getLiteralLength()
Retrieve an IMAP literal length value from the buffer. We have a literal length value IFF the last characters written to the buffer have the form "{nnnn}". This returns the integer value of the info inside the curly braces. Returns -1 if a valid literal length is not found.

Returns:
A literal length value, or -1 if we don't have a literal signature at the end.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.