Class ProtonStreamUtils
java.lang.Object
org.apache.qpid.protonj2.codec.decoders.ProtonStreamUtils
Set of Utility methods useful when dealing with byte arrays and other
primitive types.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte
readByte
(InputStream stream) Reads a single byte from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static byte[]
readBytes
(InputStream stream, int length) Reads the given number of bytes from the providedInputStream
into an array and return that to the caller.static double
readDouble
(InputStream stream) Reads a double value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static byte
readEncodingCode
(InputStream stream) Reads a single byte from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static float
readFloat
(InputStream stream) Reads a float value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static int
readInt
(InputStream stream) Reads a integer value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static long
readLong
(InputStream stream) Reads a long value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static short
readShort
(InputStream stream) Reads a short value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.static InputStream
reset
(InputStream stream) Attempts to reset the providedInputStream
to a previously marked point.static InputStream
skipBytes
(InputStream stream, long amount) Attempts to skip the given number of bytes from the providedInputStream
instance and throws a DecodeException if an error occurs during the skip.static OutputStream
writeByte
(byte value, OutputStream stream) Write the givenByte
to the targetOutputStream
.static OutputStream
writeInt
(int value, OutputStream stream) Write the givenInteger
to the targetOutputStream
.static OutputStream
writeLong
(long value, OutputStream stream) Write the givenLong
to the targetOutputStream
.static OutputStream
writeShort
(short value, OutputStream stream) Write the givenShort
to the targetOutputStream
.
-
Constructor Details
-
ProtonStreamUtils
public ProtonStreamUtils()
-
-
Method Details
-
writeByte
Write the givenByte
to the targetOutputStream
.- Parameters:
value
- the value to write to theOutputStream
.stream
- theOutputStream
where the target value is to be written.- Returns:
- the given
OutputStream
instance. - Throws:
EncodeException
- if an error occurs while writing to the targetOutputStream
.
-
writeShort
Write the givenShort
to the targetOutputStream
.- Parameters:
value
- the value to write to theOutputStream
.stream
- theOutputStream
where the target value is to be written.- Returns:
- the given
OutputStream
instance. - Throws:
EncodeException
- if an error occurs while writing to the targetOutputStream
.
-
writeInt
Write the givenInteger
to the targetOutputStream
.- Parameters:
value
- the value to write to theOutputStream
.stream
- theOutputStream
where the target value is to be written.- Returns:
- the given
OutputStream
instance. - Throws:
EncodeException
- if an error occurs while writing to the targetOutputStream
.
-
writeLong
Write the givenLong
to the targetOutputStream
.- Parameters:
value
- the value to write to theOutputStream
.stream
- theOutputStream
where the target value is to be written.- Returns:
- the given
OutputStream
instance. - Throws:
EncodeException
- if an error occurs while writing to the targetOutputStream
.
-
readBytes
Reads the given number of bytes from the providedInputStream
into an array and return that to the caller. If the requested number of bytes cannot be read from the stream anDecodeException
is thrown to indicate an underflow.- Parameters:
stream
- TheInputStream
where the bytes should be read from.length
- The number of bytes to read from the given input stream.- Returns:
- a byte array containing the requested number of bytes read from the given
InputStream
- Throws:
DecodeException
- if an error occurs reading from the stream or insufficient bytes are available.
-
readEncodingCode
Reads a single byte from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
readByte
Reads a single byte from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
readShort
Reads a short value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
readInt
Reads a integer value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
readLong
Reads a long value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
readFloat
Reads a float value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
readDouble
Reads a double value from the givenInputStream
and thrown aDecodeException
if theInputStream
indicates an EOF condition was encountered.- Parameters:
stream
- TheInputStream
where the bytes should be read from.- Returns:
- the given byte that was read from the stream.
- Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
skipBytes
Attempts to skip the given number of bytes from the providedInputStream
instance and throws a DecodeException if an error occurs during the skip.- Parameters:
stream
- TheInputStream
where the bytes should be read from.amount
- The number of bytes that should be skipped.- Returns:
- the
InputStream
instance that was passed. - Throws:
DecodeException
- if an error occurs during the read or EOF is reached.
-
reset
Attempts to reset the providedInputStream
to a previously marked point. If an error occurs this method throws an DecodeException to describe the error.- Parameters:
stream
- TheInputStream
that is to be reset.- Returns:
- the
InputStream
instance that was passed. - Throws:
DecodeException
- if an error occurs during the reset.
-