edu.mines.jtk.io
Class ArrayInputAdapter

java.lang.Object
  extended by edu.mines.jtk.io.ArrayInputAdapter
All Implemented Interfaces:
ArrayInput, java.io.DataInput

public class ArrayInputAdapter
extends java.lang.Object
implements ArrayInput

Implements ArrayInput by wrapping DataInput. This adapter wraps a specified data input to provide methods for reading values and arrays of values with an optionally specified byte order.

Byte order should rarely be specified. Most applications should simply use the default BIG_ENDIAN byte order.

When an adapter is constructed from an object that has a file channel, the channel enables more efficient reads of arrays of values.

Version:
2006.08.05
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
ArrayInputAdapter(java.io.DataInput input)
          Constructs an adapter for the specified data input.
ArrayInputAdapter(java.io.DataInput input, java.nio.ByteOrder order)
          Constructs an adapter for the specified data input and byte order.
ArrayInputAdapter(java.io.FileInputStream stream)
          Constructs an adapter for the specified file input stream and byte order.
ArrayInputAdapter(java.io.FileInputStream stream, java.nio.ByteOrder order)
          Constructs an adapter for the specified file input stream and byte order.
ArrayInputAdapter(java.io.RandomAccessFile file)
          Constructs an adapter for the specified random-access file.
ArrayInputAdapter(java.io.RandomAccessFile file, java.nio.ByteOrder order)
          Constructs an adapter for the specified random-access file and byte order.
ArrayInputAdapter(java.nio.channels.ReadableByteChannel channel, java.io.DataInput input, java.nio.ByteOrder order)
          Constructs an adapter for the specified channel, input, and byte order.
 
Method Summary
 java.nio.ByteOrder getByteOrder()
          Gets the byte order for this adapter.
 boolean readBoolean()
           
 byte readByte()
           
 void readBytes(byte[] v)
          Reads byte elements into a specified array.
 void readBytes(byte[][] v)
          Reads byte elements into a specified array.
 void readBytes(byte[][][] v)
          Reads byte elements into a specified array.
 void readBytes(byte[] v, int k, int n)
          Reads byte elements into a specified array.
 char readChar()
           
 void readChars(char[] v)
          Reads char elements into a specified array.
 void readChars(char[][] v)
          Reads char elements into a specified array.
 void readChars(char[][][] v)
          Reads char elements into a specified array.
 void readChars(char[] v, int k, int n)
          Reads char elements into a specified array.
 double readDouble()
           
 void readDoubles(double[] v)
          Reads double elements into a specified array.
 void readDoubles(double[][] v)
          Reads double elements into a specified array.
 void readDoubles(double[][][] v)
          Reads double elements into a specified array.
 void readDoubles(double[] v, int k, int n)
          Reads double elements into a specified array.
 float readFloat()
           
 void readFloats(float[] v)
          Reads float elements into a specified array.
 void readFloats(float[][] v)
          Reads float elements into a specified array.
 void readFloats(float[][][] v)
          Reads float elements into a specified array.
 void readFloats(float[] v, int k, int n)
          Reads float elements into a specified array.
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 void readInts(int[] v)
          Reads int elements into a specified array.
 void readInts(int[][] v)
          Reads int elements into a specified array.
 void readInts(int[][][] v)
          Reads int elements into a specified array.
 void readInts(int[] v, int k, int n)
          Reads int elements into a specified array.
 java.lang.String readLine()
           
 long readLong()
           
 void readLongs(long[] v)
          Reads long elements into a specified array.
 void readLongs(long[][] v)
          Reads long elements into a specified array.
 void readLongs(long[][][] v)
          Reads long elements into a specified array.
 void readLongs(long[] v, int k, int n)
          Reads long elements into a specified array.
 short readShort()
           
 void readShorts(short[] v)
          Reads short elements into a specified array.
 void readShorts(short[][] v)
          Reads short elements into a specified array.
 void readShorts(short[][][] v)
          Reads short elements into a specified array.
 void readShorts(short[] v, int k, int n)
          Reads short elements into a specified array.
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 java.lang.String readUTF()
           
 int skipBytes(int n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayInputAdapter

public ArrayInputAdapter(java.io.DataInput input)
Constructs an adapter for the specified data input. The default byte order is BIG_ENDIAN.

Parameters:
input - the data input.

ArrayInputAdapter

public ArrayInputAdapter(java.io.RandomAccessFile file)
Constructs an adapter for the specified random-access file. The file channel of the random-access file enables more efficient reads.

Parameters:
file - the random-access file.

ArrayInputAdapter

public ArrayInputAdapter(java.io.FileInputStream stream)
Constructs an adapter for the specified file input stream and byte order. The file channel of the file input stream enables more efficient reads.

Parameters:
stream - the file input stream.

ArrayInputAdapter

public ArrayInputAdapter(java.io.DataInput input,
                         java.nio.ByteOrder order)
Constructs an adapter for the specified data input and byte order.

Parameters:
input - the data input.
order - the byte order.

ArrayInputAdapter

public ArrayInputAdapter(java.io.RandomAccessFile file,
                         java.nio.ByteOrder order)
Constructs an adapter for the specified random-access file and byte order. The file channel of the random-access file enables more efficient reads.

Parameters:
file - the random-access file.
order - the byte order.

ArrayInputAdapter

public ArrayInputAdapter(java.io.FileInputStream stream,
                         java.nio.ByteOrder order)
Constructs an adapter for the specified file input stream and byte order. The file channel of the file input stream enables more efficient reads.

Parameters:
stream - the file input stream.
order - the byte order.

ArrayInputAdapter

public ArrayInputAdapter(java.nio.channels.ReadableByteChannel channel,
                         java.io.DataInput input,
                         java.nio.ByteOrder order)
Constructs an adapter for the specified channel, input, and byte order. If not null, the readable byte channel enables more efficient reads.

Parameters:
channel - the readable byte channel; null, if none.
input - the data input.
order - the byte order.
Method Detail

getByteOrder

public java.nio.ByteOrder getByteOrder()
Gets the byte order for this adapter.

Returns:
the byte order.

readFully

public void readFully(byte[] b)
               throws java.io.IOException
Specified by:
readFully in interface ArrayInput
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
Specified by:
readFully in interface ArrayInput
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Specified by:
skipBytes in interface ArrayInput
Specified by:
skipBytes in interface java.io.DataInput
Throws:
java.io.IOException

readBoolean

public final boolean readBoolean()
                          throws java.io.IOException
Specified by:
readBoolean in interface ArrayInput
Specified by:
readBoolean in interface java.io.DataInput
Throws:
java.io.IOException

readByte

public final byte readByte()
                    throws java.io.IOException
Specified by:
readByte in interface ArrayInput
Specified by:
readByte in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedByte

public final int readUnsignedByte()
                           throws java.io.IOException
Specified by:
readUnsignedByte in interface ArrayInput
Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException

readShort

public final short readShort()
                      throws java.io.IOException
Specified by:
readShort in interface ArrayInput
Specified by:
readShort in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException
Specified by:
readUnsignedShort in interface ArrayInput
Specified by:
readUnsignedShort in interface java.io.DataInput
Throws:
java.io.IOException

readChar

public final char readChar()
                    throws java.io.IOException
Specified by:
readChar in interface ArrayInput
Specified by:
readChar in interface java.io.DataInput
Throws:
java.io.IOException

readInt

public final int readInt()
                  throws java.io.IOException
Specified by:
readInt in interface ArrayInput
Specified by:
readInt in interface java.io.DataInput
Throws:
java.io.IOException

readLong

public final long readLong()
                    throws java.io.IOException
Specified by:
readLong in interface ArrayInput
Specified by:
readLong in interface java.io.DataInput
Throws:
java.io.IOException

readFloat

public final float readFloat()
                      throws java.io.IOException
Specified by:
readFloat in interface ArrayInput
Specified by:
readFloat in interface java.io.DataInput
Throws:
java.io.IOException

readDouble

public final double readDouble()
                        throws java.io.IOException
Specified by:
readDouble in interface ArrayInput
Specified by:
readDouble in interface java.io.DataInput
Throws:
java.io.IOException

readLine

public final java.lang.String readLine()
                                throws java.io.IOException
Specified by:
readLine in interface ArrayInput
Specified by:
readLine in interface java.io.DataInput
Throws:
java.io.IOException

readUTF

public final java.lang.String readUTF()
                               throws java.io.IOException
Specified by:
readUTF in interface ArrayInput
Specified by:
readUTF in interface java.io.DataInput
Throws:
java.io.IOException

readBytes

public void readBytes(byte[] v,
                      int k,
                      int n)
               throws java.io.IOException
Reads byte elements into a specified array.

Specified by:
readBytes in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readBytes

public void readBytes(byte[] v)
               throws java.io.IOException
Reads byte elements into a specified array. The array length equals the number of elements to read.

Specified by:
readBytes in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readBytes

public void readBytes(byte[][] v)
               throws java.io.IOException
Reads byte elements into a specified array. The array length equals the number of elements to read.

Specified by:
readBytes in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readBytes

public void readBytes(byte[][][] v)
               throws java.io.IOException
Reads byte elements into a specified array. The array length equals the number of elements to read.

Specified by:
readBytes in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readChars

public void readChars(char[] v,
                      int k,
                      int n)
               throws java.io.IOException
Reads char elements into a specified array.

Specified by:
readChars in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readChars

public void readChars(char[] v)
               throws java.io.IOException
Reads char elements into a specified array. The array length equals the number of elements to read.

Specified by:
readChars in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readChars

public void readChars(char[][] v)
               throws java.io.IOException
Reads char elements into a specified array. The array length equals the number of elements to read.

Specified by:
readChars in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readChars

public void readChars(char[][][] v)
               throws java.io.IOException
Reads char elements into a specified array. The array length equals the number of elements to read.

Specified by:
readChars in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readShorts

public void readShorts(short[] v,
                       int k,
                       int n)
                throws java.io.IOException
Reads short elements into a specified array.

Specified by:
readShorts in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readShorts

public void readShorts(short[] v)
                throws java.io.IOException
Reads short elements into a specified array. The array length equals the number of elements to read.

Specified by:
readShorts in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readShorts

public void readShorts(short[][] v)
                throws java.io.IOException
Reads short elements into a specified array. The array length equals the number of elements to read.

Specified by:
readShorts in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readShorts

public void readShorts(short[][][] v)
                throws java.io.IOException
Reads short elements into a specified array. The array length equals the number of elements to read.

Specified by:
readShorts in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readInts

public void readInts(int[] v,
                     int k,
                     int n)
              throws java.io.IOException
Reads int elements into a specified array.

Specified by:
readInts in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readInts

public void readInts(int[] v)
              throws java.io.IOException
Reads int elements into a specified array. The array length equals the number of elements to read.

Specified by:
readInts in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readInts

public void readInts(int[][] v)
              throws java.io.IOException
Reads int elements into a specified array. The array length equals the number of elements to read.

Specified by:
readInts in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readInts

public void readInts(int[][][] v)
              throws java.io.IOException
Reads int elements into a specified array. The array length equals the number of elements to read.

Specified by:
readInts in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readLongs

public void readLongs(long[] v,
                      int k,
                      int n)
               throws java.io.IOException
Reads long elements into a specified array.

Specified by:
readLongs in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readLongs

public void readLongs(long[] v)
               throws java.io.IOException
Reads long elements into a specified array. The array length equals the number of elements to read.

Specified by:
readLongs in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readLongs

public void readLongs(long[][] v)
               throws java.io.IOException
Reads long elements into a specified array. The array length equals the number of elements to read.

Specified by:
readLongs in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readLongs

public void readLongs(long[][][] v)
               throws java.io.IOException
Reads long elements into a specified array. The array length equals the number of elements to read.

Specified by:
readLongs in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readFloats

public void readFloats(float[] v,
                       int k,
                       int n)
                throws java.io.IOException
Reads float elements into a specified array.

Specified by:
readFloats in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readFloats

public void readFloats(float[] v)
                throws java.io.IOException
Reads float elements into a specified array. The array length equals the number of elements to read.

Specified by:
readFloats in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readFloats

public void readFloats(float[][] v)
                throws java.io.IOException
Reads float elements into a specified array. The array length equals the number of elements to read.

Specified by:
readFloats in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readFloats

public void readFloats(float[][][] v)
                throws java.io.IOException
Reads float elements into a specified array. The array length equals the number of elements to read.

Specified by:
readFloats in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readDoubles

public void readDoubles(double[] v,
                        int k,
                        int n)
                 throws java.io.IOException
Reads double elements into a specified array.

Specified by:
readDoubles in interface ArrayInput
Parameters:
v - the array.
k - the index of the first element to read.
n - the number of elements to read.
Throws:
java.io.IOException

readDoubles

public void readDoubles(double[] v)
                 throws java.io.IOException
Reads double elements into a specified array. The array length equals the number of elements to read.

Specified by:
readDoubles in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readDoubles

public void readDoubles(double[][] v)
                 throws java.io.IOException
Reads double elements into a specified array. The array length equals the number of elements to read.

Specified by:
readDoubles in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException

readDoubles

public void readDoubles(double[][][] v)
                 throws java.io.IOException
Reads double elements into a specified array. The array length equals the number of elements to read.

Specified by:
readDoubles in interface ArrayInput
Parameters:
v - the array.
Throws:
java.io.IOException