org.albite.io
Class RandomReadingFile

java.lang.Object
  extended by java.io.InputStream
      extended by org.albite.io.RandomReadingFile
All Implemented Interfaces:
java.io.DataInput, javax.microedition.io.Connection

public class RandomReadingFile
extends java.io.InputStream
implements java.io.DataInput, javax.microedition.io.Connection

Implements random reading from a FileConnection The essential methods are seek(int position) and getPointer(). This class also re-implements all the methods from InputStream All other methods are only wrappings around the underlying DataInputStream or FileConnection


Constructor Summary
RandomReadingFile(java.lang.String url)
          Creates a new RandomReadingFile from a valid file URL.
 
Method Summary
 void close()
          Closes the file and the underlying FileConnection
 java.lang.String getName()
           
 java.lang.String getPath()
           
 int getPointer()
          Returns the current position of the reading pointer in the file
 java.lang.String getURL()
           
 int length()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 double readDouble()
           
 float readFloat()
           
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 java.lang.String readUTF()
           
 void seek(int position)
          Seeks to the specified position
 long skip(long n)
           
 int skipBytes(int n)
           
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomReadingFile

public RandomReadingFile(java.lang.String url)
                  throws java.io.IOException
Creates a new RandomReadingFile from a valid file URL.

Parameters:
url - The URL of the file that is being opened.
Throws:
java.io.IOException
Method Detail

length

public final int length()
                 throws java.io.IOException
Returns:
the size of the file
Throws:
javax.microedition.io.file.ConnectionClosedException - if the file is closed.
java.lang.SecurityException - if the security of the application does not have read access for the file
java.io.IOException

getName

public final java.lang.String getName()

getURL

public final java.lang.String getURL()

getPath

public final java.lang.String getPath()

seek

public final void seek(int position)
                throws java.io.IOException
Seeks to the specified position

Parameters:
position -
Throws:
java.lang.IllegalArgumentException - if the position argument is wrong, i.e.:

position < 0

or

length() <= position

java.io.IOException - if an IOException occurred

skip

public final long skip(long n)
                throws java.io.IOException
Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

skipBytes

public final int skipBytes(int n)
                    throws java.io.IOException
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 java.io.DataInput
Throws:
java.io.IOException

readByte

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

readChar

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

readDouble

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

readFloat

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

readInt

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

readUnsignedByte

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

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException
Specified by:
readUnsignedShort 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 java.io.DataInput
Throws:
java.io.IOException

readLong

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

readShort

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

read

public final int read(byte[] b)
               throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public final int read(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public final int read()
               throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

readFully

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

readFully

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

close

public final void close()
                 throws java.io.IOException
Closes the file and the underlying FileConnection

Specified by:
close in interface javax.microedition.io.Connection
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

getPointer

public final int getPointer()
Returns the current position of the reading pointer in the file

Returns:
the current position of the reading pointer in the file