Class InputStreamOrByteBufferAdapter
- java.lang.Object
-
- nonapi.io.github.classgraph.utils.InputStreamOrByteBufferAdapter
-
public abstract class InputStreamOrByteBufferAdapter extends Object
Buffer class that can wrap either an InputStream or a ByteBuffer, depending on which is available.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static InputStreamOrByteBufferAdapter
create(InputStream inputStream)
Create a new InputStream adapter.static InputStreamOrByteBufferAdapter
create(ByteBuffer byteBuffer)
Create a new ByteBuffer adapter.abstract int
read(byte[] array, int off, int len)
Copy up to len bytes into the byte array, starting at the given offset.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.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.
-
-
-
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 intooff
- 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.
-
create
public static InputStreamOrByteBufferAdapter create(InputStream inputStream)
Create a new InputStream adapter.- Parameters:
inputStream
- TheInputStream
to use.- Returns:
- The
InputStreamOrByteBufferAdapter
.
-
create
public static InputStreamOrByteBufferAdapter create(ByteBuffer byteBuffer)
Create a new ByteBuffer adapter.- Parameters:
byteBuffer
- TheByteBuffer
to use.- Returns:
- The
InputStreamOrByteBufferAdapter
.
-
-