com.nhncorp.neptune.common.io
Class NDataInputBuffer

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.DataInputStream
              extended by com.nhncorp.neptune.common.io.NDataInputBuffer
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput

public class NDataInputBuffer
extends java.io.DataInputStream

A reusable DataInput implementation that reads from an in-memory buffer.

This saves memory over creating a new DataInputStream and ByteArrayInputStream each time data is read.

Typical usage is something like the following:


 DataInputBuffer buffer = new DataInputBuffer();
 while (... loop condition ...) {
   byte[] data = ... get data ...;
   int dataLength = ... get data length ...;
   buffer.reset(data, dataLength);
   ... read buffer using DataInput methods ...
 }
 

Author:
Doug Cutting

Constructor Summary
NDataInputBuffer()
          Constructs a new empty buffer.
 
Method Summary
 int getLength()
          Returns the length of the input.
 int getPosition()
          Returns the current position in the input.
 void reset(byte[] input, int length)
          Resets the data that the buffer reads.
 void reset(byte[] input, int start, int length)
          Resets the data that the buffer reads.
 
Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytes
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NDataInputBuffer

public NDataInputBuffer()
Constructs a new empty buffer.

Method Detail

reset

public void reset(byte[] input,
                  int length)
Resets the data that the buffer reads.


reset

public void reset(byte[] input,
                  int start,
                  int length)
Resets the data that the buffer reads.


getPosition

public int getPosition()
Returns the current position in the input.


getLength

public int getLength()
Returns the length of the input.