com.bigdata.io
Class DataInputBuffer

java.lang.Object
  extended by java.io.InputStream
      extended by com.bigdata.io.DataInputBuffer
All Implemented Interfaces:
it.unimi.dsi.fastutil.io.RepositionableStream, Closeable, DataInput

public class DataInputBuffer
extends InputStream
implements DataInput, it.unimi.dsi.fastutil.io.RepositionableStream

A fast implementation of DataInput designed to read from a byte[].

Version:
$Id: DataInputBuffer.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
DataOutputBuffer, DataInputStream

Constructor Summary
DataInputBuffer(byte[] buf)
          Prepare for reading from the byte[].
DataInputBuffer(byte[] buf, int off, int len)
          Prepare for reading from the byte[].
DataInputBuffer(ByteArrayBuffer buf)
          Prepare for reading from the buffer.
 
Method Summary
 long position()
          Report the position of the stream within its slice (relative to the original offset for the backing buffer)
 void position(long v)
          Reposition the stream within its slice (relative to the original offset for the backing buffer).
 int read()
           
 int read(byte[] a, int aoff, int alen)
          Overridden for more efficiency.
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 double readDouble()
           
 float readFloat()
           
 void readFully(byte[] b)
           
 void readFully(byte[] a, int aoff, int alen)
           
 int readInt()
           
 String readLine()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
 void setBuffer(byte[] buf)
          Replaces the buffer and resets the offset to zero (0).
 void setBuffer(byte[] buf, int off, int len)
          Replaces the buffer and reset the offset and length to the specified values.
 void setBuffer(ByteArrayBuffer buf)
          Replaces the buffer reference with ByteArrayBuffer.array() and resets the offset and length to the ByteArrayBuffer.pos() and the ByteArrayBuffer.limit() respectively.
 int skipBytes(int n)
           
 long unpackLong()
          Unpack a long value from the current buffer position.
 short unpackShort()
          Unpack a non-negative short value from the input stream.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataInputBuffer

public DataInputBuffer(byte[] buf)
Prepare for reading from the byte[].

Parameters:
buf - The source data.

DataInputBuffer

public DataInputBuffer(byte[] buf,
                       int off,
                       int len)
Prepare for reading from the byte[].

Parameters:
buf - The source data.
off - The offset of the first byte to be read.
len - The #of bytes available.

DataInputBuffer

public DataInputBuffer(ByteArrayBuffer buf)
Prepare for reading from the buffer. The bytes between the ByteArrayBuffer.pos() and the ByteArrayBuffer.limit() will be read.

Parameters:
buf - The buffer.
Method Detail

setBuffer

public void setBuffer(byte[] buf)
Replaces the buffer and resets the offset to zero (0).

Parameters:
buf - The new buffer.

setBuffer

public void setBuffer(byte[] buf,
                      int off,
                      int len)
Replaces the buffer and reset the offset and length to the specified values.

Parameters:
buf - The new buffer.
off -
len -

setBuffer

public void setBuffer(ByteArrayBuffer buf)
Replaces the buffer reference with ByteArrayBuffer.array() and resets the offset and length to the ByteArrayBuffer.pos() and the ByteArrayBuffer.limit() respectively.

Parameters:
buf - The buffer.

readBoolean

public boolean readBoolean()
                    throws IOException
Specified by:
readBoolean in interface DataInput
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

readByte

public byte readByte()
              throws IOException
Specified by:
readByte in interface DataInput
Throws:
IOException

readChar

public char readChar()
              throws IOException
Specified by:
readChar in interface DataInput
Throws:
IOException

readDouble

public double readDouble()
                  throws IOException
Specified by:
readDouble in interface DataInput
Throws:
IOException

readFloat

public float readFloat()
                throws IOException
Specified by:
readFloat in interface DataInput
Throws:
IOException

readFully

public final void readFully(byte[] b)
                     throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

readFully

public final void readFully(byte[] a,
                            int aoff,
                            int alen)
                     throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

read

public final int read(byte[] a,
                      int aoff,
                      int alen)
               throws IOException
Overridden for more efficiency.

Overrides:
read in class InputStream
Throws:
IOException

readInt

public int readInt()
            throws IOException
Specified by:
readInt in interface DataInput
Throws:
IOException

readLine

public String readLine()
                throws IOException
Specified by:
readLine in interface DataInput
Throws:
IOException

readLong

public long readLong()
              throws IOException
Specified by:
readLong in interface DataInput
Throws:
IOException

readShort

public short readShort()
                throws IOException
Specified by:
readShort in interface DataInput
Throws:
IOException

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
Throws:
IOException

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Specified by:
readUnsignedByte in interface DataInput
Throws:
IOException

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Specified by:
readUnsignedShort in interface DataInput
Throws:
IOException

skipBytes

public int skipBytes(int n)
              throws IOException
Specified by:
skipBytes in interface DataInput
Throws:
IOException

unpackLong

public final long unpackLong()
                      throws IOException
Unpack a long value from the current buffer position.

Returns:
The long value.
Throws:
IOException

unpackShort

public final short unpackShort()
                        throws IOException
Unpack a non-negative short value from the input stream.

Parameters:
is - The input stream.
Returns:
The short value.
Throws:
IOException

position

public long position()
              throws IOException
Report the position of the stream within its slice (relative to the original offset for the backing buffer)

Specified by:
position in interface it.unimi.dsi.fastutil.io.RepositionableStream
Throws:
IOException

position

public void position(long v)
              throws IOException
Reposition the stream within its slice (relative to the original offset for the backing buffer).

Specified by:
position in interface it.unimi.dsi.fastutil.io.RepositionableStream
Throws:
IOException


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.