mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-03-05 23:20:32 +07:00
Created ByteOutput#writeString(CharSequence,int)
writeString writes a string and either truncates or pads it with zeros to len
This commit is contained in:
parent
8506cc4324
commit
8c3c304dcd
@ -114,4 +114,15 @@ public class ByteOutput {
|
||||
buffer.writeCharSequence(chars, CharsetUtil.US_ASCII);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOutput writeString(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));
|
||||
} else {
|
||||
return writeString(chars).skipBytes(len - charsLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user