org.apache.hadoop.hive.ql.io
Class NonSyncDataInputBuffer

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by org.apache.hadoop.hive.ql.io.NonSyncDataInputBuffer
All Implemented Interfaces:
Closeable, DataInput

public class NonSyncDataInputBuffer
extends FilterInputStream
implements DataInput

A thread-not-safe version of Hadoop's DataInputBuffer, which removes all synchronized modifiers.


Constructor Summary
NonSyncDataInputBuffer()
          Constructs a new empty buffer.
 
Method Summary
static String convertUTF8WithBuf(byte[] buf, char[] out, int offset, int utfSize)
           
 int getLength()
          Returns the length of the input.
 int getPosition()
          Returns the current position in the input.
 int read(byte[] buffer)
          Reads bytes from the source stream into the byte array buffer.
 int read(byte[] buffer, int offset, int length)
          Read at most length bytes from this DataInputStream and stores them in byte array buffer starting at offset.
 boolean readBoolean()
          Reads a boolean from this stream.
 byte readByte()
          Reads an 8-bit byte value from this stream.
 char readChar()
           
 double readDouble()
          Reads a 64-bit double value from this stream.
 float readFloat()
          Reads a 32-bit float value from this stream.
 void readFully(byte[] buffer)
          Reads bytes from this stream into the byte array buffer.
 void readFully(byte[] buffer, int offset, int length)
          Reads bytes from this stream and stores them in the byte array buffer starting at the position offset.
 int readInt()
          Reads a 32-bit integer value from this stream.
 String readLine()
          Deprecated. Use BufferedReader
 long readLong()
          Reads a 64-bit long value from this stream.
 short readShort()
          Reads a 16-bit short value from this stream.
 int readUnsignedByte()
          Reads an unsigned 8-bit byte value from this stream and returns it as an int.
 int readUnsignedShort()
          Reads a 16-bit unsigned short value from this stream and returns it as an int.
 String readUTF()
          Reads a UTF format String from this Stream.
static String readUTF(DataInput in)
          Reads a UTF format String from the DataInput Stream in.
 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.
 int skipBytes(int count)
          Skips count number of bytes in this stream.
 
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

NonSyncDataInputBuffer

public NonSyncDataInputBuffer()
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.


read

public final int read(byte[] buffer)
               throws IOException
Reads bytes from the source stream into the byte array buffer. The number of bytes actually read is returned.

Overrides:
read in class FilterInputStream
Parameters:
buffer - the buffer to read bytes into
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

read

public final int read(byte[] buffer,
                      int offset,
                      int length)
               throws IOException
Read at most length bytes from this DataInputStream and stores them in byte array buffer starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered.

Overrides:
read in class FilterInputStream
Parameters:
buffer - the byte array in which to store the read bytes.
offset - the offset in buffer to store the read bytes.
length - the maximum number of bytes to store in buffer.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readBoolean

public final boolean readBoolean()
                          throws IOException
Reads a boolean from this stream.

Specified by:
readBoolean in interface DataInput
Returns:
the next boolean value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readByte

public final byte readByte()
                    throws IOException
Reads an 8-bit byte value from this stream.

Specified by:
readByte in interface DataInput
Returns:
the next byte value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readChar

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

readDouble

public final double readDouble()
                        throws IOException
Reads a 64-bit double value from this stream.

Specified by:
readDouble in interface DataInput
Returns:
the next double value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readFloat

public final float readFloat()
                      throws IOException
Reads a 32-bit float value from this stream.

Specified by:
readFloat in interface DataInput
Returns:
the next float value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readFully

public final void readFully(byte[] buffer)
                     throws IOException
Reads bytes from this stream into the byte array buffer. This method will block until buffer.length number of bytes have been read.

Specified by:
readFully in interface DataInput
Parameters:
buffer - to read bytes into
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readFully

public final void readFully(byte[] buffer,
                            int offset,
                            int length)
                     throws IOException
Reads bytes from this stream and stores them in the byte array buffer starting at the position offset. This method blocks until count bytes have been read.

Specified by:
readFully in interface DataInput
Parameters:
buffer - the byte array into which the data is read
offset - the offset the operation start at
length - the maximum number of bytes to read
Throws:
IOException - if a problem occurs while reading from this stream
EOFException - if reaches the end of the stream before enough bytes have been read

readInt

public final int readInt()
                  throws IOException
Reads a 32-bit integer value from this stream.

Specified by:
readInt in interface DataInput
Returns:
the next int value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readLine

@Deprecated
public final String readLine()
                      throws IOException
Deprecated. Use BufferedReader

Answers a String representing the next line of text available in this BufferedReader. A line is represented by 0 or more characters followed by '\n', '\r', "\n\r" or end of stream. The String does not include the newline sequence.

Specified by:
readLine in interface DataInput
Returns:
the contents of the line or null if no characters were read before end of stream.
Throws:
IOException - If the DataInputStream is already closed or some other IO error occurs.

readLong

public final long readLong()
                    throws IOException
Reads a 64-bit long value from this stream.

Specified by:
readLong in interface DataInput
Returns:
the next long value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readShort

public final short readShort()
                      throws IOException
Reads a 16-bit short value from this stream.

Specified by:
readShort in interface DataInput
Returns:
the next short value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readUnsignedByte

public final int readUnsignedByte()
                           throws IOException
Reads an unsigned 8-bit byte value from this stream and returns it as an int.

Specified by:
readUnsignedByte in interface DataInput
Returns:
the next unsigned byte value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readUnsignedShort

public final int readUnsignedShort()
                            throws IOException
Reads a 16-bit unsigned short value from this stream and returns it as an int.

Specified by:
readUnsignedShort in interface DataInput
Returns:
the next unsigned short value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readUTF

public final String readUTF()
                     throws IOException
Reads a UTF format String from this Stream.

Specified by:
readUTF in interface DataInput
Returns:
the next UTF String from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

readUTF

public static final String readUTF(DataInput in)
                            throws IOException
Reads a UTF format String from the DataInput Stream in.

Parameters:
in - the input stream to read from
Returns:
the next UTF String from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.

skipBytes

public final int skipBytes(int count)
                    throws IOException
Skips count number of bytes in this stream. Subsequent read()'s will not return these bytes unless reset() is used.

Specified by:
skipBytes in interface DataInput
Parameters:
count - the number of bytes to skip.
Returns:
the number of bytes actually skipped.
Throws:
IOException - If the stream is already closed or another IOException occurs.

convertUTF8WithBuf

public static String convertUTF8WithBuf(byte[] buf,
                                        char[] out,
                                        int offset,
                                        int utfSize)
                                 throws UTFDataFormatException
Throws:
UTFDataFormatException


Copyright © 2014 The Apache Software Foundation. All rights reserved.