Package com.aoindustries.io.stream
Class StreamableOutput
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.DataOutputStream
-
- com.aoindustries.io.stream.StreamableOutput
-
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
public class StreamableOutput extends DataOutputStream
Adds compressed data transfer to DataOutputStream. This class is not thread safe.- Author:
- AO Industries, Inc.
- See Also:
StreamableInput
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_COMPRESSED_INT_VALUEThe maximum value of int that can be written viawriteCompressedInt(int)orwriteCompressedInt(int, java.io.OutputStream).static intMIN_COMPRESSED_INT_VALUEThe minimum value of int that can be written viawriteCompressedInt(int)orwriteCompressedInt(int, java.io.OutputStream).-
Fields inherited from class java.io.DataOutputStream
written
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description StreamableOutput(OutputStream out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidwriteCompressedInt(int i)static voidwriteCompressedInt(int i, OutputStream out)voidwriteCompressedUTF(String str)voidwriteCompressedUTF(String str, int slot)Writes a String to the stream while using prefix compression.voidwriteEnum(Enum<?> e)Writes anEnum, represented by itsEnum.name().voidwriteIdentifier(Identifier identifier)Writes anIdentifier.voidwriteLongUTF(String str)Writes a string of any length.voidwriteNullBoolean(Boolean b)voidwriteNullByte(Byte b)voidwriteNullEnum(Enum<?> e)voidwriteNullIdentifier(Identifier identifier)Writes a possibly-nullIdentifier.voidwriteNullInteger(Integer i)voidwriteNullLong(Long l)voidwriteNullLongUTF(String str)Writes a string of any length, supportingnull.voidwriteNullShort(Short s)voidwriteNullSmallIdentifier(SmallIdentifier identifier)Writes a possibly-nullSmallIdentifier.voidwriteNullTimestamp(Timestamp ts)Writes a possibly-nullTimestamp.voidwriteNullUTF(String str)voidwriteSmallIdentifier(SmallIdentifier identifier)Writes aSmallIdentifier.voidwriteTimestamp(Timestamp ts)Writes aTimestamp.static voidwriteTimestamp(Timestamp ts, DataOutputStream out)Writes aTimestamp, maintaining the full nanosecond precision.-
Methods inherited from class java.io.DataOutputStream
flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Methods inherited from class java.io.FilterOutputStream
close, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.io.DataOutput
write
-
-
-
-
Field Detail
-
MIN_COMPRESSED_INT_VALUE
public static final int MIN_COMPRESSED_INT_VALUE
The minimum value of int that can be written viawriteCompressedInt(int)orwriteCompressedInt(int, java.io.OutputStream).- See Also:
- Constant Field Values
-
MAX_COMPRESSED_INT_VALUE
public static final int MAX_COMPRESSED_INT_VALUE
The maximum value of int that can be written viawriteCompressedInt(int)orwriteCompressedInt(int, java.io.OutputStream).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StreamableOutput
public StreamableOutput(OutputStream out)
-
-
Method Detail
-
writeCompressedInt
public static void writeCompressedInt(int i, OutputStream out) throws IOException- Throws:
IOException- See Also:
StreamableInput.readCompressedInt()
-
writeCompressedInt
public void writeCompressedInt(int i) throws IOException- Throws:
IOException
-
writeCompressedUTF
public void writeCompressedUTF(String str) throws IOException
- Throws:
IOException
-
writeCompressedUTF
public void writeCompressedUTF(String str, int slot) throws IOException
Writes a String to the stream while using prefix compression.The first byte has these bits: X X X X X X X X | | +-+-+-+-+-+ Slot number (0-63) | +------------ 1 = Suffix UTF follows, 0 = No suffix UTF exists +-------------- 1 = Common length difference follows, 0 = Common length not changed Second, if common length difference is not zero, the common length change follows one less for positive differences because 0 is handled in first byte Third, if suffix UTF follows, writeUTF of all the string after common length- Throws:
IOException
-
writeNullUTF
public void writeNullUTF(String str) throws IOException
- Throws:
IOException
-
writeLongUTF
public void writeLongUTF(String str) throws IOException
Writes a string of any length.- Throws:
IOException
-
writeNullLongUTF
public void writeNullLongUTF(String str) throws IOException
Writes a string of any length, supportingnull.- Throws:
IOException
-
writeNullByte
public void writeNullByte(Byte b) throws IOException
- Throws:
IOException
-
writeNullShort
public void writeNullShort(Short s) throws IOException
- Throws:
IOException
-
writeNullInteger
public void writeNullInteger(Integer i) throws IOException
- Throws:
IOException
-
writeNullLong
public void writeNullLong(Long l) throws IOException
- Throws:
IOException
-
writeEnum
public void writeEnum(Enum<?> e) throws IOException
Writes anEnum, represented by itsEnum.name().- Throws:
IOException
-
writeNullEnum
public void writeNullEnum(Enum<?> e) throws IOException
- Throws:
IOException
-
writeNullBoolean
public void writeNullBoolean(Boolean b) throws IOException
- Throws:
IOException
-
writeTimestamp
public static void writeTimestamp(Timestamp ts, DataOutputStream out) throws IOException
Writes aTimestamp, maintaining the full nanosecond precision. Time zone offset is not maintained.The wire protocol is
DataOutputStream.writeLong(long)number of seconds followed bycompressed intnumber of nanoseconds.This is deliberately compatible with
Instantthat is part of Java 8. Once Java 8 is our minimum Java version, many uses ofTimestampwill change toInstant.- Throws:
IOException
-
writeTimestamp
public void writeTimestamp(Timestamp ts) throws IOException
Writes aTimestamp.- Throws:
IOException- See Also:
writeTimestamp(java.sql.Timestamp, java.io.DataOutputStream)
-
writeNullTimestamp
public void writeNullTimestamp(Timestamp ts) throws IOException
Writes a possibly-nullTimestamp.- Throws:
IOException- See Also:
writeTimestamp(java.sql.Timestamp)
-
writeIdentifier
public void writeIdentifier(Identifier identifier) throws IOException
Writes anIdentifier.- Throws:
IOException
-
writeNullIdentifier
public void writeNullIdentifier(Identifier identifier) throws IOException
Writes a possibly-nullIdentifier.- Throws:
IOException
-
writeSmallIdentifier
public void writeSmallIdentifier(SmallIdentifier identifier) throws IOException
Writes aSmallIdentifier.- Throws:
IOException
-
writeNullSmallIdentifier
public void writeNullSmallIdentifier(SmallIdentifier identifier) throws IOException
Writes a possibly-nullSmallIdentifier.- Throws:
IOException
-
-