Skip navigation links

Oracle® Multimedia Java API Reference
12c Release 1 (12.1)

E17699-06


oracle.ord.media.jai.io
Class BlobInputStream

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

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

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

The BlobInputStream class is a SeekableStream object that reads data from database Blobs. 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 Blob. The simple constructor (the one that takes only a Blob or a BLOB) uses a default buffer size unless an optimal buffer size can be determined by the database. Users can also 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 BlobInputStream object, the following operations must have already been performed:


Constructor Summary
BlobInputStream(java.sql.Blob blob)
          Creates a BlobInputStream object that reads from the specified Blob.
BlobInputStream(oracle.sql.BLOB blob)
          Deprecated.  
BlobInputStream(java.sql.Blob blob, int bufferHint)
          Creates a BlobInputStream object that reads from the specified Blob.

 

Method Summary
 boolean canSeekBackwards()
          Checks whether or not the stream can seek backward.
 void close()
          Closes the BlobInputStream object, releasing any resources being used.
static int computeBlobStreamBufferSize(int bufferHint)
           
 java.sql.Blob getBlob()
          Returns the LOB associated with the BlobInputStream object.
 oracle.sql.BLOB getBLOB()
          Returns the LOB associated with the BlobInputStream object cast to an oracle.sql.BLOB.
 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 Blob 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 BlobInputStream object.
 boolean markSupported()
          Checks whether or not the BlobInputStream object supports marking.
 int read()
          Reads a single byte from the Blob associated with the BlobInputStream object.
 int read(byte[] b)
          Reads data from the Blob into the specified buffer.
 int read(byte[] b, int off, int len)
          Reads up to the specified length of bytes of data from the Blob into the specified buffer, starting from the specified offset.
 long remaining()
          Returns the number of unread bytes remaining in the Blob.
 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 Blob, at which the next read operation will occur.
 long skip(long n)
          Attempts to skip over the specified number of bytes in the Blob.

 

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

BlobInputStream

public BlobInputStream(java.sql.Blob blob)
                throws java.io.IOException,
                       java.sql.SQLException
Creates a BlobInputStream object that reads from the specified Blob. The constructor uses a default buffer size of 64KB.
Parameters:
blob - the Blob from which data will be read.
Throws:
java.io.IOException - if an IO exception occurs or if the value of the blob parameter is null.
java.sql.SQLException - if a SQL exception occurs.

BlobInputStream

public BlobInputStream(oracle.sql.BLOB blob)
                throws java.io.IOException,
                       java.sql.SQLException
Deprecated. 
Creates a BlobInputStream object that reads from the specified Blob.
Parameters:
blob - the Blob from which data will be read.
Throws:
java.io.IOException - if an IO exception occurs or if the value of the blob parameter is null.
java.sql.SQLException - if a SQL exception occurs.

BlobInputStream

public BlobInputStream(java.sql.Blob blob,
                       int bufferHint)
                throws java.io.IOException,
                       java.sql.SQLException
Creates a BlobInputStream object that reads from the specified Blob. The constructor uses the specified buffer size.
Parameters:
blob - the Blob from which data will be read.
bufferHint - the maximum amount of data to read from the Blob at one time.
Throws:
java.io.IOException - if an IO exception occurs, or if the value of the blob parameter is null.
java.sql.SQLException - if a SQL exception occurs.

Method Detail

getBLOB

public oracle.sql.BLOB getBLOB()
Returns the LOB associated with the BlobInputStream object cast to an oracle.sql.BLOB.
Returns:
the Blob associated with the BlobInputStream object.
Throws:
java.lang.ClassCastException - if the underlying LOB object is not an instance of oracle.sql.BLOB.

getBlob

public java.sql.Blob getBlob()
Returns the LOB associated with the BlobInputStream object.
Returns:
the Blob associated with the BlobInputStream object.

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Returns the offset from the beginning of the Blob 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 (in bytes) from the beginning of the Blob at which the next read operation will occur or -1 if the stream is closed.
Throws:
java.io.IOException - if an IO error occurs.

read

public int read()
         throws java.io.IOException
Reads a single byte from the Blob associated with the BlobInputStream object. The value returned is between 0 and 255.
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 Blob 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 Blob 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 Blob 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 Blob 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 into the buffer, or -1 if the end of the Blob 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 Blob, 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 Blob at which the next read operation will occur.
Throws:
java.io.IOException - if the value of the pos parameter is less than zero or if an IO error occurs.

canSeekBackwards

public boolean canSeekBackwards()
Checks whether or not the stream can seek backward. Because the BlobInputStream 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 BlobInputStream object. A call to the reset() method will return you to the last marked position in the BlobInputStream 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 BlobInputStream object supports marking. Because the BlobInputStream 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 Blob.

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 BlobInputStream object, releasing any resources being used.
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 Blob.
Returns:
the number of unread bytes in the Blob.

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.

computeBlobStreamBufferSize

public static int computeBlobStreamBufferSize(int bufferHint)

Skip navigation links

Oracle® Multimedia Java API Reference
12c Release 1 (12.1)

E17699-06


Copyright © 1999, 2013, Oracle and/or its affiliates. All rights reserved.