Package com.google.common.io
Class LittleEndianDataOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.google.common.io.LittleEndianDataOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataOutput
,java.io.Flushable
,java.lang.AutoCloseable
@GwtIncompatible public final class LittleEndianDataOutputStream extends java.io.FilterOutputStream implements java.io.DataOutput
An implementation ofDataOutput
that uses little-endian byte ordering for writingchar
,short
,int
,float
,double
, andlong
values.Note: This class intentionally violates the specification of its supertype
DataOutput
, which explicitly requires big-endian byte order.- Since:
- 8.0
- Author:
- Chris Nokleberg, Keith Bottner
-
-
Constructor Summary
Constructors Constructor Description LittleEndianDataOutputStream(java.io.OutputStream out)
Creates aLittleEndianDataOutputStream
that wraps the given stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
void
write(byte[] b, int off, int len)
void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeBytes(java.lang.String s)
Deprecated.The semantics ofwriteBytes(String s)
are considered dangerous.void
writeChar(int v)
Writes a char as specified byDataOutputStream.writeChar(int)
, except using little-endian byte order.void
writeChars(java.lang.String s)
Writes aString
as specified byDataOutputStream.writeChars(String)
, except each character is written using little-endian byte order.void
writeDouble(double v)
Writes adouble
as specified byDataOutputStream.writeDouble(double)
, except using little-endian byte order.void
writeFloat(float v)
Writes afloat
as specified byDataOutputStream.writeFloat(float)
, except using little-endian byte order.void
writeInt(int v)
Writes anint
as specified byDataOutputStream.writeInt(int)
, except using little-endian byte order.void
writeLong(long v)
Writes along
as specified byDataOutputStream.writeLong(long)
, except using little-endian byte order.void
writeShort(int v)
Writes ashort
as specified byDataOutputStream.writeShort(int)
, except using little-endian byte order.void
writeUTF(java.lang.String str)
-
-
-
Constructor Detail
-
LittleEndianDataOutputStream
public LittleEndianDataOutputStream(java.io.OutputStream out)
Creates aLittleEndianDataOutputStream
that wraps the given stream.- Parameters:
out
- the stream to delegate to
-
-
Method Detail
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
write
in interfacejava.io.DataOutput
- Overrides:
write
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean v) throws java.io.IOException
- Specified by:
writeBoolean
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeByte
public void writeByte(int v) throws java.io.IOException
- Specified by:
writeByte
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeBytes
@Deprecated public void writeBytes(java.lang.String s) throws java.io.IOException
Deprecated.The semantics ofwriteBytes(String s)
are considered dangerous. Please usewriteUTF(String s)
,writeChars(String s)
or another write method instead.- Specified by:
writeBytes
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
writeChar
public void writeChar(int v) throws java.io.IOException
Writes a char as specified byDataOutputStream.writeChar(int)
, except using little-endian byte order.- Specified by:
writeChar
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeChars
public void writeChars(java.lang.String s) throws java.io.IOException
Writes aString
as specified byDataOutputStream.writeChars(String)
, except each character is written using little-endian byte order.- Specified by:
writeChars
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeDouble
public void writeDouble(double v) throws java.io.IOException
Writes adouble
as specified byDataOutputStream.writeDouble(double)
, except using little-endian byte order.- Specified by:
writeDouble
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeFloat
public void writeFloat(float v) throws java.io.IOException
Writes afloat
as specified byDataOutputStream.writeFloat(float)
, except using little-endian byte order.- Specified by:
writeFloat
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeInt
public void writeInt(int v) throws java.io.IOException
Writes anint
as specified byDataOutputStream.writeInt(int)
, except using little-endian byte order.- Specified by:
writeInt
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeLong
public void writeLong(long v) throws java.io.IOException
Writes along
as specified byDataOutputStream.writeLong(long)
, except using little-endian byte order.- Specified by:
writeLong
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeShort
public void writeShort(int v) throws java.io.IOException
Writes ashort
as specified byDataOutputStream.writeShort(int)
, except using little-endian byte order.- Specified by:
writeShort
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
- if an I/O error occurs
-
writeUTF
public void writeUTF(java.lang.String str) throws java.io.IOException
- Specified by:
writeUTF
in interfacejava.io.DataOutput
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
-