Class FileImageOutputStream
- All Implemented Interfaces:
Closeable, DataInput, DataOutput, AutoCloseable, ImageInputStream, ImageOutputStream
ImageOutputStream that writes its
output directly to a File or
RandomAccessFile.-
Field Summary
Fields declared in class ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPosModifier and TypeFieldDescriptionprotected intThe current bit offset within the stream.protected ByteOrderThe byte order of the stream as an instance of the enumeration classjava.nio.ByteOrder, whereByteOrder.BIG_ENDIANindicates network byte order andByteOrder.LITTLE_ENDIANindicates the reverse order.protected longThe position prior to which data may be discarded.protected longThe current read position within the stream. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aFileImageOutputStreamthat will write to a givenFile.Constructs aFileImageOutputStreamthat will write to a givenRandomAccessFile. -
Method Summary
Modifier and TypeMethodDescriptionintread()Reads a single byte from the stream and returns it as anintbetween 0 and 255.intread(byte[] b, int off, int len) Reads up tolenbytes from the stream, and stores them intobstarting at indexoff.voidseek(long pos) Sets the current stream position and resets the bit offset to 0.voidwrite(byte[] b, int off, int len) Writes a sequence of bytes to the stream at the current position.voidwrite(int b) Writes a single byte to the stream at the current position.Methods declared in class ImageOutputStreamImpl
flushBits, write, writeBit, writeBits, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeChars, writeDouble, writeDoubles, writeFloat, writeFloats, writeInt, writeInts, writeLong, writeLongs, writeShort, writeShorts, writeUTFModifier and TypeMethodDescriptionprotected final voidIf the bit offset is non-zero, forces the remaining bits in the current byte to 0 and advances the stream position by one.voidwrite(byte[] b) Writes a sequence of bytes to the stream at the current position.voidwriteBit(int bit) Writes a single bit, given by the least significant bit of the argument, to the stream at the current bit offset within the current byte position.voidwriteBits(long bits, int numBits) Writes a sequence of bits, given by thenumBitsleast significant bits of thebitsargument in left-to-right order, to the stream at the current bit offset within the current byte position.voidwriteBoolean(boolean v) Writes abooleanvalue to the stream.voidwriteByte(int v) Writes the 8 low-order bits ofvto the stream.voidwriteBytes(String s) Writes a string to the output stream.voidwriteChar(int v) This method is a synonym forwriteShort.voidwriteChars(char[] c, int off, int len) Writes a sequence of chars to the stream at the current position.voidwriteChars(String s) Writes a string to the output stream.voidwriteDouble(double v) Writes adoublevalue, which is comprised of four bytes, to the output stream.voidwriteDoubles(double[] d, int off, int len) Writes a sequence of doubles to the stream at the current position.voidwriteFloat(float v) Writes afloatvalue, which is comprised of four bytes, to the output stream.voidwriteFloats(float[] f, int off, int len) Writes a sequence of floats to the stream at the current position.voidwriteInt(int v) Writes the 32 bits ofvto the stream.voidwriteInts(int[] i, int off, int len) Writes a sequence of ints to the stream at the current position.voidwriteLong(long v) Writes the 64 bits ofvto the stream.voidwriteLongs(long[] l, int off, int len) Writes a sequence of longs to the stream at the current position.voidwriteShort(int v) Writes the 16 low-order bits ofvto the stream.voidwriteShorts(short[] s, int off, int len) Writes a sequence of shorts to the stream at the current position.voidWrites two bytes of length information to the output stream in network byte order, followed by the modified UTF-8 representation of every character in the strings.Methods declared in class ImageInputStreamImpl
checkClosed, close, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, 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, skipBytesModifier and TypeMethodDescriptionprotected final voidThrows anIOExceptionif the stream has been closed.voidclose()Closes the stream.voidflush()Discards the initial position of the stream prior to the current stream position.voidflushBefore(long pos) Discards the initial portion of the stream prior to the indicated position.intReturns the current bit offset, as an integer between 0 and 7, inclusive.Returns the byte order with which data values will be read from this stream as an instance of thejava.nio.ByteOrderenumeration.longReturns the earliest position in the stream to which seeking may be performed.longReturns the current byte position of the stream.booleanisCached()Default implementation returns false.booleanDefault implementation returns false.booleanDefault implementation returns false.longlength()Returns-1Lto indicate that the stream has unknown length.voidmark()Pushes the current stream position onto a stack of marked positions.intread(byte[] b) A convenience method that callsread(b, 0, b.length).intreadBit()Reads a single bit from the stream and returns it as anintwith the value0or1.longreadBits(int numBits) Reads a bitstring from the stream and returns it as along, with the first bit read becoming the most significant bit of the output.booleanReads a byte from the stream and returns abooleanvalue oftrueif it is nonzero,falseif it is zero.bytereadByte()Reads a byte from the stream and returns it as abytevalue.voidreadBytes(IIOByteBuffer buf, int len) Reads up tolenbytes from the stream, and modifies the suppliedIIOByteBufferto indicate the byte array, offset, and length where the data may be found.charreadChar()Equivalent toreadUnsignedShort, except that the result is returned using thechardatatype.doubleReads 8 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as adouble.floatReads 4 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as afloat.voidreadFully(byte[] b) Readsb.lengthbytes from the stream, and stores them intobstarting at index0.voidreadFully(byte[] b, int off, int len) Readslenbytes from the stream, and stores them intobstarting at indexoff.voidreadFully(char[] c, int off, int len) Readslenchars (unsigned 16-bit integers) from the stream according to the current byte order, and stores them intocstarting at indexoff.voidreadFully(double[] d, int off, int len) Readslendoubles (64-bit IEEE double-precision floats) from the stream according to the current byte order, and stores them intodstarting at indexoff.voidreadFully(float[] f, int off, int len) Readslenfloats (32-bit IEEE single-precision floats) from the stream according to the current byte order, and stores them intofstarting at indexoff.voidreadFully(int[] i, int off, int len) Readslenints (signed 32-bit integers) from the stream according to the current byte order, and stores them intoistarting at indexoff.voidreadFully(long[] l, int off, int len) Readslenlongs (signed 64-bit integers) from the stream according to the current byte order, and stores them intolstarting at indexoff.voidreadFully(short[] s, int off, int len) Readslenshorts (signed 16-bit integers) from the stream according to the current byte order, and stores them intosstarting at indexoff.intreadInt()Reads 4 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as anint.readLine()Reads the next line of text from the input stream.longreadLong()Reads 8 bytes from the stream, and (conceptually) concatenates them according to the current byte order and returns the result as along.shortReads two bytes from the stream, and (conceptually) concatenates them according to the current byte order, and returns the result as ashortvalue.intReads a byte from the stream, and (conceptually) converts it to an int, masks it with0xffin order to strip off any sign-extension bits, and returns it as abytevalue.longReads 4 bytes from the stream, and (conceptually) concatenates them according to the current byte order, converts the result to a long, masks it with0xffffffffLin order to strip off any sign-extension bits, and returns the result as an unsignedlongvalue.intReads two bytes from the stream, and (conceptually) concatenates them according to the current byte order, converts the resulting value to anint, masks it with0xffffin order to strip off any sign-extension buts, and returns the result as an unsignedintvalue.readUTF()Reads in a string that has been encoded using a modified UTF-8 format.voidreset()Resets the current stream byte and bit positions from the stack of marked positions.voidsetBitOffset(int bitOffset) Sets the bit offset to an integer between 0 and 7, inclusive.voidsetByteOrder(ByteOrder byteOrder) Sets the desired byte order for future reads of data values from this stream.intskipBytes(int n) Advances the current stream position by callingseek(getStreamPosition() + n).longskipBytes(long n) Advances the current stream position by callingseek(getStreamPosition() + n).Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.Methods declared in interface ImageOutputStream
flushBeforeModifier and TypeMethodDescriptionvoidflushBefore(long pos) Flushes all data prior to the given position to the underlying destination, such as anOutputStreamorFile.
-
Constructor Details
-
FileImageOutputStream
Constructs aFileImageOutputStreamthat will write to a givenFile.- Parameters:
f- aFileto write to.- Throws:
IllegalArgumentException- iffisnull.FileNotFoundException- iffdoes not denote a regular file or it cannot be opened for reading and writing for any other reason.IOException- if an I/O error occurs.
-
FileImageOutputStream
Constructs aFileImageOutputStreamthat will write to a givenRandomAccessFile.- Parameters:
raf- aRandomAccessFileto write to.- Throws:
IllegalArgumentException- ifrafisnull.
-
-
Method Details
-
read
Description copied from class:ImageInputStreamImplReads a single byte from the stream and returns it as anintbetween 0 and 255. If EOF is reached,-1is returned.Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.
The bit offset within the stream must be reset to zero before the read occurs.
- Specified by:
readin interfaceImageInputStream- Specified by:
readin classImageInputStreamImpl- Returns:
- the value of the next byte in the stream, or
-1if EOF is reached. - Throws:
IOException- if the stream has been closed.
-
read
Description copied from class:ImageInputStreamImplReads up tolenbytes from the stream, and stores them intobstarting at indexoff. If no bytes can be read because the end of the stream has been reached,-1is returned.The bit offset within the stream must be reset to zero before the read occurs.
Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.
- Specified by:
readin interfaceImageInputStream- Specified by:
readin classImageInputStreamImpl- Parameters:
b- an array of bytes to be written to.off- the starting position withinbto write to.len- the maximum number of bytes to read.- Returns:
- the number of bytes actually read, or
-1to indicate EOF. - Throws:
IOException- if an I/O error occurs.
-
write
Description copied from interface:ImageOutputStreamWrites a single byte to the stream at the current position. The 24 high-order bits ofbare 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
flushBitsmethod ofImageOutputStreamImplto guarantee this.- Parameters:
b- anintwhose lower 8 bits are to be written.- Throws:
IOException- if an I/O error occurs.
-
write
Description copied from interface:ImageOutputStreamWrites a sequence of bytes to the stream at the current position. Iflenis 0, nothing is written. The byteb[off]is written first, then the byteb[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
flushBitsmethod ofImageOutputStreamImplto guarantee this.- Parameters:
b- an array ofbytes to be written.off- the start offset in the data.len- the number ofbytes to write.- Throws:
IOException- if an I/O error occurs.
-
seek
Sets the current stream position and resets the bit offset to 0. It is legal to seeking past the end of the file; anEOFExceptionwill be thrown only if a read is performed. The file length will not be increased until a write is performed.- Parameters:
pos- alongcontaining the desired file pointer position.- Throws:
IndexOutOfBoundsException- ifposis smaller than the flushed position.IOException- if any other I/O error occurs.
-