java.lang.Object
javax.imageio.stream.ImageInputStreamImpl
javax.imageio.stream.ImageOutputStreamImpl
javax.imageio.stream.FileCacheImageOutputStream
- 所有已实现的接口:
-
Closeable,DataInput,DataOutput,AutoCloseable,ImageInputStream,ImageOutputStream
实现了
ImageOutputStream,将其输出写入常规OutputStream的类。使用文件缓存数据,直到刷新到输出流为止。
-
Field Summary
Fields declared in class javax.imageio.stream.ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPos -
Constructor Summary
ConstructorsConstructorDescriptionFileCacheImageOutputStream(OutputStream stream, File cacheDir) 构造一个将写入给定outputStream的FileCacheImageOutputStream。 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()关闭此FileCacheImageOutputStream。voidflushBefore(long pos) 刷新给定位置之前的所有数据到底层目标,如OutputStream或File。booleanisCached()返回true,因为此ImageOutputStream缓存数据以允许向后查找。boolean返回true,因为此ImageOutputStream维护文件缓存。boolean返回false,因为此ImageOutputStream不维护主内存缓存。longlength()返回-1L,表示流的长度未知。intread()从流中读取一个字节并将其作为介于0和255之间的int返回。intread(byte[] b, int off, int len) 从流中读取最多len个字节,并将它们存储到从索引off开始的b中。voidseek(long pos) 设置当前流位置并将位偏移重置为0。voidwrite(byte[] b, int off, int len) 将一系列字节写入当前位置的流。voidwrite(int b) 将一个字节写入当前位置的流。Methods declared in 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, writeUTFMethods declared in class javax.imageio.stream.ImageInputStreamImpl
checkClosed, finalize, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, length, 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, setBitOffset, setByteOrder, skipBytes, skipBytesMethods declared in class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in 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, setBitOffset, setByteOrder, skipBytes, skipBytes
-
Constructor Details
-
FileCacheImageOutputStream
构造一个将写入给定outputStream的FileCacheImageOutputStream。使用临时文件作为缓存。如果
cacheDir非null且为目录,则文件将在那里创建。如果为null,则将使用系统相关的默认临时文件目录(有关详细信息,请参阅File.createTempFile的文档)。- 参数:
-
stream- 要写入的OutputStream。 -
cacheDir- 指示应在其中创建缓存文件的File,或null以使用系统目录。 - 抛出:
-
IllegalArgumentException- 如果stream为null。 -
IllegalArgumentException- 如果cacheDir非null但不是目录。 -
IOException- 如果无法创建缓存文件。
-
-
Method Details
-
read
从类中复制的描述:ImageInputStreamImpl从流中读取一个字节并将其作为介于0和255之间的int返回。如果达到EOF,则返回-1。子类必须为此方法提供实现。子类实现应在退出前更新流位置。
读取发生前,流中的位偏移必须重置为零。
- 指定者:
-
read在接口ImageInputStream中 - 指定者:
-
read在类ImageInputStreamImpl中 - 返回:
-
流中下一个字节的值,如果达到EOF,则返回
-1。 - 抛出:
-
IOException- 如果流已关闭。
-
read
从类中复制的描述:ImageInputStreamImpl从流中读取最多len个字节,并将它们存储到从索引off开始的b中。如果无法读取任何字节,因为已到达流的末尾,则返回-1。读取发生前,流中的位偏移必须重置为零。
子类必须为此方法提供实现。子类实现应在退出前更新流位置。
- 指定者:
-
read在接口ImageInputStream中 - 指定者:
-
read在类ImageInputStreamImpl中 - 参数:
-
b- 要写入的字节数组。 -
off- 要写入的数据中的起始位置。 -
len- 要读取的最大字节数。 - 返回:
-
实际读取的字节数,或
-1表示EOF。 - 抛出:
-
IOException- 如果发生I/O错误。
-
write
从接口中复制的描述:ImageOutputStream将一个字节写入当前位置的流。忽略b的24个高阶位。如果流中的位偏移不为零,则首先填充当前字节的剩余部分并写出。写入后,位偏移将为0。实现者可以使用
ImageOutputStreamImpl的flushBits方法来保证这一点。- 参数:
-
b- 要写入其低8位的int。 - 抛出:
-
IOException- 如果发生I/O错误。
-
write
从接口中复制的描述:ImageOutputStream将一系列字节写入当前位置的流。如果len为0,则不写入任何内容。首先写入字节b[off],然后是字节b[off + 1],依此类推。如果流中的位偏移不为零,则首先填充当前字节的剩余部分并写出。写入后,位偏移将为0。实现者可以使用
ImageOutputStreamImpl的flushBits方法来保证这一点。- 参数:
-
b- 要写入的byte数组。 -
off- 数据中的起始偏移量。 -
len- 要写入的byte数。 - 抛出:
-
IOException- 如果发生I/O错误。
-
length
public long length()从类中复制的描述:ImageInputStreamImpl返回-1L,表示流的长度未知。子类必须重写此方法以提供实际长度信息。- 指定者:
-
length在接口ImageInputStream中 - 覆盖:
-
length在类ImageInputStreamImpl中 - 返回:
- -1L表示长度未知。
-
seek
设置当前流位置并将位偏移重置为0。可以寻址超出文件末尾;只有在执行读取时才会抛出EOFException。直到执行写入操作,文件长度不会增加。- 参数:
-
pos- 包含所需文件指针位置的long。 - 抛出:
-
IndexOutOfBoundsException- 如果pos小于刷新位置。 -
IOException- 如果发生其他I/O错误。
-
isCached
public boolean isCached()返回true,因为此ImageOutputStream缓存数据以允许向后查找。- 指定由:
-
isCached在接口ImageInputStream - 覆盖:
-
isCached在类ImageInputStreamImpl - 返回:
-
true. - 参见:
-
isCachedFile
public boolean isCachedFile()返回true,因为这个ImageOutputStream维护一个文件缓存。- 指定由:
-
isCachedFile在接口ImageInputStream - 覆盖:
-
isCachedFile在类ImageInputStreamImpl - 返回:
-
true. - 参见:
-
isCachedMemory
public boolean isCachedMemory()返回false,因为这个ImageOutputStream不维护主内存缓存。- 指定由:
-
isCachedMemory在接口ImageInputStream - 覆盖:
-
isCachedMemory在类ImageInputStreamImpl - 返回:
-
false. - 参见:
-
close
关闭这个FileCacheImageOutputStream。所有待处理数据都会刷新到输出,缓存文件会被关闭和删除。目标OutputStream不会被关闭。- 抛出:
-
IOException- 如果发生错误。
-
flushBefore
从接口复制的描述:ImageOutputStream刷新给定位置之前的所有数据到底层目标,比如一个OutputStream或File。尝试定位到已刷新部分的流将导致IndexOutOfBoundsException。- 参数:
-
pos- 包含要刷新到目标的流前缀的长度的long。 - 抛出:
-
IOException- 如果发生I/O错误。
-