7.1 Prerequisites

7.2 BfileInputStream Object

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.

BfileInputStream(BFILE)

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.

canSeekBackwards( )

Format

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.

close( )

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( )

getBFILE( )

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( );

getFilePointer( )

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( );

mark( )

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

readLimit

This argument is ignored by the class.

Return Value

None.

Exceptions

None.

Example

inStream.mark(1);

markSupported( )

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.

read( )

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( );

read(byte[ ])

Format

public int read(byte[ ] buffer)

Description

Reads data from the BFILE into the specified buffer.

Parameters

buffer

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.

read(byte[ ], int, int)

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

buffer

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.

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.

remaining( )

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( );

reset( )

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( );

seek( )

Format

public void seek(long pos)

Description

Sets the offset from the beginning of the BFILE at which the next read should occur.

Parameters

pos

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.

skip( )

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

n

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.

7.3 BlobInputStream Object

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.

BlobInputStream(BLOB)

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.

canSeekBackwards( )

Format

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.

close( )

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( )

getBLOB( )

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( );

getFilePointer( )

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( );

mark( )

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

readLimit

This argument is ignored by the class.

Return Value

None.

Exceptions

None.

Example

inStream.mark(1);

markSupported( )

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.

read( )

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( );

read(byte[ ])

Format

public int read(byte[ ] buffer)

Description

Reads data from the BLOB into the specified buffer.

Parameters

buffer

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.

read(byte[ ], int, int)

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

buffer

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 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.

remaining( )

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( );

reset( )

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( );

seek( )

Format

public void seek(long pos)

Description

Sets the offset from the beginning of the BLOB at which the next read should occur.

Parameters

pos

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.

skip( )

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

n

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.

7.4 BlobOutputStream Object

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.

BlobOutputStream(BLOB)

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.

Exceptions

Example

BlobOutputStream(BLOB, int)

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 0.

close( )

Format

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( );

flush( )

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( );

getFilePointer( )

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( );

length( )

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( );

seek( )

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

pos

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);

write(byte[ ])

Format

public void write(byte[ ] buffer)

Description

Writes all bytes in the specified byte array to the BLOB.

Parameters

buffer

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.

write(byte[ ], int, int)

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

buffer

The buffer containing the data to be written to the BLOB.

off

The start offset in the buffer.

len

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.

write(int)

Format

public void write(int b)

Description

Writes the specified byte to the BLOB.

Parameters

b

The byte to be written to the BLOB. Only the low-order byte is written; the upper 24 bits are ignored.