@NotThreadSafe public class LittleEndianOutputStream extends DecoratingOutputStream
This class is similar to DataOutputStream
,
but writes data in Little Endian format to its underlying stream.
A noteable difference to DataOutputStream
is that the
size()
method and the written
field are respectively
return long
values.
Modifier and Type | Field and Description |
---|---|
protected long |
written
The number of bytes written to the data output stream so far.
|
out
Modifier | Constructor and Description |
---|---|
protected |
LittleEndianOutputStream() |
|
LittleEndianOutputStream(OutputStream out) |
Modifier and Type | Method and Description |
---|---|
long |
size()
Returns the current value of the counter
written ,
the number of bytes written to this data output stream so far. |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off to the underlying output stream. |
void |
write(int b)
Writes the specified byte (the low eight bits of the argument
b ) to the underlying output stream. |
void |
writeBoolean(boolean b)
Writes a
boolean value to the underlying output stream
as a 1-byte value. |
void |
writeByte(int b)
Writes a
byte value to the underlying output stream
as a 1-byte value. |
void |
writeBytes(String s)
Writes the string
s to the underlying output stream as a
sequence of bytes. |
void |
writeChar(int c)
Writes a
char value to the underlying output stream
as a 2-byte value, low byte first. |
void |
writeChars(String s)
Writes the string
s to the underlying output stream as a
sequence of characters. |
void |
writeDouble(double d)
Converts the double value
d to a long using
the doubleToLongBits method in class Double ,
and then writes that long value to the underlying
output stream as an 8-byte quantity, low byte first. |
void |
writeFloat(float f)
Converts the float value
f to an int using
the floatToIntBits method in class Float ,
and then writes that int value to the underlying
output stream as a 4-byte quantity, low byte first. |
void |
writeInt(int i)
Writes the integer value
i to the underlying output stream
as four bytes, low byte first. |
void |
writeLong(long l)
Writes the integer value
l to the underlying output stream
as eight bytes, low byte first. |
void |
writeShort(int s)
Writes the integer value
s to the underlying output stream
as two bytes, low byte first. |
void |
writeUTF(String str)
This method is not implemented.
|
close, flush, toString, write
protected long written
Long.MAX_VALUE
.DataOutputStream.written
protected LittleEndianOutputStream()
public LittleEndianOutputStream(@WillCloseWhenClosed OutputStream out)
public final long size()
written
,
the number of bytes written to this data output stream so far.
If the counter overflows, it will get adjusted to Long.MAX_VALUE
.written
.DataOutputStream.size()
public void write(byte[] b, int off, int len) throws IOException
len
bytes from the specified byte array
starting at offset off
to the underlying output stream.
If no exception is thrown, the counter written
is
incremented by len
.write
in class DecoratingOutputStream
b
- The data.off
- The start offset in the data.len
- The number of bytes to write.IOException
- on any I/O error.public void write(int b) throws IOException
b
) to the underlying output stream.
If no exception is thrown, the counter written
is
incremented by one.
Implements the write
method of OutputStream
.
write
in class DecoratingOutputStream
b
- The byte
to be written.IOException
- on any I/O error.public final void writeBoolean(boolean b) throws IOException
boolean
value to the underlying output stream
as a 1-byte value. The value true
is written out as the
value (byte)1
; the value false
is
written out as the value (byte)0
.
If no exception is thrown, the counter written
is
incremented by one.b
- The boolean
value to be written.IOException
- on any I/O error.public final void writeByte(int b) throws IOException
byte
value to the underlying output stream
as a 1-byte value.
If no exception is thrown, the counter written
is
incremented by one.b
- The byte
value to be written.IOException
- on any I/O error.public final void writeBytes(String s) throws IOException
s
to the underlying output stream as a
sequence of bytes. Each character in the string is written out, in
sequence, by discarding its high eight bits.
If no exception is thrown, the counter written
is
incremented by the length of s
.s
- The string of bytes to be written.IOException
- on any I/O error.public final void writeChar(int c) throws IOException
char
value to the underlying output stream
as a 2-byte value, low byte first.
If no exception is thrown, the counter written
is
incremented by two.c
- The char
value to be written.IOException
- on any I/O error.public final void writeChars(String s) throws IOException
s
to the underlying output stream as a
sequence of characters. Each character is written out as
if by the writeChar
method.
If no exception is thrown, the counter written
is
incremented by twice the length of s
.s
- The String
value to be written.IOException
- on any I/O error.DataOutputStream.writeChar(int)
public final void writeDouble(double d) throws IOException
d
to a long
using
the doubleToLongBits
method in class Double
,
and then writes that long
value to the underlying
output stream as an 8-byte quantity, low byte first.
If no exception is thrown, the counter written
is
incremented by 8
.d
- The double
value to be written.IOException
- on any I/O error.Double.doubleToLongBits(double)
public final void writeFloat(float f) throws IOException
f
to an int
using
the floatToIntBits
method in class Float
,
and then writes that int
value to the underlying
output stream as a 4-byte quantity, low byte first.
If no exception is thrown, the counter written
is
incremented by 4
.f
- The float
value to be written.IOException
- on any I/O error.Float.floatToIntBits(float)
public final void writeInt(int i) throws IOException
i
to the underlying output stream
as four bytes, low byte first.
If no exception is thrown, the counter written
is
incremented by four.i
- The integer value to be written.IOException
- on any I/O error.public final void writeLong(long l) throws IOException
l
to the underlying output stream
as eight bytes, low byte first.
If no exception is thrown, the counter written
is
incremented by eight.l
- The long integer value to be written.IOException
- on any I/O error.public final void writeShort(int s) throws IOException
s
to the underlying output stream
as two bytes, low byte first.
If no exception is thrown, the counter written
is
incremented by two.s
- The short integer value to be written.IOException
- on any I/O error.public void writeUTF(String str) throws IOException
str
- the string to write.UnsupportedOperationException
- Always.IOException
Copyright © 2012–2016 Schlichtherle IT Services. All rights reserved.