add byte arrays to TypesStreams
This commit is contained in:
parent
f3508cb27f
commit
fb459defea
2 changed files with 19 additions and 0 deletions
|
@ -116,6 +116,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();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
|
|
@ -119,6 +119,13 @@ public class TypedOutputStream {
|
|||
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();
|
||||
writeInt(i);
|
||||
|
|
Loading…
Add table
Reference in a new issue