Package org.cryptacular.io
Class DecodingInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.cryptacular.io.DecodingInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Filters read bytes through a
Decoder such that consumers obtain raw (decoded) bytes from read operations.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DecoderPerforms decoding.private CharBufferHolds input bytes as characters.private ByteBufferReceives decoding result.private final InputStreamReaderWraps the input stream to convert bytes to characters.Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance that wraps the given stream and performs decoding using the given encoder component. -
Method Summary
Modifier and TypeMethodDescriptionstatic DecodingInputStreambase64(InputStream in) Creates a new instance that decodes base64 input from the given stream.static DecodingInputStreamhex(InputStream in) Creates a new instance that decodes hexadecimal input from the given stream.private voidprepareInputBuffer(int required) Prepares the input buffer to receive the given number of bytes.private voidPrepares the output buffer based on input buffer capacity.intread()intread(byte[] b) intread(byte[] b, int off, int len) Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skip
-
Field Details
-
decoder
Performs decoding. -
reader
Wraps the input stream to convert bytes to characters. -
input
Holds input bytes as characters. -
output
Receives decoding result.
-
-
Constructor Details
-
DecodingInputStream
Creates a new instance that wraps the given stream and performs decoding using the given encoder component.- Parameters:
in- Input stream to wrap.d- Decoder that provides on-the-fly decoding.
-
-
Method Details
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
base64
Creates a new instance that decodes base64 input from the given stream.- Parameters:
in- Wrapped input stream.- Returns:
- Decoding input stream that decodes base64 output.
-
hex
Creates a new instance that decodes hexadecimal input from the given stream.- Parameters:
in- Wrapped input stream.- Returns:
- Decoding input stream that decodes hexadecimal output.
-
prepareInputBuffer
private void prepareInputBuffer(int required) Prepares the input buffer to receive the given number of bytes.- Parameters:
required- Number of bytes required.
-
prepareOutputBuffer
private void prepareOutputBuffer()Prepares the output buffer based on input buffer capacity.
-