swisseph
Class FilePtr

java.lang.Object
  extended by swisseph.FilePtr
All Implemented Interfaces:
java.io.Serializable

public class FilePtr
extends java.lang.Object
implements java.io.Serializable

This class is meant to be a wrapper to some read functionality of the RandomAccessFile class. It adds the ability to read (and search and seek) in files using http://... access. This is needed to allow applets read access to files, in this case the Swiss Ephemeris and JPL data files.

See Also:
Serialized Form

Field Summary
static java.lang.String useragent
           
 
Constructor Summary
FilePtr(java.io.RandomAccessFile fp, java.net.Socket sk, java.io.InputStream is, java.io.BufferedOutputStream os, java.lang.String fnamp, long fileLength, int bufsize)
          Creates a new FilePtr instance.
 
Method Summary
 void close()
          Closes the connection to the file.
 long getFilePointer()
          Returns the current position of the file pointer.
 long length()
          Returns the length of the file.
 byte readByte()
          Reads one (signed) byte.
 double readDouble()
          Reads a double value.
 int readInt()
          Reads a (signed) integer value.
 java.lang.String readLine()
          Reads a complete line from the file.
 short readShort()
          Reads a (signed) short value.
 int readUnsignedByte()
          Reads one unsigned byte.
 void seek(long pos)
          Positions the file pointer.
 void setBigendian(boolean bigendian)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

useragent

public static final java.lang.String useragent
See Also:
Constant Field Values
Constructor Detail

FilePtr

public FilePtr(java.io.RandomAccessFile fp,
               java.net.Socket sk,
               java.io.InputStream is,
               java.io.BufferedOutputStream os,
               java.lang.String fnamp,
               long fileLength,
               int bufsize)
        throws java.io.IOException
Creates a new FilePtr instance. Well, the parameters are rather "funny" for now, but there were reasons for it. I will change it later (hopefully)...
If you do not need to read randomly and you have access to the file directly, you should use the BufferedInputStream etc. -classes, as they are MUCH faster than the RandomAccessFile class that is used here.

Throws:
java.io.IOException
Method Detail

setBigendian

public void setBigendian(boolean bigendian)

readByte

public byte readByte()
              throws java.io.IOException,
                     java.io.EOFException
Reads one (signed) byte.

Returns:
One signed 8 bit byte.
Throws:
java.io.IOException - if an I/O error occurs.
java.io.EOFException - if the end of file is reached before the byte could be read.

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException,
                            java.io.EOFException
Reads one unsigned byte.

Returns:
One unsigned 8 bit byte as an integer.
Throws:
java.io.IOException - if an I/O error occurs.
java.io.EOFException - if the end of file is reached before the byte could be read.

readShort

public short readShort()
                throws java.io.IOException,
                       java.io.EOFException
Reads a (signed) short value. This is a two byte read (16 bits) with highest byte first.

Returns:
A signed 2 byte (16 bit) value as a short.
Throws:
java.io.IOException - if an I/O error occurs.
java.io.EOFException - if the end of file is reached before the 2 bytes could be read completely.

readInt

public int readInt()
            throws java.io.IOException,
                   java.io.EOFException
Reads a (signed) integer value. This is a four byte read (32 bits) with highest bytes first.

Returns:
A signed 4 byte (32 bit) value as an integer.
Throws:
java.io.IOException - if an I/O error occurs.
java.io.EOFException - if the end of file is reached before the 4 bytes could be read completely.

readDouble

public double readDouble()
                  throws java.io.IOException,
                         java.io.EOFException
Reads a double value. This is an 8 byte read (64 bits) with highest bytes first.

Returns:
A double value.
Throws:
java.io.IOException - if an I/O error occurs.
java.io.EOFException - if the end of file is reached before the 8 bytes could be read completely.

readLine

public java.lang.String readLine()
                          throws java.io.IOException,
                                 java.io.EOFException
Reads a complete line from the file. The line is seen to end on a newline character ('\n') or on an end of file. The returned String will include the newline character if any.

Returns:
A String containing a complete line. The line may be 0 characters long.
Throws:
java.io.IOException - if an I/O error occurs.
java.io.EOFException - if the end of file is reached before even one character (byte) could be read.

close

public void close()
           throws java.io.IOException
Closes the connection to the file. This includes any Streams as well as the Socket and the RandomAccessFile from the constructor.

Throws:
java.io.IOException - if an I/O error occurs.

getFilePointer

public long getFilePointer()
Returns the current position of the file pointer.

Returns:
the current position of the file pointer.

length

public long length()
            throws java.io.IOException
Returns the length of the file.

Returns:
the length of the file in bytes.
Throws:
java.io.IOException - if an I/O error occurs.

seek

public void seek(long pos)
Positions the file pointer.

Parameters:
pos - the new position in the file. The position is seen zero based.