- java.lang.Object
-
- javax.imageio.stream.ImageInputStreamImpl
-
- javax.imageio.stream.ImageOutputStreamImpl
-
- javax.imageio.stream.MemoryCacheImageOutputStream
-
- All Implemented Interfaces:
-
Closeable,DataInput,DataOutput,AutoCloseable,ImageInputStream,ImageOutputStream
public class MemoryCacheImageOutputStream extends ImageOutputStreamImpl
一个ImageOutputStream的实现,将其输出写入常规的OutputStream。 存储器缓冲器用于至少缓存丢弃位置和当前写入位置之间的数据。 唯一的构造函数需要一个OutputStream,所以这个类可能不用于读/修改/写操作。 读取只能发生在已经写入高速缓存并且尚未刷新的流的部分上。
-
-
Field Summary
-
Fields inherited from class javax.imageio.stream.ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPos
-
-
构造方法摘要
构造方法 Constructor 描述 MemoryCacheImageOutputStream(OutputStream stream)构造一个MemoryCacheImageOutputStream,它将写入给定的OutputStream。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 voidclose()关闭此MemoryCacheImageOutputStream。voidflushBefore(long pos)在指示的位置之前丢弃流的初始部分。booleanisCached()返回true因为这ImageOutputStream缓存数据,以便向后ImageOutputStream。booleanisCachedFile()返回false因为这个ImageOutputStream没有维护一个文件缓存。booleanisCachedMemory()返回true因为这个ImageOutputStream维护一个主内存缓存。longlength()返回-1L以表示流长度不明确。intread()从流中读取一个字节,并将其作为int和255之间的int返回。intread(byte[] b, int off, int len)读取到len从流字节,并将其存储到b开始于索引off。voidwrite(byte[] b, int off, int len)在当前位置写入一串字节。voidwrite(int b)将当前位置的单个字节写入流。-
Methods inherited from interface javax.imageio.stream.ImageInputStream
flush, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, mark, read, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, reset, seek, setBitOffset, setByteOrder, skipBytes, skipBytes
-
Methods inherited from class javax.imageio.stream.ImageInputStreamImpl
checkClosed, finalize, flush, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, mark, read, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, reset, seek, setBitOffset, setByteOrder, skipBytes, skipBytes
-
Methods inherited from class javax.imageio.stream.ImageOutputStreamImpl
flushBits, write, writeBit, writeBits, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeChars, writeDouble, writeDoubles, writeFloat, writeFloats, writeInt, writeInts, writeLong, writeLongs, writeShort, writeShorts, writeUTF
-
-
-
-
构造方法详细信息
-
MemoryCacheImageOutputStream
public MemoryCacheImageOutputStream(OutputStream stream)
构造一个MemoryCacheImageOutputStream,它将写入给定的OutputStream。- 参数
-
stream- 要写的OutputStream。 - 异常
-
IllegalArgumentException- 如果stream是null。
-
-
方法详细信息
-
read
public int read() throws IOException描述从类复制:ImageInputStreamImpl从流中读取一个字节,并将其作为int和255之间的-1返回。如果达到EOF,则返回-1。子类必须为此方法提供一个实现。 子类实现应该在退出之前更新流位置。
在发生读取之前,流内的位偏移必须重置为零。
- Specified by:
-
read接口ImageInputStream - Specified by:
-
read类ImageInputStreamImpl - 结果
-
流中下一个字节的值,如果达到EOF,
-1。 - 异常
-
IOException- 如果流已关闭。
-
read
public int read(byte[] b, int off, int len) throws IOException描述从类复制:ImageInputStreamImpl从流中读取最多len个字节,并将其存储到b,索引号为off。 如果没有字节可以读取,因为已经到达流的末尾,则返回-1。在发生读取之前,流内的位偏移必须重置为零。
子类必须为此方法提供一个实现。 子类实现应该在退出之前更新流位置。
- Specified by:
-
read在接口ImageInputStream - Specified by:
-
read类ImageInputStreamImpl - 参数
-
b- 要写入的字节数组。 -
off- 起始位置在b内写。 -
len- 要读取的最大字节数。 - 结果
-
实际读取的字节数,或
-1表示EOF。 - 异常
-
IOException- 如果发生I / O错误。
-
write
public void write(int b) throws IOException说明从接口ImageOutputStream复制将当前位置的单个字节写入流。 忽略了b的24个高位。如果流内的位偏移量不为零,则当前字节的剩余部分用0填充并首先写出。 写入后位偏移将为0。 实施者可以使用
flushBits的方法ImageOutputStreamImpl来保证这一点。- Specified by:
-
write在接口DataOutput - Specified by:
-
write在接口ImageOutputStream - Specified by:
-
write在ImageOutputStreamImpl - 参数
-
b- 要写入低8位的int。 - 异常
-
IOException- 如果发生I / O错误。
-
write
public void write(byte[] b, int off, int len) throws IOException描述从接口ImageOutputStream复制在当前位置写入一串字节。 如果len为0,则不会写入。 字节b[off]首先写入,然后字节b[off + 1]等等。如果流内的位偏移量不为零,则当前字节的剩余部分用0填充并首先写出。 写入后位偏移将为0。 实施者可以使用
flushBits的方法ImageOutputStreamImpl来保证这一点。- Specified by:
-
write在接口DataOutput - Specified by:
-
write在接口ImageOutputStream - Specified by:
-
write在ImageOutputStreamImpl - 参数
-
b- 要写入的byte的数组。 -
off- 数据中的起始偏移量。 -
len-byte的len的数量。 - 异常
-
IOException- 如果发生I / O错误。
-
length
public long length()
描述从类复制:ImageInputStreamImpl返回-1L以表示该流具有未知长度。 子类必须覆盖此方法以提供实际的长度信息。- Specified by:
-
length在接口ImageInputStream - 重写:
-
length在ImageInputStreamImpl - 结果
- -1L表示未知长度。
-
isCached
public boolean isCached()
返回true因为这ImageOutputStream缓存数据以允许向后搜索。- Specified by:
-
isCached在接口ImageInputStream - 重写:
-
isCached在ImageInputStreamImpl - 结果
-
true。 - 另请参见:
-
isCachedMemory(),isCachedFile()
-
isCachedFile
public boolean isCachedFile()
返回false因为这个ImageOutputStream不保存文件缓存。- Specified by:
-
isCachedFile在接口ImageInputStream - 重写:
-
isCachedFile中的ImageInputStreamImpl - 结果
-
false。 - 另请参见:
-
isCached(),isCachedMemory()
-
isCachedMemory
public boolean isCachedMemory()
返回true因为该ImageOutputStream维护主内存缓存。- Specified by:
-
isCachedMemory在接口ImageInputStream - 重写:
-
isCachedMemory在ImageInputStreamImpl - 结果
-
true。 - 另请参见:
-
isCached(),isCachedFile()
-
close
public void close() throws IOException关闭此MemoryCacheImageOutputStream。 所有挂起的数据都被刷新到输出,缓存被释放。 目的地OutputStream未关闭。- Specified by:
-
close接口AutoCloseable - Specified by:
-
close在接口Closeable - Specified by:
-
close在接口ImageInputStream - 重写:
-
close在ImageInputStreamImpl - 异常
-
IOException- 如果发生I / O错误。
-
flushBefore
public void flushBefore(long pos) throws IOException描述从接口ImageInputStream复制在指示的位置之前丢弃流的初始部分。 试图寻求在流的冲洗部分内的偏移将导致一个IndexOutOfBoundsException。调用
flushBefore可能允许实现此接口的类释放用于存储流中的数据的资源(如内存或磁盘空间)。- Specified by:
-
flushBefore接口ImageInputStream - Specified by:
-
flushBefore接口ImageOutputStream - 重写:
-
flushBefore在ImageInputStreamImpl - 参数
-
pos- 一个long其中包含可能被刷新的流前缀的长度。 - 异常
-
IOException- 如果发生I / O错误。
-
-