Class StreamInput
- java.lang.Object
-
- java.io.InputStream
-
- cn.sliew.milky.common.io.stream.StreamInput
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
InputStreamStreamInput
public abstract class StreamInput extends InputStream
A stream from this node to another node. Technically, it can also be streamed to a byte array but that is mostly for testing.This class's methods are optimized so you can put the methods that read and write a class next to each other and you can scan them visually for differences. That means that most variables should be read and written in a single line so even large objects fit both reading and writing on the screen. It also means that the methods on this class are named very similarly to
StreamOutput. Finally it means that the "barrier to entry" for adding new methods to this class is relatively low even though it is a shared class with code everywhere. That being said, this class deals primarily withLists rather than Arrays. For the most part calls should adapt to lists, either by storingLists internally or just converting to and from aListwhen calling. This comment is repeated onStreamInput.
-
-
Constructor Summary
Constructors Constructor Description StreamInput()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intavailable()abstract voidclose()Closes the stream to further operations.booleanreadBoolean()Reads a boolean.abstract bytereadByte()Reads and returns a single byte.abstract voidreadBytes(byte[] b, int offset, int len)Reads a specified number of bytes into an array at the specified offset.doublereadDouble()floatreadFloat()ObjectreadGenericValue()Reads a value of unspecified type.intreadInt()Reads four bytes and returns an int.longreadLong()Reads eight bytes and returns a long.BooleanreadOptionalBoolean()DoublereadOptionalDouble()FloatreadOptionalFloat()IntegerreadOptionalInt()Reads an optionalInteger.LongreadOptionalLong()IntegerreadOptionalVInt()LongreadOptionalVLong()shortreadShort()intreadVInt()Reads an int stored in variable-length format.longreadVLong()Reads a long stored in variable-length format.longreadZLong()static StreamInputwrap(byte[] bytes)static StreamInputwrap(byte[] bytes, int offset, int length)-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Method Detail
-
wrap
public static StreamInput wrap(byte[] bytes)
-
wrap
public static StreamInput wrap(byte[] bytes, int offset, int length)
-
close
public abstract void close() throws IOExceptionCloses the stream to further operations.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
available
public abstract int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
readByte
public abstract byte readByte() throws IOExceptionReads and returns a single byte.- Throws:
IOException
-
readBytes
public abstract void readBytes(byte[] b, int offset, int len) throws IOExceptionReads a specified number of bytes into an array at the specified offset.- Parameters:
b- the array to read bytes intooffset- the offset in the array to start storing byteslen- the number of bytes to read- Throws:
IOException
-
readShort
public short readShort() throws IOException- Throws:
IOException
-
readInt
public int readInt() throws IOExceptionReads four bytes and returns an int.- Throws:
IOException
-
readOptionalInt
public Integer readOptionalInt() throws IOException
Reads an optionalInteger.- Throws:
IOException
-
readVInt
public int readVInt() throws IOExceptionReads an int stored in variable-length format. Reads between one and five bytes. Smaller values take fewer bytes. Negative numbers will always use all 5 bytes and are therefore better serialized usingreadInt()- Throws:
IOException
-
readOptionalVInt
public Integer readOptionalVInt() throws IOException
- Throws:
IOException
-
readLong
public long readLong() throws IOExceptionReads eight bytes and returns a long.- Throws:
IOException
-
readOptionalLong
public Long readOptionalLong() throws IOException
- Throws:
IOException
-
readVLong
public long readVLong() throws IOExceptionReads a long stored in variable-length format. Reads between one and ten bytes. Smaller values take fewer bytes. Negative numbers are encoded in ten bytes so preferreadLong()orreadZLong()for negative numbers.- Throws:
IOException
-
readOptionalVLong
public Long readOptionalVLong() throws IOException
- Throws:
IOException
-
readZLong
public long readZLong() throws IOException- Throws:
IOException
-
readFloat
public final float readFloat() throws IOException- Throws:
IOException
-
readOptionalFloat
public Float readOptionalFloat() throws IOException
- Throws:
IOException
-
readDouble
public final double readDouble() throws IOException- Throws:
IOException
-
readOptionalDouble
public final Double readOptionalDouble() throws IOException
- Throws:
IOException
-
readBoolean
public final boolean readBoolean() throws IOExceptionReads a boolean.- Throws:
IOException
-
readOptionalBoolean
public final Boolean readOptionalBoolean() throws IOException
- Throws:
IOException
-
readGenericValue
public Object readGenericValue() throws IOException
Reads a value of unspecified type. If a collection is read then the collection will be mutable if it contains any entry but might be immutable if it is empty.- Throws:
IOException
-
-