Class DecodingInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.cryptacular.io.DecodingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class DecodingInputStream extends FilterInputStream
Filters read bytes through a Decoder such that consumers obtain raw (decoded) bytes from read operations.
  • Field Details

    • decoder

      private final Decoder decoder
      Performs decoding.
    • reader

      private final InputStreamReader reader
      Wraps the input stream to convert bytes to characters.
    • input

      private CharBuffer input
      Holds input bytes as characters.
    • output

      private ByteBuffer output
      Receives decoding result.
  • Constructor Details

    • DecodingInputStream

      public DecodingInputStream(InputStream in, Decoder d)
      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

      public int read() throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • base64

      public static DecodingInputStream base64(InputStream in)
      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

      public static DecodingInputStream hex(InputStream in)
      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.