Oracle® interMedia Java Classes User's Guide and Reference Release 9.2 Part No. A96121-01 |
|
Oracle interMedia Java Classes describes three types of stream objects, which provide interfaces to BLOB and BFILE data that can be used by Java Advanced Imaging (JAI):
BfileInputStream, which allows you to read data from an Oracle BFILE associated with the stream.
BlobInputStream, which allows you to read data from an Oracle BLOB associated with the stream.
BlobOutputStream, which allows you to write data from a buffer to an Oracle BLOB associated with the stream
You will need to include the following import statements in your Java file in order to use the JAI stream objects:
import oracle.sql.BLOB; import oracle.sql.BFILE; import oracle.ord.media.jai.io.*;
This section presents reference information on the methods associated with the BfileInputStream object, which provides an interface for JAI to read data from BFILEs. It is a subclass of com.sun.media.jai.codec.SeekableStream and java.io.InputStream; it implements java.io.DataInput.
Some examples in this reference chapter are based on the assumption that the following operations have already been performed:
The following import statements have been included:
import javax.media.jai.JAI; import java.awt.image.RenderedImage;
A local BfileInputStream object named inStream has been created.
Format
public BfileInputStream(oracle.sql.BFILE bfile)
Description
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 executes.
Parameters
The BFILE from which data will be read.
Return Value
None.
Exceptions
java.io.IOException
java.sql.SQLException
Example
BfileInputStream inStream = new BfileInputStream(bfile); RenderedImage image = JAI.create("stream",inStream);
Format
public BfileInputStream(oracle.sql.BFILE bfile, int chunkSize)
Description
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
The BFILE from which data will be read.
The maximum amount of data to read from the BFILE at one time.
Return Value
None.
Exceptions
java.io.IOException
java.sql.SQLException
Example
BfileInputStream inStream = new BfileInputStream(bfile,4096); RenderedImage image = JAI.create("stream",inStream);
where:
4096: is the maximum number of bytes to be read at one time.
Format
public boolean canSeekBackwards( )
Description
Checks whether or not the stream can read backwards. Because the BfileInputStream object can read backwards, this method will always return true.
Parameters
None.
Return Value
This method returns true.
Exceptions
None.
Example
None.
Format
public void close( )
Description
Closes the BfileInputStream, releasing any resources being used. The BFILE automatically closes after the stream closes.
Parameters
None.
Return Value
None.
Exceptions
java.io.IOException
Example
inStream.close( )
Format
public oracle.sql.BFILE getBFILE( )
Description
Returns the BFILE associated with the BfileInputStream.
Parameters
None.
Return Value
This method returns the BFILE associated with the BfileInputStream.
Exceptions
None.
Example
BFILE imageBFILE = inStream.getBFILE( );
Format
public long getFilePointer( )
Description
Returns the offset from the beginning of the BFILE at which the next read will occur.
Parameters
None.
Return Value
This method returns the offset from the beginning of the BFILE at which the next read will occur, in bytes.
Exceptions
java.io.IOException
Example
long offset = inStream.getFilePointer( );
Format
public void mark(int readLimit)
Description
Marks the current position in the BfileInputStream. A call to the reset( ) method will return you to the last marked position in the BfileInputStream.
Parameters
This argument is ignored by the class.
Return Value
None.
Exceptions
None.
Example
inStream.mark(1);
Format
public boolean markSupported( )
Description
Checks whether or not the BfileInputStream supports marking. Because the BfileInputStream object supports marking, this method will always return true.
Parameters
None.
Return Value
This method returns true.
Exceptions
None.
Example
None.
Format
public int read( )
Description
Reads a single byte from the BFILE associated with the BfileInputStream.
Parameters
None.
Return Value
This method returns the byte of data that is read, or -1 if the end of the BFILE has been reached.
Exceptions
java.io.IOException
Example
int i = inStream.read( );
Format
public int read(byte[ ] buffer)
Description
Reads data from the BFILE into the specified buffer.
Parameters
The buffer into which the data is read.
Return Value
This method 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.
Exceptions
java.io.IOException
Example
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer);
where:
buffer: is the buffer into which the data is read.
Format
public int read(byte[ ]buffer, int off, int len)
Description
Reads up to the specified length of data from the BFILE into the specified buffer, starting from the specified offset.
Parameters
The buffer into which the data is read.
The offset from the beginning of the buffer at which data will be written, in bytes.
The maximum number of bytes to be read into the buffer.
Return Value
This method 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.
Exceptions
java.io.IOException
Example
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer,75,50);
where:
buffer: is the buffer into which the data is read.
75: is the offset from the beginning of the buffer at which reading will begin.
50: is the number of bytes to be read into the buffer.
Format
public long remaining( )
Description
Returns the number of unread bytes remaining in the BFILE.
Parameters
None.
Return Value
This method returns the number of unread bytes in the BFILE.
Exceptions
None.
Example
long remain = inStream.remaining( );
Format
public void reset( )
Description
Repositions the stream to the position of the last valid mark.
Parameters
None.
Return Value
None.
Exceptions
java.io.IOException
Example
inStream.reset( );
Format
public void seek(long pos)
Description
Sets the offset from the beginning of the BFILE at which the next read should occur.
Parameters
The offset from the beginning of the BFILE at which the next read should occur.
Return Value
None.
Exceptions
java.io.IOException
Example
inStream.seek(75);
where:
75: is the offset from the beginning of the BFILE at which the next read should occur.
Format
public long skip(long n)
Description
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.
Parameters
The number of bytes to be skipped.
Return Value
This method returns the number of bytes that are actually skipped.
Exceptions
java.io.IOException
Example
long skipped = inStream.skip(100);
where:
100: is the number of bytes to be skipped.
This section presents reference information on the methods associated with the BlobInputStream object, which provides an interface for JAI to read data from BLOBs. It is a subclass of com.sun.media.jai.codec.SeekableStream and java.io.InputStream; it implements java.io.DataInput.
Some examples in this reference chapter are based on the assumption that the following operations have already been performed:
The following import statements have been included:
import javax.media.jai.JAI; import java.awt.image.RenderedImage;
A local BlobInputStream object named inStream has been created.
Format
public BlobInputStream(oracle.sql.BLOB blob)
Description
Creates a BlobInputStream object that reads from the specified BLOB. The constructor uses an optimal chunk size that is determined by the database.
Parameters
The BLOB from which data will be read.
Return Value
None.
Exceptions
java.io.IOException
java.sql.SQLException
Example
BlobInputStream inStream = new BlobInputStream(blob); RenderedImage image = JAI.create("stream",inStream);
Format
public BlobInputStream(oracle.sql.BLOB blob, int chunkSize)
Description
Creates a BlobInputStream object that reads from the specified BLOB. The constructor uses the specified chunk size.
Parameters
The BLOB from which data will be read.
The maximum amount of data to read from the BLOB at one time.
Return Value
None.
Exceptions
java.io.IOException
java.sql.SQLException
Example
BlobInputStream inStream = new BlobInputStream(blob,4096); RenderedImage image = JAI.create("stream",inStream);
where:
4096: is the maximum number of bytes to be read at one time.
Format
public boolean canSeekBackwards( )
Description
Checks whether or not the stream can read backwards. Because the BlobInputStream object can read backwards, this method will always return true.
Parameters
None.
Return Value
This method returns true.
Exceptions
None.
Example
None.
Format
public void close( )
Description
Closes the BlobInputStream, releasing any resources being used.
Parameters
None.
Return Value
None.
Exceptions
java.io.IOException
Example
inStream.close( )
Format
public oracle.sql.BLOB getBLOB( )
Description
Returns the BLOB associated with the BlobInputStream.
Parameters
None.
Return Value
This method returns the BLOB associated with the BlobInputStream.
Exceptions
None.
Example
BLOB imageBLOB = inStream.getBLOB( );
Format
public long getFilePointer( )
Description
Returns the offset from the beginning of the BLOB at which the next read will occur.
Parameters
None.
Return Value
This method returns the offset from the beginning of the BLOB at which the next read will occur, in bytes.
Exceptions
java.io.IOException
Example
long offset = inStream.getFilePointer( );
Format
public void mark(int readLimit)
Description
Marks the current position in the BlobInputStream. A call to the reset( ) method will return you to the last marked position in the BlobInputStream.
Parameters
This argument is ignored by the class.
Return Value
None.
Exceptions
None.
Example
inStream.mark(1);
Format
public boolean markSupported( )
Description
Checks whether or not the BlobInputStream supports marking. Because the BlobInputStream object supports marking, this method will always return true.
Parameters
None.
Return Value
This method returns true.
Exceptions
None.
Example
None.
Format
public int read( )
Description
Reads a single byte from the BLOB associated with the BlobInputStream.
Parameters
None.
Return Value
This method returns the byte of data that is read, or -1 if the end of the BLOB has been reached.
Exceptions
java.io.IOException
Example
int i = inStream.read( );
Format
public int read(byte[ ] buffer)
Description
Reads data from the BLOB into the specified buffer.
Parameters
The buffer into which the data is read.
Return Value
This method 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.
Exceptions
java.io.IOException
Example
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer);
where:
buffer: is the buffer into which the data is read.
Format
public int read(byte[ ]buffer, int off, int len)
Description
Reads up to the specified length of data from the BLOB into the specified buffer, starting from the specified offset.
Parameters
The buffer into which the data is read.
The offset from the beginning of the buffer at which data will be written, in bytes.
The maximum number of bytes to be written to the buffer.
Return Value
This method returns the number of bytes read into the buffer, or -1 if the end of the BLOB has been reached. The value cannot exceed the length of the buffer.
Exceptions
java.io.IOException
Example
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer,75,50);
where:
buffer: is the buffer into which the data is read.
75: is the offset from the beginning of the buffer at which data will be written.
50: is the number of bytes to be read into the buffer.
Format
public long remaining( )
Description
Returns the number of unread bytes remaining in the BLOB.
Parameters
None.
Return Value
This method returns the number of unread bytes in the BLOB.
Exceptions
None.
Example
long remain = inStream.remaining( );
Format
public void reset( )
Description
Repositions the stream to the position of the last valid mark.
Parameters
None.
Return Value
None.
Exceptions
java.io.IOException
Example
inStream.reset( );
Format
public void seek(long pos)
Description
Sets the offset from the beginning of the BLOB at which the next read should occur.
Parameters
The offset from the beginning of the BLOB at which the next read should occur.
Return Value
None.
Exceptions
java.io.IOException
Example
inStream.seek(75);
where:
75: is the offset from the beginning of the BLOB at which the next read should occur.
Format
public long skip(long n)
Description
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.
Parameters
The number of bytes to be skipped.
Return Value
This method returns the number of bytes that are actually skipped.
Exceptions
java.io.IOException
Example
long skipped = inStream.skip(100);
where:
100: is the number of bytes to be skipped.
This section presents reference information on the methods associated with the BlobOutputStream object, which provides an interface for JAI to write data to BLOBs. It is a subclass of java.io.OutputStream.
Some examples in this reference chapter are based on the assumption that the following operations have already been performed:
The following import statements have been included:
import javax.media.jai.JAI; import java.awt.image.RenderedImage;
A local BlobOutputStream object named outStream has been created.
Format
public BlobOutputStream (oracle.sql.BLOB blob)
Description
Creates a BlobOutputStream object that writes to the specified BLOB, using an optimal chunk size that is determined by the database. Creating an object of this type implicitly trims the data in the BLOB to a length of 0.
Parameters
The BLOB to which data will be written.
Return Value
None.
Exceptions
java.io.IOException
java.sql.SQLException
Example
RenderedImage = JAI.create("fileload","sample.jpg"); BlobOutputStream outStream = new BlobOutputStream(blob); JAI.create("encode",image,"bmp")
Format
public BlobOutputStream(oracle.sql.BLOB blob, int chunkSize)
Description
Creates a BlobOutputStream object that writes to the specified BLOB, using the given integer as the maximum chunk size. Creating an object of this type implicitly trims the data in the BLOB to a length of zero.
Parameters
The BLOB to which data will be written
The maximum amount of data to write to the BLOB at one time.
Return Value
None.
Exceptions
java.io.IOException
java.sql.SQLException
Example
RenderedImage = JAI.create("fileload","sample.jpg"); BlobOutputStream outStream = new BlobOutputStream(blob,4096); JAI.create("encode",image,"bmp")
where:
4096: is the maximum amount of data that will be written at one time.
Format
public void close( )
Description
Closes the output stream and releases any system resources associated with this stream. Before closing the stream, this method automatically calls flush( ) to write any buffered bytes to the BLOB.
Parameters
None.
Return Value
None.
Exceptions
java.io.IOException
Example
outStream.close( );
Format
public void flush( )
Description
Flushes the output stream and forces any buffered output bytes to be written to the BLOB.
Parameters
None.
Return Value
None.
Exceptions
java.io.IOException
Example
outStream.flush( );
Format
public long getFilePointer( )
Description
Returns the offset from the beginning of the BLOB at which the next write will occur.
Parameters
None.
Return Value
This method returns the offset from the beginning of the BLOB at which the next write will occur, in bytes.
Exceptions
java.io.IOException
Example
long offset = outStream.getFilePointer( );
Format
public long length( )
Description
Returns the current length of the output stream.
Parameters
None.
Return Value
This method returns the current length of the output stream.
Exceptions
java.io.IOException
Example
long length = outStream.length( );
Format
public void seek(long pos)
Description
Sets the file-pointer offset, measured from the beginning of this stream, at which the next write occurs.
The offset may be set beyond the end of the stream. Setting the offset beyond the end of the stream does not change the stream length; the stream length will change only by writing after the offset has been set beyond the end of the stream.
Parameters
The offset position, measured in bytes from the beginning of the stream, at which to set the file pointer.
Return Value
None.
Exceptions
java.io.IOException
Example
outStream.seek(4096);
Format
public void write(byte[ ] buffer)
Description
Writes all bytes in the specified byte array to the BLOB.
Parameters
An array of bytes to be written to the BLOB.
Return Value
None.
Exceptions
java.io.IOException
Example
//create a byte array named buffer and populate it with data outStream.write(buffer);
where:
buffer: is the array of bytes that will be written to the BLOB.
Format
public void write(byte[ ] buffer, int off, int len)
Description
Writes the specified number of bytes from the specified byte array to the BLOB.
Parameters
The buffer containing the data to be written to the BLOB.
The start offset in the buffer.
The number of bytes to write to the BLOB.
Return Value
None.
Exceptions
java.io.IOException
Example
//create a byte array named buffer and populate it with data outStream.write(buffer,75,50);
where:
buffer: is the array of bytes that will be written to the BLOB.
75: is the offset from the beginning of the buffer at which data will be read.
50: is the number of bytes to be written.
Format
public void write(int b)
Description
Writes the specified byte to the BLOB.
Parameters
The byte to be written to the BLOB. Only the low-order byte is written; the upper 24 bits are ignored.
Return Value
None.
Exceptions
java.io.IOException
Example
outStream.write(50);
where:
50: is an integer whose low-order byte will be written to the BLOB.
|
Copyright © 1999, 2002 Oracle Corporation All rights reserved |
|