add byte arrays to TypesStreams

This commit is contained in:
Daniella / Tove 2024-06-09 22:01:40 +02:00
parent f3508cb27f
commit fb459defea
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 19 additions and 0 deletions

View file

@ -115,6 +115,18 @@ public class TypedInputStream {
}
return booleans;
}
public byte[] readByteArray() throws IOException {
byte[] bytes = new byte[readInt()];
int n = 0;
while ((n += stream.read(bytes, n, bytes.length - n)) != 0);
if(n != bytes.length) {
byte[] cutBytes = new byte[n];
System.arraycopy(bytes, 0, cutBytes, 0, n);
return cutBytes;
}
return bytes;
}
public String readString() throws IOException {
int i = readInt();

View file

@ -118,6 +118,13 @@ public class TypedOutputStream {
stream.flush();
return booleans;
}
public byte[] writeByteArray(byte[] bytes) throws IOException {
int i = bytes.length;
writeInt(i);
stream.write(bytes);
return bytes;
}
public String writeString(String string) throws IOException {
int i = string.length();