Effectively renamed #writeString methods to #writeChars (see #136)

This commit is contained in:
Collin Smith 2020-12-12 17:38:49 -08:00
parent 7b8ea9511b
commit eec17d0a01
2 changed files with 20 additions and 5 deletions

View File

@ -112,21 +112,36 @@ public class ByteOutput {
return this;
}
public ByteOutput writeString(CharSequence chars) {
// TODO: create readChars int com.riiablo.io.BitInput
// Chars methods for explicit chars
// String methods for implicit null-termination
public ByteOutput writeChars(CharSequence chars) {
assert aligned() : "not aligned";
incrementBitsWritten((long) chars.length() * Byte.SIZE);
buffer.writeCharSequence(chars, CharsetUtil.US_ASCII);
return this;
}
public ByteOutput writeString(CharSequence chars, int len) {
public ByteOutput writeChars(CharSequence chars, int len) {
if (len < 0) throw new IllegalArgumentException("len(" + len + ") < " + 0);
assert aligned() : "not aligned";
final int charsLength = chars.length();
if (len <= charsLength) {
return writeString(chars.subSequence(0, len));
return writeChars(chars.subSequence(0, len));
} else {
return writeString(chars).skipBytes(len - charsLength);
return writeChars(chars).skipBytes(len - charsLength);
}
}
public ByteOutput writeString(CharSequence chars) {
return writeChars(chars).skipBytes(1);
}
/**
* @deprecated until fixed and null termination
*/
// @Deprecated
// public ByteOutput writeString(CharSequence chars, int len) {
// throw new UnsupportedOperationException("Not supported yet!");
// }
}

View File

@ -23,7 +23,7 @@ public class D2SWriter96 {
out.write32(d2s.size);
out.write32(d2s.checksum);
out.write32(d2s.alternate);
out.writeString(d2s.name, Riiablo.MAX_NAME_LENGTH + 1);
out.writeChars(d2s.name, Riiablo.MAX_NAME_LENGTH + 1);
out.write32(d2s.flags);
out.write8(d2s.charClass);
}