APIdia Launch Partner
Top Description Fields Constructors Methods
javax.imageio.stream

public Class MemoryCacheImageOutputStream

extends ImageOutputStreamImpl
Class Inheritance
Imports
java.io.IOException, .OutputStream

An implementation of ImageOutputStream that writes its output to a regular OutputStream. A memory buffer is used to cache at least the data between the discard position and the current write position. The only constructor takes an OutputStream, so this class may not be used for read/modify/write operations. Reading can occur only on parts of the stream that have already been written to the cache and not yet flushed.

Field Summary

Modifier and TypeField and Description
private MemoryCache
private OutputStream

Constructor Summary

AccessConstructor and Description
public
MemoryCacheImageOutputStream(OutputStream
an OutputStream to write to.
stream
)

Constructs a MemoryCacheImageOutputStream that will write to a given OutputStream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides javax.imageio.stream.ImageInputStreamImpl.close.

Implements javax.imageio.stream.ImageInputStream.close.

Closes this MemoryCacheImageOutputStream.

public void
flushBefore(long pos)

Overrides javax.imageio.stream.ImageInputStreamImpl.flushBefore.

Implements javax.imageio.stream.ImageOutputStream.flushBefore, javax.imageio.stream.ImageInputStream.flushBefore.

Flushes all data prior to the given position to the underlying destination, such as an OutputStream or File.

public boolean

Returns:

true.
isCached
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCached.

Implements javax.imageio.stream.ImageInputStream.isCached.

Returns true since this ImageOutputStream caches data in order to allow seeking backwards.

public boolean

Returns:

false.
isCachedFile
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedFile.

Implements javax.imageio.stream.ImageInputStream.isCachedFile.

Returns false since this ImageOutputStream does not maintain a file cache.

public boolean

Returns:

true.
isCachedMemory
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedMemory.

Implements javax.imageio.stream.ImageInputStream.isCachedMemory.

Returns true since this ImageOutputStream maintains a main memory cache.

public long
length()

Overrides javax.imageio.stream.ImageInputStreamImpl.length.

Implements javax.imageio.stream.ImageInputStream.length.

Returns the total length of the stream, if known.

public int
read()

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Reads a single byte from the stream and returns it as an integer between 0 and 255.

public int
read(byte[] b, int off, int len)

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Reads up to len bytes from the stream, and stores them into b starting at index off.

public void
write(int b)

Implements abstract javax.imageio.stream.ImageOutputStreamImpl.write.

Implements javax.imageio.stream.ImageOutputStream.write.

Writes a single byte to the stream at the current position.

public void
write(byte[] b, int off, int len)

Implements abstract javax.imageio.stream.ImageOutputStreamImpl.write.

Implements javax.imageio.stream.ImageOutputStream.write.

Writes a sequence of bytes to the stream at the current position.

Inherited from javax.imageio.stream.ImageOutputStreamImpl:
flushBitswritewriteBitwriteBitswriteBooleanwriteBytewriteByteswriteCharwriteCharswriteCharswriteDoublewriteDoubleswriteFloatwriteFloatswriteIntwriteIntswriteLongwriteLongswriteShortwriteShortswriteUTF

Field Detail

cacheback to summary
private MemoryCache cache
streamback to summary
private OutputStream stream

Constructor Detail

MemoryCacheImageOutputStreamback to summary
public MemoryCacheImageOutputStream(OutputStream stream)

Constructs a MemoryCacheImageOutputStream that will write to a given OutputStream.

Parameters
stream:OutputStream

an OutputStream to write to.

Exceptions
IllegalArgumentException:
if stream is null.

Method Detail

closeback to summary
public void close() throws IOException

Overrides javax.imageio.stream.ImageInputStreamImpl.close.

Implements javax.imageio.stream.ImageInputStream.close.

Closes this MemoryCacheImageOutputStream. All pending data is flushed to the output, and the cache is released. The destination OutputStream is not closed.

Exceptions
IOException:

Doc from javax.imageio.stream.ImageInputStream.close.

if an I/O error occurs.

flushBeforeback to summary
public void flushBefore(long pos) throws IOException

Overrides javax.imageio.stream.ImageInputStreamImpl.flushBefore.

Implements javax.imageio.stream.ImageOutputStream.flushBefore, javax.imageio.stream.ImageInputStream.flushBefore.

Doc from javax.imageio.stream.ImageOutputStream.flushBefore.

Flushes all data prior to the given position to the underlying destination, such as an OutputStream or File. Attempting to seek to the flushed portion of the stream will result in an IndexOutOfBoundsException.

Exceptions
IOException:
if an I/O error occurs.
isCachedback to summary
public boolean isCached()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCached.

Implements javax.imageio.stream.ImageInputStream.isCached.

Returns true since this ImageOutputStream caches data in order to allow seeking backwards.

Returns:boolean

true.

See Also
isCachedMemory, isCachedFile
isCachedFileback to summary
public boolean isCachedFile()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedFile.

Implements javax.imageio.stream.ImageInputStream.isCachedFile.

Returns false since this ImageOutputStream does not maintain a file cache.

Returns:boolean

false.

See Also
isCached, isCachedMemory
isCachedMemoryback to summary
public boolean isCachedMemory()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedMemory.

Implements javax.imageio.stream.ImageInputStream.isCachedMemory.

Returns true since this ImageOutputStream maintains a main memory cache.

Returns:boolean

true.

See Also
isCached, isCachedFile
lengthback to summary
public long length()

Overrides javax.imageio.stream.ImageInputStreamImpl.length.

Implements javax.imageio.stream.ImageInputStream.length.

Doc from javax.imageio.stream.ImageInputStream.length.

Returns the total length of the stream, if known. Otherwise, -1 is returned.

readback to summary
public int read() throws IOException

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Doc from javax.imageio.stream.ImageInputStream.read.

Reads a single byte from the stream and returns it as an integer between 0 and 255. If the end of the stream is reached, -1 is returned.

The bit offset within the stream is reset to zero before the read occurs.

Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Doc from javax.imageio.stream.ImageInputStream.read.

Reads up to len bytes from the stream, and stores them into b starting at index off. The number of bytes read is returned. If no bytes can be read because the end of the stream has been reached, -1 is returned.

The bit offset within the stream is reset to zero before the read occurs.

Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(int b) throws IOException

Implements abstract javax.imageio.stream.ImageOutputStreamImpl.write.

Implements javax.imageio.stream.ImageOutputStream.write.

Doc from javax.imageio.stream.ImageOutputStream.write.

Writes a single byte to the stream at the current position. The 24 high-order bits of b are ignored.

If the bit offset within the stream is non-zero, the remainder of the current byte is padded with 0s and written out first. The bit offset will be 0 after the write. Implementers can use the flushBits method of ImageOutputStreamImpl to guarantee this.

Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Implements abstract javax.imageio.stream.ImageOutputStreamImpl.write.

Implements javax.imageio.stream.ImageOutputStream.write.

Doc from javax.imageio.stream.ImageOutputStream.write.

Writes a sequence of bytes to the stream at the current position. If len is 0, nothing is written. The byte b[off] is written first, then the byte b[off + 1], and so on.

If the bit offset within the stream is non-zero, the remainder of the current byte is padded with 0s and written out first. The bit offset will be 0 after the write. Implementers can use the flushBits method of ImageOutputStreamImpl to guarantee this.

Exceptions
IOException:
if an I/O error occurs.