com.sun.media.jai.codec
Class FileSeekableStream

java.lang.Object
  extended byjava.io.InputStream
      extended bycom.sun.media.jai.codec.SeekableStream
          extended bycom.sun.media.jai.codec.FileSeekableStream
All Implemented Interfaces:
DataInput

public class FileSeekableStream
extends SeekableStream

A subclass of SeekableStream that takes its input from a File or RandomAccessFile. Backwards seeking is supported. The mark() and reset() methods are supported.

This class is not a committed part of the JAI API. It may be removed or changed in future releases of JAI.


Constructor Summary
FileSeekableStream(File file)
          Constructs a FileSeekableStream from a File.
FileSeekableStream(RandomAccessFile file)
          Constructs a FileSeekableStream from a RandomAccessFile.
FileSeekableStream(String name)
          Constructs a FileSeekableStream from a String path name.
 
Method Summary
 boolean canSeekBackwards()
          Returns true since seeking backwards is supported.
 void close()
          Forwards the request to the real File.
 long getFilePointer()
          Returns the current offset in this stream.
 void mark(int readLimit)
          Marks the current file position for later return using the reset() method.
 boolean markSupported()
          Returns true since marking is supported.
 int read()
          Forwards the request to the real File.
 int read(byte[] b, int off, int len)
          Forwards the request to the real File.
 void reset()
          Returns the file position to its position at the time of the immediately previous call to the mark() method.
 void seek(long pos)
          Sets the offset, measured from the beginning of this stream, at which the next read occurs.
 int skip(int n)
           
 
Methods inherited from class com.sun.media.jai.codec.SeekableStream
finalize, readBoolean, readByte, readChar, readCharLE, readDouble, readDoubleLE, readFloat, readFloatLE, readFully, readFully, readInt, readIntLE, readLine, readLong, readLongLE, readShort, readShortLE, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedShort, readUnsignedShortLE, readUTF, skipBytes, wrapInputStream
 
Methods inherited from class java.io.InputStream
available, read, skip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSeekableStream

public FileSeekableStream(RandomAccessFile file)
                   throws IOException
Constructs a FileSeekableStream from a RandomAccessFile.


FileSeekableStream

public FileSeekableStream(File file)
                   throws IOException
Constructs a FileSeekableStream from a File.


FileSeekableStream

public FileSeekableStream(String name)
                   throws IOException
Constructs a FileSeekableStream from a String path name.

Method Detail

canSeekBackwards

public final boolean canSeekBackwards()
Returns true since seeking backwards is supported.

Overrides:
canSeekBackwards in class SeekableStream

getFilePointer

public final long getFilePointer()
                          throws IOException
Returns the current offset in this stream.

Specified by:
getFilePointer in class SeekableStream
Returns:
the offset from the beginning of the stream, in bytes, at which the next read occurs.
Throws:
IOException - if an I/O error occurs.

seek

public final void seek(long pos)
                throws IOException
Description copied from class: SeekableStream
Sets the offset, measured from the beginning of this stream, at which the next read occurs.

If canSeekBackwards() returns false, then setting pos to an offset smaller than the current value of getFilePointer() will have no effect.

Specified by:
seek in class SeekableStream
Parameters:
pos - the offset position, measured in bytes from the beginning of the stream, at which to set the stream pointer.
Throws:
IOException - if pos is less than 0 or if an I/O error occurs.

skip

public final int skip(int n)
               throws IOException
Throws:
IOException

read

public final int read()
               throws IOException
Forwards the request to the real File.

Specified by:
read in class SeekableStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.

read

public final int read(byte[] b,
                      int off,
                      int len)
               throws IOException
Forwards the request to the real File.

Specified by:
read in class SeekableStream
Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

close

public final void close()
                 throws IOException
Forwards the request to the real File.

Throws:
IOException

mark

public final void mark(int readLimit)
Marks the current file position for later return using the reset() method.

Overrides:
mark in class SeekableStream

reset

public final void reset()
                 throws IOException
Returns the file position to its position at the time of the immediately previous call to the mark() method.

Overrides:
reset in class SeekableStream
Throws:
IOException

markSupported

public boolean markSupported()
Returns true since marking is supported.

Overrides:
markSupported in class SeekableStream