Skip navigation links

Oracle Multimedia Java API Reference
11g Release 1 (11.1)

Part No. B28413-01


oracle.ord.media.jai.io
Class BfileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.sun.media.jai.codec.SeekableStream
          extended by oracle.ord.media.jai.io.BfileInputStream

All Implemented Interfaces:
java.io.Closeable, java.io.DataInput, SeekableInputStream

public class BfileInputStream
extends com.sun.media.jai.codec.SeekableStream
implements SeekableInputStream

The BfileInputStream class is a SeekableStream object that reads data from Oracle BFILEs. It is a subclass of com.sun.media.jai.codec.SeekableStream and java.io.InputStream; it implements the java.io.DataInput and oracle.ord.media.io.SeekableInputStream interfaces.

This class uses buffering while reading from a BFILE. The simple constructor (the one that takes just a BFILE) uses a default buffer size that should be sufficient for most streams; however, users can specify any buffer size using an alternate constructor.

Prerequisites

In order to to use the JAI stream objects, you will need to include the following import statements in your Java file:

 import java.sql.Blob;
 import oracle.sql.BFILE;

In order to use JAI with Oracle Multimedia JAI stream objects, you will also need to import classes from the oracle.ord.media.jai.io package into your Java file.

Before running the methods associated with the BfileInputStream object, the following operations must have already been performed:


Constructor Summary
BfileInputStream(oracle.sql.BFILE bfile)
          Creates a BfileInputStream object that reads from the specified BFILE.
BfileInputStream(oracle.sql.BFILE bfile, int chunkSize)
          Creates a BfileInputStream object that reads from the specified BFILE.

 

Method Summary
 boolean canSeekBackwards()
          Checks whether or not the stream can seek backward.
 void close()
          Closes the BfileInputStream object, releasing any resources being used.
 oracle.sql.BFILE getBFILE()
          Returns the BFILE associated with the BfileInputStream object.
 java.lang.String getDBErrorMessage()
          Returns the database error message associated with the last error encountered.
 long getFilePointer()
          Returns the offset from the beginning of the BFILE at which the next read operation will occur.
 boolean hasDBErrorMessage()
          Checks whether or not a database error message has been set.
 void mark(int readLimit)
          Marks the current position in the BfileInputStream object.
 boolean markSupported()
          Checks whether or not the BfileInputStream object supports marking.
 int read()
          Reads a single byte from the BFILE associated with the BfileInputStream object.
 int read(byte[] b)
          Reads data from the BFILE into the specified buffer.
 int read(byte[] b, int off, int len)
          Reads up to the specified length of bytes of data from the BFILE into the specified buffer, starting from the specified offset.
 long remaining()
          Returns the number of unread bytes remaining in the BFILE.
 void reset()
          Repositions the stream to the position of the last valid mark.
 void seek(long pos)
          Sets the offset from the beginning of the BFILE at which the next read operation will occur.
 long skip(long n)
          Attempts to skip over the specified number of bytes in the BFILE.

 

Methods inherited from class com.sun.media.jai.codec.SeekableStream
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

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

BfileInputStream

public BfileInputStream(oracle.sql.BFILE bfile)
                 throws java.io.IOException,
                        java.sql.SQLException
Creates a BfileInputStream object that reads from the specified BFILE. The constructor uses the maximum chunk size defined for a BFILE. The BFILE will be opened after this constructor.
Parameters:
bfile - the BFILE from which data will be read.
Throws:
java.io.IOException - if an IO exception occurs, or if the value of the bfile parameter is null, or if the underlying file does not exist.
java.sql.SQLException - if a SQL exception occurs.

BfileInputStream

public BfileInputStream(oracle.sql.BFILE bfile,
                        int chunkSize)
                 throws java.io.IOException,
                        java.sql.SQLException
Creates a BfileInputStream object that reads from the specified BFILE. The constructor uses the specified chunk size. The BFILE will be opened after this constructor executes.
Parameters:
bfile - the BFILE from which data will be read.
chunkSize - the maximum amount of data to read from the BFILE at one time.
Throws:
java.io.IOException - if an IO exception occurs, or if the value of the bfile parameter is null, or if the value of the chunkSize parameter is less than 1, or if the underlying file does not exist.
java.sql.SQLException - if a SQL exception occurs.

Method Detail

getBFILE

public oracle.sql.BFILE getBFILE()
Returns the BFILE associated with the BfileInputStream object.
Returns:
the BFILE associated with the BfileInputStream object.

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Returns the offset from the beginning of the BFILE at which the next read operation will occur.
Specified by:
getFilePointer in interface SeekableInputStream
Specified by:
getFilePointer in class com.sun.media.jai.codec.SeekableStream
Returns:
the offset from the beginning of the BFILE at which the next read operation will occur, in bytes.
Throws:
java.io.IOException - if an IO error occurs.

read

public int read()
         throws java.io.IOException
Reads a single byte from the BFILE associated with the BfileInputStream object.
Specified by:
read in interface SeekableInputStream
Specified by:
read in class com.sun.media.jai.codec.SeekableStream
Returns:
the byte of data that is read, or -1 if the end of the BFILE has been reached.
Throws:
java.io.IOException - if an IO error occurs.

read

public int read(byte[] b)
         throws java.io.IOException
Reads data from the BFILE into the specified buffer.
Specified by:
read in interface SeekableInputStream
Overrides:
read in class java.io.InputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the number of bytes read into the buffer, or -1 if the end of the BFILE was reached before any data was read. The value cannot exceed the length of the buffer.
Throws:
java.io.IOException - if an IO error occurs.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to the specified length of bytes of data from the BFILE into the specified buffer, starting from the specified offset.
Specified by:
read in interface SeekableInputStream
Specified by:
read in class com.sun.media.jai.codec.SeekableStream
Parameters:
b - the buffer into which the data is read.
off - the offset from the beginning of the buffer at which data will be written, in bytes.
len - the maximum number of bytes to be read into the buffer.
Returns:
the number of bytes read, or -1 if the end of the BFILE was reached before any data was read. The value cannot exceed the length of the buffer.
Throws:
java.io.IOException - if an IO error occurs.

seek

public void seek(long pos)
          throws java.io.IOException
Sets the offset from the beginning of the BFILE at which the next read operation will occur.
Specified by:
seek in interface SeekableInputStream
Specified by:
seek in class com.sun.media.jai.codec.SeekableStream
Parameters:
pos - the offset from the beginning of the BFILE at which the next read operation will occur.
Throws:
java.io.IOException - if the value of the pos parameter is less than zero or an IO error occurs.

canSeekBackwards

public boolean canSeekBackwards()
Checks whether or not the stream can seek backward. Because the BfileInputStream object can seek backward, this method will always return true.
Overrides:
canSeekBackwards in class com.sun.media.jai.codec.SeekableStream
Returns:
true.

mark

public void mark(int readLimit)
Marks the current position in the BfileInputStream object. A call to the reset() method will return you to the last marked position in the BfileInputStream object.
Overrides:
mark in class com.sun.media.jai.codec.SeekableStream
Parameters:
readLimit - ignored by the class.

markSupported

public boolean markSupported()
Checks whether or not the BfileInputStream object supports marking. Because the BfileInputStream object supports marking, this method will always return true.
Overrides:
markSupported in class com.sun.media.jai.codec.SeekableStream
Returns:
true.

reset

public void reset()
           throws java.io.IOException
Repositions the stream to the position of the last valid mark.
Overrides:
reset in class com.sun.media.jai.codec.SeekableStream
Throws:
java.io.IOException - if this stream has not been marked or the mark has been invalidated.

skip

public long skip(long n)
          throws java.io.IOException
Attempts to skip over the specified number of bytes in the BFILE.

The number of bytes skipped may be smaller than the specified number; for example, the number would be smaller if the end of the file is reached.

Specified by:
skip in interface SeekableInputStream
Overrides:
skip in class java.io.InputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the number of bytes that are actually skipped.
Throws:
java.io.IOException - if an IO error occurs.

close

public void close()
           throws java.io.IOException
Closes the BfileInputStream object, releasing any resources being used. The BFILE automatically closes after the stream closes.
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface SeekableInputStream
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - if an IO error occurs.

remaining

public long remaining()
Returns the number of unread bytes remaining in the BFILE.
Returns:
the number of unread bytes in the BFILE.

getDBErrorMessage

public java.lang.String getDBErrorMessage()
Returns the database error message associated with the last error encountered.
Returns:
a String with the last database error message, or null if no such message existed.

hasDBErrorMessage

public boolean hasDBErrorMessage()
Checks whether or not a database error message has been set.
Returns:
true if an exception has occurred while communicating with the database that returned a supplementary error message; false otherwise.

Skip navigation links

Oracle Multimedia Java API Reference
11g Release 1 (11.1)

Part No. B28413-01


Copyright © 1999, 2007, Oracle. All rights reserved.