Skip Headers

Oracle® interMedia Java Classes User's Guide and Reference
Release 9.2
Part No. A96121-01
Go To Documentation Library
Library
Go To Product List
Product
Go To Table Of Contents
Contents

Master Index
Go To Index
Index

Feedback

Previous Next

7
JAI Input and Output Stream Reference Information

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

7.1 Prerequisites

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

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:


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.

Parameters

bfile

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

BfileInputStream(BFILE, int)

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

bfile

The BFILE from which data will be read.

chunkSize

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:


canSeekBackwards( )

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.


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:


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:


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:


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:


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:


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.

Parameters

blob

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

BlobInputStream(BLOB, int)

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

blob

The BLOB from which data will be read.

chunkSize

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:


canSeekBackwards( )

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.


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:


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:


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:


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:


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:


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.

Parameters

blob

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

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

Parameters

blob

The BLOB to which data will be written

chunkSize

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:


close( )

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

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:


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:


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.

Return Value

None.

Exceptions

java.io.IOException

Example

outStream.write(50);

where:






Previous Next
Oracle Logo
Copyright © 1999, 2002 Oracle Corporation

All rights reserved
Go To Documentation Library
Library
Go To Product List
Product
Go To Table Of Contents
Contents

Master Index
Go To Index
Index

Feedback