- java.lang.Object
-
- java.io.OutputStream
-
- net.morimekta.io.BinaryOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
- Direct Known Subclasses:
BigEndianBinaryOutputStream
,LittleEndianBinaryOutputStream
public abstract class BinaryOutputStream extends OutputStream
IO-Optimized binary writer. This is somewhat similar to the native javaObjectOutput
, but that it
-
-
Field Summary
Fields Modifier and Type Field Description protected OutputStream
out
-
Constructor Summary
Constructors Constructor Description BinaryOutputStream(OutputStream out)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
void
write(byte[] bytes)
void
write(byte[] bytes, int off, int len)
void
write(int b)
int
writeBase128(int i)
Write a signed number as varint (integer with variable number of bytes, determined as part of the bytes themselves.int
writeBase128(long i)
Write a signed number as base 128 (integer with variable number of bytes, determined as part of the bytes themselves.void
writeByte(byte integer)
Write a signed byte to the output stream.void
writeDouble(double value)
Write a double value to stream.void
writeFloat(float value)
Write a float value to stream.abstract void
writeInt(int integer)
Write a signed int to the output stream.abstract void
writeLong(long integer)
Write a signed long to the output stream.abstract void
writeShort(short integer)
Write a signed short to the output stream.void
writeSigned(int number, int bytes)
void
writeSigned(long number, int bytes)
abstract void
writeUInt16(int number)
abstract void
writeUInt24(int number)
abstract void
writeUInt32(int number)
void
writeUInt8(int number)
void
writeUnsigned(int number, int bytes)
int
writeVarint(int number)
Deprecated.int
writeVarint(long number)
Deprecated.int
writeZigzag(int number)
Write a long number as zigzag encoded to the stream.int
writeZigzag(long number)
Write a long number as zigzag encoded to the stream.-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream
-
-
-
-
Field Detail
-
out
protected final OutputStream out
-
-
Constructor Detail
-
BinaryOutputStream
public BinaryOutputStream(OutputStream out)
-
-
Method Detail
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] bytes) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] bytes, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
writeByte
public void writeByte(byte integer) throws IOException
Write a signed byte to the output stream.- Parameters:
integer
- The number to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeShort
public abstract void writeShort(short integer) throws IOException
Write a signed short to the output stream.- Parameters:
integer
- The number to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeInt
public abstract void writeInt(int integer) throws IOException
Write a signed int to the output stream.- Parameters:
integer
- The number to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeLong
public abstract void writeLong(long integer) throws IOException
Write a signed long to the output stream.- Parameters:
integer
- The number to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeFloat
public void writeFloat(float value) throws IOException
Write a float value to stream.- Parameters:
value
- The double value to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeDouble
public void writeDouble(double value) throws IOException
Write a double value to stream.- Parameters:
value
- The double value to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeUInt8
public void writeUInt8(int number) throws IOException
- Parameters:
number
- Unsigned byte to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeUInt16
public abstract void writeUInt16(int number) throws IOException
- Parameters:
number
- Unsigned short to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeUInt24
public abstract void writeUInt24(int number) throws IOException
- Parameters:
number
- Unsigned short to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeUInt32
public abstract void writeUInt32(int number) throws IOException
- Parameters:
number
- Unsigned short to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeUnsigned
public void writeUnsigned(int number, int bytes) throws IOException
- Parameters:
number
- Unsigned integer to writeBinary.bytes
- Number of bytes to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeSigned
public void writeSigned(int number, int bytes) throws IOException
- Parameters:
number
- Signed integer to writeBinary.bytes
- Number of bytes to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeSigned
public void writeSigned(long number, int bytes) throws IOException
- Parameters:
number
- Signed integer to writeBinary.bytes
- Number of bytes to writeBinary.- Throws:
IOException
- if unable to write to stream.
-
writeZigzag
public int writeZigzag(int number) throws IOException
Write a long number as zigzag encoded to the stream. The least significant bit becomes the sign, and the actual value is mad absolute and shifted one bit. This makes it maximum compressed both when positive and negative.- Parameters:
number
- The number to writeBinary.- Returns:
- Number of bytes written.
- Throws:
IOException
- if unable to write to stream.
-
writeZigzag
public int writeZigzag(long number) throws IOException
Write a long number as zigzag encoded to the stream. The least significant bit becomes the sign, and the actual value is mad absolute and shifted one bit. This makes it maximum compressed both when positive and negative.- Parameters:
number
- The number to writeBinary.- Returns:
- Number of bytes written.
- Throws:
IOException
- if unable to write to stream.
-
writeVarint
@Deprecated public int writeVarint(int number) throws IOException
Deprecated.- Throws:
IOException
-
writeBase128
public int writeBase128(int i) throws IOException
Write a signed number as varint (integer with variable number of bytes, determined as part of the bytes themselves.- Parameters:
i
- The number to writeBinary.- Returns:
- The number of bytes written.
- Throws:
IOException
- if unable to write to stream.
-
writeVarint
@Deprecated public int writeVarint(long number) throws IOException
Deprecated.- Throws:
IOException
-
writeBase128
public int writeBase128(long i) throws IOException
Write a signed number as base 128 (integer with variable number of bytes, determined as part of the bytes themselves.- Parameters:
i
- The number to writeBinary.- Returns:
- The number of bytes written.
- Throws:
IOException
- if unable to write to stream.
-
-