FreeHEP API
Version current

hep.io.xdr
Class XDRInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjava.io.DataInputStream
              extended byhep.io.xdr.XDRInputStream
All Implemented Interfaces:
DataInput, XDRDataInput

public class XDRInputStream
extends DataInputStream
implements XDRDataInput

A class for reading XDR files. Not too hard to do in Java since the XDR format is very similar to the Java native DataStream format, except for String and the fact that elements (ro an array of elements) are always padded to a multiple of 4 bytes. This class requires the user to call the pad method, to skip to the next 4-byte boundary after reading an element or array of elements that may not span a multiple of 4 bytes.

Version:
$Id: XDRInputStream.java,v 1.3 2003/09/16 23:11:55 tonyj Exp $
Author:
Tony Johnson (tonyj@slac.stanford.edu)
Source Code:
XDRInputStream.java

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
XDRInputStream(InputStream in)
           
 
Method Summary
 void clearReadLimit()
           
 long getBytesRead()
           
 void pad()
          Skips appropriate amount to bring stream to 4-byte boundary.
 double[] readDoubleArray(double[] buffer)
          Reads a double array.
 float[] readFloatArray(float[] buffer)
          Reads a float array.
 int[] readIntArray(int[] buffer)
          Reads an integer array.
 String readString()
          Read a String.
 String readString(int l)
          Reads a String of length l bytes, and skips appropriate amount to bring stream to 4-byte boundary.
 void setReadLimit(int bytes)
          Sets a limit on the number of bytes that can be read from this file before an EOF will be generated
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 

Constructor Detail

XDRInputStream

public XDRInputStream(InputStream in)
Method Detail

getBytesRead

public long getBytesRead()

setReadLimit

public void setReadLimit(int bytes)
Sets a limit on the number of bytes that can be read from this file before an EOF will be generated


clearReadLimit

public void clearReadLimit()

pad

public void pad()
         throws IOException
Skips appropriate amount to bring stream to 4-byte boundary.

Specified by:
pad in interface XDRDataInput
Throws:
IOException

readDoubleArray

public double[] readDoubleArray(double[] buffer)
                         throws IOException
Description copied from interface: XDRDataInput
Reads a double array. Assumes int length proceeds array. Throws an exception if array length > 32767 to protect against bad data exhausting memory. If buffer is not null, and is large enough to hold array, it is filled and returned, otherwise a new array is allocated and returned.

Specified by:
readDoubleArray in interface XDRDataInput
Throws:
IOException

readFloatArray

public float[] readFloatArray(float[] buffer)
                       throws IOException
Description copied from interface: XDRDataInput
Reads a float array. Assumes int length proceeds array. Throws an exception if array length > 32767 to protect against bad data exhausting memory. If buffer is not null, and is large enough to hold array, it is filled and returned, otherwise a new array is allocated and returned.

Specified by:
readFloatArray in interface XDRDataInput
Throws:
IOException

readIntArray

public int[] readIntArray(int[] buffer)
                   throws IOException
Description copied from interface: XDRDataInput
Reads an integer array. Assumes int length proceeds array. Throws an exception if array length > 32767 to protect against bad data exhausting memory. If buffer is not null, and is large enough to hold array, it is filled and returned, otherwise a new array is allocated and returned.

Specified by:
readIntArray in interface XDRDataInput
Throws:
IOException

readString

public String readString(int l)
                  throws IOException
Description copied from interface: XDRDataInput
Reads a String of length l bytes, and skips appropriate amount to bring stream to 4-byte boundary.

Specified by:
readString in interface XDRDataInput
Throws:
IOException

readString

public String readString()
                  throws IOException
Description copied from interface: XDRDataInput
Read a String. Assumes int length proceeds String. Throws an exception if string length > 32767 to protect against bad data exhausting memory.

Specified by:
readString in interface XDRDataInput
Throws:
IOException

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.