Class InputStreamOrByteBufferAdapter


  • public abstract class InputStreamOrByteBufferAdapter
    extends Object
    Buffer class that can wrap either an InputStream or a ByteBuffer, depending on which is available.
    • Field Detail

      • buf

        public byte[] buf
        Bytes read from the beginning of the classfile. This array is reused across calls.
      • curr

        public int curr
        The current position in the buffer.
      • used

        public int used
        Bytes used in the buffer.
    • Method Detail

      • readInitialChunk

        public void readInitialChunk()
                              throws IOException
        Read an initial chunk of the file into the buffer.
        Throws:
        IOException - If a chunk of the file content could not be read.
      • readUnsignedByte

        public int readUnsignedByte()
                             throws IOException
        Read an unsigned byte from the buffer.
        Returns:
        The next unsigned byte in the buffer.
        Throws:
        IOException - If there was an exception while reading.
      • readUnsignedByte

        public int readUnsignedByte​(int offset)
        Read an unsigned byte from the buffer at a specific absolute offset before the current read point.
        Parameters:
        offset - The buffer offset to read from.
        Returns:
        The unsigned byte at the buffer offset.
      • readUnsignedShort

        public int readUnsignedShort()
                              throws IOException
        Returns:
        The next unsigned short in the buffer.
        Throws:
        IOException - If there was an exception while reading.
      • readUnsignedShort

        public int readUnsignedShort​(int offset)
        Read an unsigned short from the buffer at a specific absolute offset before the current read point.
        Parameters:
        offset - The buffer offset to read from.
        Returns:
        The unsigned short at the buffer offset.
      • readInt

        public int readInt()
                    throws IOException
        Returns:
        The next int in the buffer.
        Throws:
        IOException - If there was an exception while reading.
      • readInt

        public int readInt​(int offset)
        Read an int from the buffer at a specific absolute offset before the current read point.
        Parameters:
        offset - The buffer offset to read from.
        Returns:
        The int at the buffer offset.
      • readLong

        public long readLong()
                      throws IOException
        Returns:
        The next long in the buffer.
        Throws:
        IOException - If there was an exception while reading.
      • readLong

        public long readLong​(int offset)
        Read a long from the buffer at a specific offset before the current read point.
        Parameters:
        offset - The buffer offset to read from.
        Returns:
        The long at the buffer offset.
      • skip

        public void skip​(int bytesToSkip)
                  throws IOException
        Skip the given number of bytes in the input stream.
        Parameters:
        bytesToSkip - The number of bytes to skip.
        Throws:
        IOException - If there was an exception while reading.
      • readString

        public String readString​(int strStart,
                                 boolean replaceSlashWithDot,
                                 boolean stripLSemicolon)
        Reads the "modified UTF8" format defined in the Java classfile spec, optionally replacing '/' with '.', and optionally removing the prefix "L" and the suffix ";".
        Parameters:
        strStart - The start index of the string.
        replaceSlashWithDot - If true, replace '/' with '.'.
        stripLSemicolon - If true, string final ';' character.
        Returns:
        The string.
      • read

        public abstract int read​(byte[] array,
                                 int off,
                                 int len)
                          throws IOException
        Copy up to len bytes into the byte array, starting at the given offset.
        Parameters:
        array - The array to copy into
        off - The start index for the copy.
        len - The maximum number of bytes to copy.
        Returns:
        The number of bytes actually copied.
        Throws:
        IOException - If the file content could not be read.