Class InputStreamOrByteBufferAdapter
- java.lang.Object
-
- nonapi.io.github.classgraph.utils.InputStreamOrByteBufferAdapter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class InputStreamOrByteBufferAdapter extends java.lang.Object implements java.lang.AutoCloseable
Buffer class that can wrap either an InputStream or a ByteBuffer, depending on which is available.
-
-
Constructor Summary
Constructors Constructor Description InputStreamOrByteBufferAdapter(java.io.InputStream inputStream)
Create anInputStreamOrByteBufferAdapter
from anInputStream
.InputStreamOrByteBufferAdapter(java.nio.ByteBuffer byteBuffer)
Create anInputStreamOrByteBufferAdapter
from anInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
readInitialChunk()
Read an initial chunk of the file into the buffer.int
readInt()
int
readInt(int offset)
Read an int from the buffer at a specific absolute offset before the current read point.long
readLong()
long
readLong(int offset)
Read a long from the buffer at a specific offset before the current read point.java.lang.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 ";".int
readUnsignedByte()
Read an unsigned byte from the buffer.int
readUnsignedByte(int offset)
Read an unsigned byte from the buffer at a specific absolute offset before the current read point.int
readUnsignedShort()
int
readUnsignedShort(int offset)
Read an unsigned short from the buffer at a specific absolute offset before the current read point.void
skip(int bytesToSkip)
Skip the given number of bytes in the input stream.
-
-
-
Constructor Detail
-
InputStreamOrByteBufferAdapter
public InputStreamOrByteBufferAdapter(java.io.InputStream inputStream)
Create anInputStreamOrByteBufferAdapter
from anInputStream
.
-
InputStreamOrByteBufferAdapter
public InputStreamOrByteBufferAdapter(java.nio.ByteBuffer byteBuffer)
Create anInputStreamOrByteBufferAdapter
from anInputStream
.
-
-
Method Detail
-
readInitialChunk
public void readInitialChunk() throws java.io.IOException
Read an initial chunk of the file into the buffer.- Throws:
java.io.IOException
- If a chunk of the file content could not be read.
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
Read an unsigned byte from the buffer.- Returns:
- The next unsigned byte in the buffer.
- Throws:
java.io.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 java.io.IOException
- Returns:
- The next unsigned short in the buffer.
- Throws:
java.io.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 java.io.IOException
- Returns:
- The next int in the buffer.
- Throws:
java.io.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 java.io.IOException
- Returns:
- The next long in the buffer.
- Throws:
java.io.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 java.io.IOException
Skip the given number of bytes in the input stream.- Parameters:
bytesToSkip
- The number of bytes to skip.- Throws:
java.io.IOException
- If there was an exception while reading.
-
readString
public java.lang.String readString(int strStart, boolean replaceSlashWithDot, boolean stripLSemicolon) throws java.io.IOException
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.
- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-