Skip to content

Commit

Permalink
Effectively renamed #writeString methods to #writeChars (see #136)
Browse files Browse the repository at this point in the history
  • Loading branch information
collinsmith committed Dec 13, 2020
1 parent 7b8ea95 commit eec17d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions core/src/main/java/com/riiablo/io/ByteOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,36 @@ public ByteOutput writeBytes(byte[] src, int srcOffset, int len) {
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!");
// }
}
2 changes: 1 addition & 1 deletion core/src/main/java/com/riiablo/save/D2SWriter96.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void writeHeader(D2S d2s, ByteOutput out) {
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);
}
Expand Down

0 comments on commit eec17d0

Please sign in to comment.