Oracle interMedia Java Classes User's Guide and Reference Release 9.0.1 Part Number A88785-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):
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:
import javax.media.jai.JAI; import java.awt.image.RenderedImage;
public BfileInputStream(oracle.sql.BFILE bfile)
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.
The BFILE from which data will be read.
None.
java.io.IOException
java.sql.SQLException
BfileInputStream inStream = new BfileInputStream(bfile); RenderedImage image = JAI.create("stream",inStream);
public BfileInputStream(oracle.sql.BFILE bfile, int chunkSize)
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.
The BFILE from which data will be read.
The maximum amount of data to read from the BFILE at one time.
None.
java.io.IOException
java.sql.SQLException
BfileInputStream inStream = new BfileInputStream(bfile,4096); RenderedImage image = JAI.create("stream",inStream);
where:
public boolean canSeekBackwards( )
Checks whether or not the stream can read backwards. Because the BfileInputStream object can read backwards, this method will always return true.
None.
This method returns true.
None.
None.
public void close( )
Closes the BfileInputStream, releasing any resources being used. The BFILE automatically closes after the stream closes.
None.
None.
java.io.IOException
inStream.close( )
public oracle.sql.BFILE getBFILE( )
Returns the BFILE associated with the BfileInputStream.
None.
This method returns the BFILE associated with the BfileInputStream.
None.
BFILE imageBFILE = inStream.getBFILE( );
public long getFilePointer( )
Returns the offset from the beginning of the BFILE at which the next read will occur.
None.
This method returns the offset from the beginning of the BFILE at which the next read will occur, in bytes.
java.io.IOException
long offset = inStream.getFilePointer( );
public void mark(int readLimit)
Marks the current position in the BfileInputStream. A call to the reset( ) method will return you to the last marked position in the BfileInputStream.
This argument is ignored by the class.
None.
None.
inStream.mark(1);
public boolean markSupported( )
Checks whether or not the BfileInputStream supports marking. Because the BfileInputStream object supports marking, this method will always return true.
None.
This method returns true.
None.
None.
public int read( )
Reads a single byte from the BFILE associated with the BfileInputStream.
None.
This method returns the byte of data that is read, or -1 if the end of the BFILE has been reached.
java.io.IOException
int i = inStream.read( );
public int read(byte[ ] buffer)
Reads data from the BFILE into the specified buffer.
The buffer into which the data is read.
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.
java.io.IOException
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer);
where:
public int read(byte[ ]buffer, int off, int len)
Reads up to the specified length of data from the BFILE into the specified buffer, starting from the specified offset.
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.
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.
java.io.IOException
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer,75,50);
where:
public long remaining( )
Returns the number of unread bytes remaining in the BFILE.
None.
This method returns the number of unread bytes in the BFILE.
None.
long remain = inStream.remaining( );
public void reset( )
Repositions the stream to the position of the last valid mark.
None.
None.
java.io.IOException
inStream.reset( );
public void seek(long pos)
Sets the offset from the beginning of the BFILE at which the next read should occur.
The offset from the beginning of the BFILE at which the next read should occur.
None.
java.io.IOException
inStream.seek(75);
where:
public long skip(long n)
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.
The number of bytes to be skipped.
This method returns the number of bytes that are actually skipped.
java.io.IOException
long skipped = inStream.skip(100);
where:
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:
import javax.media.jai.JAI; import java.awt.image.RenderedImage;
public BlobInputStream(oracle.sql.BLOB blob)
Creates a BlobInputStream object that reads from the specified BLOB. The constructor uses an optimal chunk size that is determined by the database.
The BLOB from which data will be read.
None.
java.io.IOException
java.sql.SQLException
BlobInputStream inStream = new BlobInputStream(blob); RenderedImage image = JAI.create("stream",inStream);
public BlobInputStream(oracle.sql.BLOB blob, int chunkSize)
Creates a BlobInputStream object that reads from the specified BLOB. The constructor uses the specified chunk size.
The BLOB from which data will be read.
The maximum amount of data to read from the BLOB at one time.
None.
java.io.IOException
java.sql.SQLException
BlobInputStream inStream = new BlobInputStream(blob,4096); RenderedImage image = JAI.create("stream",inStream);
where:
public boolean canSeekBackwards( )
Checks whether or not the stream can read backwards. Because the BlobInputStream object can read backwards, this method will always return true.
None.
This method returns true.
None.
None.
public void close( )
Closes the BlobInputStream, releasing any resources being used.
None.
None.
java.io.IOException
inStream.close( )
public oracle.sql.BLOB getBLOB( )
Returns the BLOB associated with the BlobInputStream.
None.
This method returns the BLOB associated with the BlobInputStream.
None.
BLOB imageBLOB = inStream.getBLOB( );
public long getFilePointer( )
Returns the offset from the beginning of the BLOB at which the next read will occur.
None.
This method returns the offset from the beginning of the BLOB at which the next read will occur, in bytes.
java.io.IOException
long offset = inStream.getFilePointer( );
public void mark(int readLimit)
Marks the current position in the BlobInputStream. A call to the reset( ) method will return you to the last marked position in the BlobInputStream.
This argument is ignored by the class.
None.
None.
inStream.mark(1);
public boolean markSupported( )
Checks whether or not the BlobInputStream supports marking. Because the BlobInputStream object supports marking, this method will always return true.
None.
This method returns true.
None.
None.
public int read( )
Reads a single byte from the BLOB associated with the BlobInputStream.
None.
This method returns the byte of data that is read, or -1 if the end of the BLOB has been reached.
java.io.IOException
int i = inStream.read( );
public int read(byte[ ] buffer)
Reads data from the BLOB into the specified buffer.
The buffer into which the data is read.
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.
java.io.IOException
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer);
where:
public int read(byte[ ]buffer, int off, int len)
Reads up to the specified length of data from the BLOB into the specified buffer, starting from the specified offset.
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.
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.
java.io.IOException
byte[ ] buffer = new byte[4000]; int i = inStream.read(buffer,75,50);
where:
public long remaining( )
Returns the number of unread bytes remaining in the BLOB.
None.
This method returns the number of unread bytes in the BLOB.
None.
long remain = inStream.remaining( );
public void reset( )
Repositions the stream to the position of the last valid mark.
None.
None.
java.io.IOException
inStream.reset( );
public void seek(long pos)
Sets the offset from the beginning of the BLOB at which the next read should occur.
The offset from the beginning of the BLOB at which the next read should occur.
None.
java.io.IOException
inStream.seek(75);
where:
public long skip(long n)
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.
The number of bytes to be skipped.
This method returns the number of bytes that are actually skipped.
java.io.IOException
long skipped = inStream.skip(100);
where:
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:
import javax.media.jai.JAI; import java.awt.image.RenderedImage;
public BlobOutputStream (oracle.sql.BLOB blob)
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.
The BLOB to which data will be written.
None.
java.io.IOException
java.sql.SQLException
RenderedImage = JAI.create("fileload","sample.jpg"); BlobOutputStream outStream = new BlobOutputStream(blob); JAI.create("encode",image,"bmp")
public BlobOutputStream(oracle.sql.BLOB blob, int chunkSize)
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 0.
The BLOB to which data will be written
The maximum amount of data to write to the BLOB at one time.
None.
java.io.IOException
java.sql.SQLException
RenderedImage = JAI.create("fileload","sample.jpg"); BlobOutputStream outStream = new BlobOutputStream(blob,4096); JAI.create("encode",image,"bmp")
where:
public void close( )
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.
None.
None.
java.io.IOException
outStream.close( );
public void flush( )
Flushes the output stream and forces any buffered output bytes to be written to the BLOB.
None.
None.
java.io.IOException
outStream.flush( );
public long getFilePointer( )
Returns the offset from the beginning of the BLOB at which the next write will occur.
None.
This method returns the offset from the beginning of the BLOB at which the next write will occur, in bytes.
java.io.IOException
long offset = outStream.getFilePointer( );
public long length( )
Returns the current length of the output stream.
None.
This method returns the current length of the output stream.
java.io.IOException
long length = outStream.length( );
public void seek(long pos)
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.
The offset position, measured in bytes from the beginning of the stream, at which to set the file pointer.
None.
java.io.IOException
outStream.seek(4096);
public void write(byte[ ] buffer)
Writes all bytes in the specified byte array to the BLOB.
An array of bytes to be written to the BLOB.
None.
java.io.IOException
//create a byte array named buffer and populate it with data outStream.write(buffer);
where:
public void write(byte[ ] buffer, int off, int len)
Writes the specified number of bytes from the specified byte array to the BLOB.
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.
None.
java.io.IOException
//create a byte array named buffer and populate it with data outStream.write(buffer,75,50);
where:
public void write(int b)
Writes the specified byte to the BLOB.
The byte to be written to the BLOB. Only the low-order byte is written; the upper 24 bits are ignored.
None.
java.io.IOException
outStream.write(50);
where:
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|