mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-20 09:17:29 +07:00
Adjusted documentation and added ByteInput#readString(int,boolean)
This commit is contained in:
parent
efce34ef8a
commit
e3fc03f240
@ -478,12 +478,12 @@ public class BitInput {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <i>n</i> characters of size {@code bits} and constructs a string.
|
||||
* Reads up to <i>n</i> characters of size {@code bits} and constructs a
|
||||
* string.
|
||||
*
|
||||
* @param maxLen number of characters to read
|
||||
* @param maxLen maximum number of characters to read
|
||||
* @param bits size of each character ({@code 7} or {@code 8})
|
||||
* @param nullTerminated {@code true} to stop reading at {@code \0}, otherwise
|
||||
* {@code maxLen} characters will be read (variable-width string)
|
||||
* @param nullTerminated {@code true} to stop reading at {@code '\0}'
|
||||
*/
|
||||
public String readString(int maxLen, int bits, boolean nullTerminated) {
|
||||
if (maxLen < 0) throw new IllegalArgumentException("maxLen(" + maxLen + ") < " + 0);
|
||||
|
@ -411,4 +411,22 @@ public class ByteInput {
|
||||
throw new EndOfInput(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to <i>n</i> bytes and constructs a string.
|
||||
*
|
||||
* @param maxLen maximum number of characters to read
|
||||
* @param nullTerminated {@code true} to stop reading at {@code '\0'}
|
||||
*/
|
||||
public String readString(int maxLen, boolean nullTerminated) {
|
||||
assert aligned() : "not aligned";
|
||||
if (!nullTerminated) return readString(maxLen);
|
||||
try {
|
||||
final String string = unalign().readString(maxLen, Byte.SIZE, true);
|
||||
assert aligned() : "not aligned";
|
||||
return string;
|
||||
} catch (IndexOutOfBoundsException t) {
|
||||
throw new EndOfInput(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user