diff --git a/core/src/com/riiablo/io/BitInput.java b/core/src/com/riiablo/io/BitInput.java
index 621c086a..70da63cd 100644
--- a/core/src/com/riiablo/io/BitInput.java
+++ b/core/src/com/riiablo/io/BitInput.java
@@ -478,12 +478,12 @@ public class BitInput {
}
/**
- * Reads n characters of size {@code bits} and constructs a string.
+ * Reads up to n 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);
diff --git a/core/src/com/riiablo/io/ByteInput.java b/core/src/com/riiablo/io/ByteInput.java
index bc3a8079..085e0392 100644
--- a/core/src/com/riiablo/io/ByteInput.java
+++ b/core/src/com/riiablo/io/ByteInput.java
@@ -411,4 +411,22 @@ public class ByteInput {
throw new EndOfInput(t);
}
}
+
+ /**
+ * Reads up to n 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);
+ }
+ }
}