org.jwall.web.http.nio
Class BufferedReadableByteChannel

java.lang.Object
  extended by org.jwall.web.http.nio.BufferedReadableByteChannel
All Implemented Interfaces:
Closeable, Channel, ReadableByteChannel

public class BufferedReadableByteChannel
extends Object
implements ReadableByteChannel

This class implements a few convenient methods, mainly for reading a newline terminated line from a channel. It relies on a standard readable byte channel provided by a number of JDK classes, which are given to the constructor at creation time.

Author:
Christian Bockermann <chris@jwall.org>

Constructor Summary
BufferedReadableByteChannel(ReadableByteChannel input)
          This constructor creates a new instance of this class with an internal buffer of 32k bytes.
BufferedReadableByteChannel(ReadableByteChannel input, int bufSize)
          This constructor creates a new instance of this class with an internal buffer of the given buffer-size.
 
Method Summary
 void close()
           
 boolean isOpen()
           
 int read(ByteBuffer dst)
           
 String readLine()
          This method tries to read a full line, terminated by a \n newline character, from the currently available bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedReadableByteChannel

public BufferedReadableByteChannel(ReadableByteChannel input)
This constructor creates a new instance of this class with an internal buffer of 32k bytes.

Parameters:
input - The byte-channel this instance reads from.

BufferedReadableByteChannel

public BufferedReadableByteChannel(ReadableByteChannel input,
                                   int bufSize)
This constructor creates a new instance of this class with an internal buffer of the given buffer-size.

Parameters:
input -
bufSize -
Method Detail

readLine

public String readLine()
                throws IOException
This method tries to read a full line, terminated by a \n newline character, from the currently available bytes. If there can no complete line be read (i.e. no newline char in the buffer), then the method transfers the currently available bytes into a "partial complete line" and immediately returns null.

Returns:
A new-line terminated line or null if no complete line can be read from the currently available bytes.
Throws:
IOExecption - in case
IOException

read

public int read(ByteBuffer dst)
         throws IOException
Specified by:
read in interface ReadableByteChannel
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Throws:
IOException
See Also:
Channel.close()

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Channel
See Also:
Channel.isOpen()


Copyright © 2012 jwall.org. All Rights Reserved.