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.AutoCloseableBuffer 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 anInputStreamOrByteBufferAdapterfrom anInputStream.InputStreamOrByteBufferAdapter(java.nio.ByteBuffer byteBuffer)Create anInputStreamOrByteBufferAdapterfrom anInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidreadInitialChunk()Read an initial chunk of the file into the buffer.intreadInt()intreadInt(int offset)Read an int from the buffer at a specific absolute offset before the current read point.longreadLong()longreadLong(int offset)Read a long from the buffer at a specific offset before the current read point.java.lang.StringreadString(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 ";".intreadUnsignedByte()Read an unsigned byte from the buffer.intreadUnsignedByte(int offset)Read an unsigned byte from the buffer at a specific absolute offset before the current read point.intreadUnsignedShort()intreadUnsignedShort(int offset)Read an unsigned short from the buffer at a specific absolute offset before the current read point.voidskip(int bytesToSkip)Skip the given number of bytes in the input stream.
-
-
-
Constructor Detail
-
InputStreamOrByteBufferAdapter
public InputStreamOrByteBufferAdapter(java.io.InputStream inputStream)
Create anInputStreamOrByteBufferAdapterfrom anInputStream.
-
InputStreamOrByteBufferAdapter
public InputStreamOrByteBufferAdapter(java.nio.ByteBuffer byteBuffer)
Create anInputStreamOrByteBufferAdapterfrom anInputStream.
-
-
Method Detail
-
readInitialChunk
public void readInitialChunk() throws java.io.IOExceptionRead 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.IOExceptionRead 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.IOExceptionSkip 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.IOExceptionReads 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:
closein interfacejava.lang.AutoCloseable
-
-