Skip navigation links

Oracle Multimedia Java API Reference
11g Release 1 (11.1)

Part No. B28413-01


oracle.ord.media.jai.io
Class BlobOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by oracle.ord.media.jai.io.SeekableOutputStream
          extended by oracle.ord.media.jai.io.BlobOutputStream

All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class BlobOutputStream
extends SeekableOutputStream

The BlobOutputStream class writes data to database Blobs. It is a subclass of oracle.ord.media.jai.io.SeekableOutputStream.

This class uses buffering while writing to an underlying Blob. The simple constructor (the one that takes only a Blob or BLOB ) uses a default buffer size unless an optimal 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 BlobOutputStream object, the following operations must have already been performed:


Constructor Summary
BlobOutputStream(java.sql.Blob blob)
          Creates a BlobOutputStream object that writes to the specified java.sql.Blob, using a default buffer size of 64KB.
BlobOutputStream(oracle.sql.BLOB blob)
          Deprecated.  
BlobOutputStream(java.sql.Blob blob, int bufferHint)
          Creates a BlobOutputStream object that writes to the specified Blob, using the given integer as the maximum buffer size.

 

Method Summary
 void close()
          Closes the output stream and releases any resources associated with this stream.
 void flush()
          Flushes the output stream and forces any buffered output bytes to be written to the 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 write operation will occur.
 boolean hasDBErrorMessage()
          Checks whether or not a database error message has been set.
 long length()
          Returns the current length of the output stream.
 void seek(long pos)
          Sets the file-pointer offset, measured from the beginning of this stream, at which the next write operation will occur.
 void truncate(long len)
          Truncates the stream to the specified length.
 void write(byte[] b)
          Writes all bytes in the specified byte array to the Blob.
 void write(byte[] b, int off, int len)
          Writes the specified number of bytes from the specified byte array to the Blob.
 void write(int b)
          Writes the specified byte to the Blob.

 

Methods inherited from class oracle.ord.media.jai.io.SeekableOutputStream
wrapOutputStream

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

BlobOutputStream

public BlobOutputStream(java.sql.Blob blob)
                 throws java.io.IOException,
                        java.sql.SQLException
Creates a BlobOutputStream object that writes to the specified java.sql.Blob, using a default buffer size of 64KB. Blob is not trimed until new content is flushed to Blob.
Parameters:
blob - the Blob to which data will be written.
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.

BlobOutputStream

public BlobOutputStream(oracle.sql.BLOB blob)
                 throws java.io.IOException,
                        java.sql.SQLException
Deprecated. 
Creates a BlobOutputStream object that writes to the specified oracle.sql.BLOB. Blob is not trimed until new content is flushed to Blob.
Parameters:
blob - the Blob to which data will be written.
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.

BlobOutputStream

public BlobOutputStream(java.sql.Blob blob,
                        int bufferHint)
                 throws java.io.IOException,
                        java.sql.SQLException
Creates a BlobOutputStream object that writes to the specified Blob, using the given integer as the maximum buffer size. Blob is not trimed until new content is flushed to Blob.
Parameters:
blob - the Blob to which data will be written.
bufferHint - the maximum amount of data to buffer before writing to the database.
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

length

public long length()
            throws java.io.IOException
Returns the current length of the output stream.
Specified by:
length in class SeekableOutputStream
Returns:
the current length of the output stream.
Throws:
java.io.IOException - if an IO error occurs.

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Returns the offset from the beginning of the Blob at which the next write operation will occur.
Specified by:
getFilePointer in class SeekableOutputStream
Returns:
the offset from the beginning of the Blob at which the next write operation will occur, in bytes.
Throws:
java.io.IOException - if an IO error occurs.

seek

public void seek(long pos)
          throws java.io.IOException
Sets the file-pointer offset, measured from the beginning of this stream, at which the next write operation will occur.

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.

Specified by:
seek in class SeekableOutputStream
Parameters:
pos - the offset position, measured in bytes from the beginning of the stream, at which to set the file pointer.
Throws:
java.io.IOException - if the value of the pos parameter is less than zero or if an IO error occurs.

truncate

public void truncate(long len)
              throws java.io.IOException
Truncates the stream to the specified length.
Specified by:
truncate in class SeekableOutputStream
Parameters:
len - the length of the stream, in bytes.
Throws:
java.io.IOException - if the value of the len parameter is less than zero or larger than the stream length, or if an IO error occurs.

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to the Blob.
Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte to be written to the Blob. Only the low-order byte is written; the upper 24 bits are ignored.
Throws:
java.io.IOException - if an IO error occurs. In particular, this exception will be thrown if the stream is closed.

write

public void write(byte[] b)
           throws java.io.IOException
Writes all bytes in the specified byte array to the Blob.
Overrides:
write in class java.io.OutputStream
Parameters:
b - an array of bytes to be written to the Blob.
Throws:
java.io.IOException - if an IO error occurs. In particular, this exception will be thrown if the stream is closed or if the value of the buffer parameter is null.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes the specified number of bytes from the specified byte array to the Blob.
Overrides:
write in class java.io.OutputStream
Parameters:
b - the buffer containing the data to be written to the Blob.
off - the starting position for the offset in the buffer.
len - the number of bytes to write to the Blob.
Throws:
java.io.IOException - if an IO error occurs. In particular, this exception will be thrown if the stream is closed or if the value of the buffer parameter is null.

flush

public void flush()
           throws java.io.IOException
Flushes the output stream and forces any buffered output bytes to be written to the Blob.
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if an IO error occurs.

close

public void close()
           throws java.io.IOException
Closes the output stream and releases any resources associated with this stream. Before closing the stream, this method automatically calls the flush() method to write any buffered bytes to the Blob.
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - if an IO error occurs.

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.

Skip navigation links

Oracle Multimedia Java API Reference
11g Release 1 (11.1)

Part No. B28413-01


Copyright © 1999, 2007, Oracle. All rights reserved.