add byte arrays to TypesStreams
This commit is contained in:
parent
f3508cb27f
commit
fb459defea
2 changed files with 19 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue