Class ASCIIHexInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.jpedal.io.filter.ASCIIHexInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class ASCIIHexInputStream extends FilterInputStream
An input stream that lazily decodes ASCII Hex encoded data

The ASCIIHexDecode filter shall produce one byte of binary data for each pair of ASCII hexadecimal digits (0–9 and A–F or a–f). All white-space characters (see 7.2, "Lexical conventions") shall be ignored. A GREATER-THAN SIGN (3Eh) indicates EOD (End Of Data). Any other characters shall cause an error.
If the filter encounters the EOD marker after reading an odd number of hexadecimal digits, it shall behave as if a 0 (zero) followed the last digit.
- PDF Spec ISO 32000-2

  • Constructor Details

    • ASCIIHexInputStream

      public ASCIIHexInputStream(InputStream in)
  • Method Details

    • read

      public int read() throws IOException
      Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown
      Overrides:
      read in class FilterInputStream
      Returns:
      the next byte of data, or -1 if the end of the stream is reached.
      Throws:
      IOException - if an IO error occurs
    • read

      public int read(byte[] outputBuffer, int outputOffset, int byteCount) throws IOException
      Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.
      Overrides:
      read in class FilterInputStream
      Parameters:
      outputBuffer - the buffer into which the data is read.
      outputOffset - the start offset in array outputBytes at which the data is written.
      byteCount - the maximum number of bytes to read.
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
      Throws:
      IOException - if an IO error occurs
      Implementation Note:
      This method will retroactively notice the closing > before stopping just before. That means it will likely overrun this byte in the underlying InputStream with the assumption that it will be closed with this input stream.
    • skip

      public long skip(long n) throws IOException
      Skips over and discards n bytes of data from the input stream.

      The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

      Due to hex being 2 characters per byte, this method will skip twice as many bytes as requested from the underlying stream. The method will also ignore garbage in the underlying stream and only count valid hex whilst skipping.

      Overrides:
      skip in class FilterInputStream
      Parameters:
      n - the number of bytes to be skipped.
      Returns:
      the actual number of bytes skipped
      Throws:
      IOException - if an io error occurs
    • available

      public int available() throws IOException
      Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

      The result will be half the bytes available in the underlying InputStream due to 2 hex characters making one byte. Fewer bytes may actually be available as this does not account for garbage in the underlying stream.

      Overrides:
      available in class FilterInputStream
      Returns:
      an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.
      Throws:
      IOException - if an I/O error occurs