fr.umlv.tatoo.runtime.buffer.impl
Class ReadableByteChannelWrapper

java.lang.Object
  extended by fr.umlv.tatoo.runtime.buffer.impl.AbstractLexerBuffer
      extended by fr.umlv.tatoo.runtime.buffer.impl.ReadableByteChannelWrapper
All Implemented Interfaces:
LexerBuffer, TokenBuffer<ByteBuffer>

public class ReadableByteChannelWrapper
extends AbstractLexerBuffer

A ReadableByteChannelWrapper wraps a ReadableByteChannel in order to allow a lexer to process its content in order to have its tokens extracted.

Author:
Julien
See Also:
Lexer

Constructor Summary
ReadableByteChannelWrapper(boolean direct, int capacity, int increment, int chunkSize, ReadableByteChannel readable, LocationTracker tracker)
          Construct a ReadableByteChannelWrapper used by the lexer to process the ReadableByteChannel.
ReadableByteChannelWrapper(ReadableByteChannel readable, LocationTracker tracker)
          Constructs a ReadableByteChannelWrapper with default behavior.
 
Method Summary
protected  ByteBuffer allocateBuffer(boolean direct, int capacity)
           
protected  void discardImpl()
           
 ReadableByteChannel getReadableByteChannel()
           
 boolean hasRemaining()
          Returns true if more characters are availables in the buffer.
 int lastChar()
          Returns last read char or -1 if not available.
protected  int nextImpl()
          Returns next character in buffer without taking care of locations
 boolean previousWasNewLine()
          Determines if the last unwinded character was an end of line.
 boolean read()
          Reads at some bytes from the stream.
protected  void resetImpl()
          Moves current position back to first non unwinded character without taking care of locations
 void restart(ReadableByteChannel readableByteChannel)
           
protected  void restartImpl()
           
 String toString()
          Returns a String representation of the current token using the platform default encoding.
 String toString(String encoding)
          Returns a String representation of the current token using the specified encoding.
protected  void unwindImpl(int l)
          Performs unwind operation on buffer without taking care of locations
 ByteBuffer view()
          Returns the token part of the buffer as a ByteBuffer.
 
Methods inherited from class fr.umlv.tatoo.runtime.buffer.impl.AbstractLexerBuffer
discard, getLocationProvider, locationClear, next, reset, restart, unwind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fr.umlv.tatoo.runtime.buffer.TokenBuffer
discard
 

Constructor Detail

ReadableByteChannelWrapper

public ReadableByteChannelWrapper(ReadableByteChannel readable,
                                  LocationTracker tracker)
Constructs a ReadableByteChannelWrapper with default behavior.

Parameters:
readable - the readable to wrap

ReadableByteChannelWrapper

public ReadableByteChannelWrapper(boolean direct,
                                  int capacity,
                                  int increment,
                                  int chunkSize,
                                  ReadableByteChannel readable,
                                  LocationTracker tracker)
Construct a ReadableByteChannelWrapper used by the lexer to process the ReadableByteChannel. The parameters specify how the underlying buffer which stores data in allocated and reallocated when more space is needed.

Parameters:
direct - if the ByteBuffer must be direct
capacity - the initial capacity
increment - how much to increment the size of the buffer when more space is required
chunkSize - how many bytes are read at once is the input
readable - the input
tracker - the location tracker
Method Detail

allocateBuffer

protected ByteBuffer allocateBuffer(boolean direct,
                                    int capacity)

resetImpl

protected void resetImpl()
Description copied from class: AbstractLexerBuffer
Moves current position back to first non unwinded character without taking care of locations

Specified by:
resetImpl in class AbstractLexerBuffer
See Also:
LexerBuffer.reset()

unwindImpl

protected void unwindImpl(int l)
Description copied from class: AbstractLexerBuffer
Performs unwind operation on buffer without taking care of locations

Specified by:
unwindImpl in class AbstractLexerBuffer
Parameters:
l - the number of characters to unwind
See Also:
LexerBuffer.unwind(int)

previousWasNewLine

public boolean previousWasNewLine()
Description copied from interface: LexerBuffer
Determines if the last unwinded character was an end of line.

Returns:
true if the last unwinded character was an end of line; false otherwise

hasRemaining

public boolean hasRemaining()
Description copied from interface: LexerBuffer
Returns true if more characters are availables in the buffer. If the end of file has been reached and backtracked by lexer this method must return true.

Returns:
true if more characters are availables in the buffer

read

public boolean read()
             throws IOException
Description copied from interface: LexerBuffer
Reads at some bytes from the stream. This operation is optionnal and only used by SimpleLexer.run().

Specified by:
read in interface LexerBuffer
Returns:
false at end of stream
Throws:
IOException - if an i/o operation failed.

nextImpl

protected int nextImpl()
Description copied from class: AbstractLexerBuffer
Returns next character in buffer without taking care of locations

Specified by:
nextImpl in class AbstractLexerBuffer
Returns:
the next character in the buffer
See Also:
LexerBuffer.next()

restart

public void restart(ReadableByteChannel readableByteChannel)

getReadableByteChannel

public ReadableByteChannel getReadableByteChannel()

discardImpl

protected void discardImpl()
Specified by:
discardImpl in class AbstractLexerBuffer

toString

public String toString()
Returns a String representation of the current token using the platform default encoding. This method must only be used for debug since it is not efficient since it recreates the CharsetDecoder at each call.

Overrides:
toString in class Object
Returns:
a String representation of the current token
See Also:
Charset.defaultCharset()

toString

public String toString(String encoding)
Returns a String representation of the current token using the specified encoding. This method must only be used for debug since it is not efficient since it recreates the CharsetDecoder at each call.

Parameters:
encoding - the character encoding
Returns:
a String representation of the current token
See Also:
Charset

restartImpl

protected void restartImpl()
Specified by:
restartImpl in class AbstractLexerBuffer

view

public ByteBuffer view()
Returns the token part of the buffer as a ByteBuffer. The Buffer.limit() index must not be moved, the Buffer.position() can be moved, but any data before it can be discarded by the wrapper.

Returns:
the token part of the buffer as a ByteBuffer

lastChar

public int lastChar()
Description copied from interface: LexerBuffer
Returns last read char or -1 if not available. This method is used for logging and error reporting. This operation is optional since this method can return -1 anytime

Returns:
last read char or -1 if not available