- All Superinterfaces:
AutoCloseable
,Closeable
,DataInput
,DataOutput
,ImageInputStream
- All Known Implementing Classes:
FileCacheImageOutputStream
,FileImageOutputStream
,ImageOutputStreamImpl
,MemoryCacheImageOutputStream
public interface ImageOutputStream extends ImageInputStream, DataOutput
ImageWriter
s. Various output destinations, such as
OutputStream
s and File
s, as well as
future fast I/O destinations may be "wrapped" by a suitable
implementation of this interface for use by the Image I/O API.
Unlike a standard OutputStream
, ImageOutputStream
extends its counterpart, ImageInputStream
. Thus it is
possible to read from the stream as it is being written. The same
seek and flush positions apply to both reading and writing, although
the semantics for dealing with a non-zero bit offset before a byte-aligned
write are necessarily different from the semantics for dealing with
a non-zero bit offset before a byte-aligned read. When reading bytes,
any bit offset is set to 0 before the read; when writing bytes, a
non-zero bit offset causes the remaining bits in the byte to be written
as 0s. The byte-aligned write then starts at the next byte position.
- See Also:
ImageInputStream
-
Method Summary
Modifier and Type Method Description void
flushBefore(long pos)
Flushes all data prior to the given position to the underlying destination, such as anOutputStream
orFile
.void
write(byte[] b)
Writes a sequence of bytes to the stream at the current position.void
write(byte[] b, int off, int len)
Writes a sequence of bytes to the stream at the current position.void
write(int b)
Writes a single byte to the stream at the current position.void
writeBit(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.void
writeBits(long bits, int numBits)
Writes a sequence of bits, given by thenumBits
least significant bits of thebits
argument in left-to-right order, to the stream at the current bit offset within the current byte position.void
writeBoolean(boolean v)
Writes aboolean
value to the stream.void
writeByte(int v)
Writes the 8 low-order bits ofv
to the stream.void
writeBytes(String s)
Writes a string to the output stream.void
writeChar(int v)
This method is a synonym forwriteShort
.void
writeChars(char[] c, int off, int len)
Writes a sequence of chars to the stream at the current position.void
writeChars(String s)
Writes a string to the output stream.void
writeDouble(double v)
Writes adouble
value, which is comprised of four bytes, to the output stream.void
writeDoubles(double[] d, int off, int len)
Writes a sequence of doubles to the stream at the current position.void
writeFloat(float v)
Writes afloat
value, which is comprised of four bytes, to the output stream.void
writeFloats(float[] f, int off, int len)
Writes a sequence of floats to the stream at the current position.void
writeInt(int v)
Writes the 32 bits ofv
to the stream.void
writeInts(int[] i, int off, int len)
Writes a sequence of ints to the stream at the current position.void
writeLong(long v)
Writes the 64 bits ofv
to the stream.void
writeLongs(long[] l, int off, int len)
Writes a sequence of longs to the stream at the current position.void
writeShort(int v)
Writes the 16 low-order bits ofv
to the stream.void
writeShorts(short[] s, int off, int len)
Writes a sequence of shorts to the stream at the current position.void
writeUTF(String s)
Writes 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 interface javax.imageio.stream.ImageInputStream
close, flush, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, length, mark, read, read, 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
-
Method Details
-
write
Writes a single byte to the stream at the current position. The 24 high-order bits ofb
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 ofImageOutputStreamImpl
to guarantee this.- Specified by:
write
in interfaceDataOutput
- Parameters:
b
- anint
whose lower 8 bits are to be written.- Throws:
IOException
- if an I/O error occurs.
-
write
Writes a sequence of bytes to the stream at the current position. Ifb.length
is 0, nothing is written. The byteb[0]
is written first, then the byteb[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.
- Specified by:
write
in interfaceDataOutput
- Parameters:
b
- an array ofbyte
s to be written.- Throws:
NullPointerException
- ifb
isnull
.IOException
- if an I/O error occurs.
-
write
Writes a sequence of bytes to the stream at the current position. Iflen
is 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
flushBits
method ofImageOutputStreamImpl
to guarantee this.- Specified by:
write
in interfaceDataOutput
- Parameters:
b
- an array ofbyte
s to be written.off
- the start offset in the data.len
- the number ofbyte
s to write.- Throws:
IndexOutOfBoundsException
- ifoff
is negative,len
is negative, oroff + len
is greater thanb.length
.NullPointerException
- ifb
isnull
.IOException
- if an I/O error occurs.
-
writeBoolean
Writes aboolean
value to the stream. Ifv
is true, the value(byte)1
is written; ifv
is false, the value(byte)0
is written.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.
- Specified by:
writeBoolean
in interfaceDataOutput
- Parameters:
v
- theboolean
to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeByte
Writes the 8 low-order bits ofv
to the stream. The 24 high-order bits ofv
are ignored. (This means thatwriteByte
does exactly the same thing aswrite
for an integer argument.)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.
- Specified by:
writeByte
in interfaceDataOutput
- Parameters:
v
- anint
containing the byte value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeShort
Writes the 16 low-order bits ofv
to the stream. The 16 high-order bits ofv
are ignored. If the stream uses network byte order, the bytes written, in order, will be:(byte)((v >> 8) & 0xff) (byte)(v & 0xff)
Otherwise, the bytes written will be:(byte)(v & 0xff) (byte)((v >> 8) & 0xff)
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.
- Specified by:
writeShort
in interfaceDataOutput
- Parameters:
v
- anint
containing the short value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeChar
This method is a synonym forwriteShort
.- Specified by:
writeChar
in interfaceDataOutput
- Parameters:
v
- anint
containing the char (unsigned short) value to be written.- Throws:
IOException
- if an I/O error occurs.- See Also:
writeShort(int)
-
writeInt
Writes the 32 bits ofv
to the stream. If the stream uses network byte order, the bytes written, in order, will be:(byte)((v >> 24) & 0xff) (byte)((v >> 16) & 0xff) (byte)((v >> 8) & 0xff) (byte)(v & 0xff)
Otheriwse, the bytes written will be:(byte)(v & 0xff) (byte)((v >> 8) & 0xff) (byte)((v >> 16) & 0xff) (byte)((v >> 24) & 0xff)
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.
- Specified by:
writeInt
in interfaceDataOutput
- Parameters:
v
- anint
containing the value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeLong
Writes the 64 bits ofv
to the stream. If the stream uses network byte order, the bytes written, in order, will be:(byte)((v >> 56) & 0xff) (byte)((v >> 48) & 0xff) (byte)((v >> 40) & 0xff) (byte)((v >> 32) & 0xff) (byte)((v >> 24) & 0xff) (byte)((v >> 16) & 0xff) (byte)((v >> 8) & 0xff) (byte)(v & 0xff)
Otherwise, the bytes written will be:(byte)(v & 0xff) (byte)((v >> 8) & 0xff) (byte)((v >> 16) & 0xff) (byte)((v >> 24) & 0xff) (byte)((v >> 32) & 0xff) (byte)((v >> 40) & 0xff) (byte)((v >> 48) & 0xff) (byte)((v >> 56) & 0xff)
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.
- Specified by:
writeLong
in interfaceDataOutput
- Parameters:
v
- along
containing the value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeFloat
Writes afloat
value, which is comprised of four bytes, to the output stream. It does this as if it first converts thisfloat
value to anint
in exactly the manner of theFloat.floatToIntBits
method and then writes the int value in exactly the manner of thewriteInt
method.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.
- Specified by:
writeFloat
in interfaceDataOutput
- Parameters:
v
- afloat
containing the value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeDouble
Writes adouble
value, which is comprised of four bytes, to the output stream. It does this as if it first converts thisdouble
value to along
in exactly the manner of theDouble.doubleToLongBits
method and then writes the long value in exactly the manner of thewriteLong
method.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.
- Specified by:
writeDouble
in interfaceDataOutput
- Parameters:
v
- adouble
containing the value to be written.- Throws:
IOException
- if an I/O error occurs.
-
writeBytes
Writes a string to the output stream. For every character in the strings
, taken in order, one byte is written to the output stream. Ifs
isnull
, aNullPointerException
is thrown.If
s.length
is zero, then no bytes are written. Otherwise, the characters[0]
is written first, thens[1]
, and so on; the last character written iss[s.length-1]
. For each character, one byte is written, the low-order byte, in exactly the manner of thewriteByte
method. The high-order eight bits of each character in the string 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.
- Specified by:
writeBytes
in interfaceDataOutput
- Parameters:
s
- aString
containing the value to be written.- Throws:
NullPointerException
- ifs
isnull
.IOException
- if an I/O error occurs.
-
writeChars
Writes a string to the output stream. For every character in the strings
, taken in order, two bytes are written to the output stream, ordered according to the current byte order setting. If network byte order is being used, the high-order byte is written first; the order is reversed otherwise. Ifs
isnull
, aNullPointerException
is thrown.If
s.length
is zero, then no bytes are written. Otherwise, the characters[0]
is written first, thens[1]
, and so on; the last character written iss[s.length-1]
.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.
- Specified by:
writeChars
in interfaceDataOutput
- Parameters:
s
- aString
containing the value to be written.- Throws:
NullPointerException
- ifs
isnull
.IOException
- if an I/O error occurs.
-
writeUTF
Writes 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
. Ifs
isnull
, aNullPointerException
is thrown. Each character in the strings
is converted to a group of one, two, or three bytes, depending on the value of the character.If a character
c
is in the range\u0001
through\u007f
, it is represented by one byte:(byte)c
If a character
c
is\u0000
or is in the range\u0080
through\u07ff
, then it is represented by two bytes, to be written in the order shown:(byte)(0xc0 | (0x1f & (c >> 6))) (byte)(0x80 | (0x3f & c))
If a character
c
is in the range\u0800
throughuffff
, then it is represented by three bytes, to be written in the order shown:(byte)(0xe0 | (0x0f & (c >> 12))) (byte)(0x80 | (0x3f & (c >> 6))) (byte)(0x80 | (0x3f & c))
First, the total number of bytes needed to represent all the characters of
s
is calculated. If this number is larger than65535
, then aUTFDataFormatException
is thrown. Otherwise, this length is written to the output stream in exactly the manner of thewriteShort
method; after this, the one-, two-, or three-byte representation of each character in the strings
is written.The current byte order setting is 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.
Note: This method should not be used in the implementation of image formats that use standard UTF-8, because the modified UTF-8 used here is incompatible with standard UTF-8.
- Specified by:
writeUTF
in interfaceDataOutput
- Parameters:
s
- aString
containing the value to be written.- Throws:
NullPointerException
- ifs
isnull
.UTFDataFormatException
- if the modified UTF-8 representation ofs
requires more than 65536 bytes.IOException
- if an I/O error occurs.
-
writeShorts
Writes a sequence of shorts to the stream at the current position. Iflen
is 0, nothing is written. The shorts[off]
is written first, then the shorts[off + 1]
, and so on. The byte order of the stream is used to determine the order in which the individual bytes are written.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.
- Parameters:
s
- an array ofshort
s to be written.off
- the start offset in the data.len
- the number ofshort
s to write.- Throws:
IndexOutOfBoundsException
- ifoff
is negative,len
is negative, oroff + len
is greater thans.length
.NullPointerException
- ifs
isnull
.IOException
- if an I/O error occurs.
-
writeChars
Writes a sequence of chars to the stream at the current position. Iflen
is 0, nothing is written. The charc[off]
is written first, then the charc[off + 1]
, and so on. The byte order of the stream is used to determine the order in which the individual bytes are written.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.
- Parameters:
c
- an array ofchar
s to be written.off
- the start offset in the data.len
- the number ofchar
s to write.- Throws:
IndexOutOfBoundsException
- ifoff
is negative,len
is negative, oroff + len
is greater thanc.length
.
-