public final class ByteScanner extends Scanner
Scanner
implementation that scans binary data.
In order to use ByteScanner
, consider the following example:
File file = ...; StringBuilder stringBuilder = new StringBuilder(); ByteScanner byteScanner = ByteScanner.newInstance(file); byteScanner.nextInteger(0xCAFEBABE); byteScanner.consume(stringBuilder); System.out.println(stringBuilder);
Modifier and Type | Method and Description |
---|---|
void |
error()
Causes a
ScannerException to be thrown with an implementation-specific detail message. |
void |
error(java.lang.String message)
Causes a
ScannerException to be thrown with the given detail message. |
static ByteScanner |
newInstance(java.io.File file)
Returns a new
ByteScanner instance given a File . |
boolean |
next()
A simple method for advancing the index at the end of the next consumption.
|
boolean |
nextByte() |
boolean |
nextByte(byte value) |
boolean |
nextInteger() |
boolean |
nextInteger(int integer) |
byte |
peekByte() |
byte |
peekByte(int relativeIndex) |
void |
printBytes()
Prints the bytes to standard out in hex-form.
|
java.lang.String |
toString()
Returns a
String representation of this ByteScanner instance. |
java.lang.String |
toString(int absoluteIndex)
Returns a
String representation of the data at the given absolute index. |
consume, consume, consumption, getIndexAtBeginningOfConsumption, getIndexAtEndOfConsumption, mark, rewind, setIndexAtBeginningOfConsumption, setIndexAtEndOfConsumption, skip, testNext, unmark
public boolean next()
If it succeeds, true
is returned, false
otherwise.
This method is implemented in terms of the nextByte()
method.
public boolean nextByte()
public boolean nextByte(byte value)
public boolean nextInteger()
public boolean nextInteger(int integer)
public byte peekByte()
public byte peekByte(int relativeIndex)
public java.lang.String toString()
String
representation of this ByteScanner
instance.toString
in class java.lang.Object
String
representation of this ByteScanner
instancepublic java.lang.String toString(int absoluteIndex)
String
representation of the data at the given absolute index.
If absoluteIndex
is less than 0
, or greater than or equal to the size of the underlying ByteDataBuffer
, an IllegalArgumentException
will be thrown.
toString
in class Scanner
absoluteIndex
- the absolute indexString
representation of the data at the given absolute indexjava.lang.IllegalArgumentException
- thrown if, and only if, absoluteIndex
is less than 0
, or greater than or equal to the size of the underlying ByteDataBuffer
public void error()
ScannerException
to be thrown with an implementation-specific detail message.error
in class Scanner
ScannerException
- thrown if, and only if, this method is calledpublic void error(java.lang.String message)
ScannerException
to be thrown with the given detail message.
If message
is null
, a NullPointerException
will be thrown.
error
in class Scanner
message
- the detail message of the ScannerException
java.lang.NullPointerException
- thrown if, and only if, message
is null
ScannerException
- thrown if, and only if, this method is called and message
is not null
public void printBytes()
public static ByteScanner newInstance(java.io.File file)
ByteScanner
instance given a File
.
If file
is null
, a NullPointerException
will be thrown.
If any IO-errors occur, an UncheckedIOException
will be thrown.
file
- the File
to readByteScanner
instance given a File
java.lang.NullPointerException
- thrown if, and only if, file
is null
java.io.UncheckedIOException
- thrown if, and only if, any IO-errors occur