AndroidAsync
AndroidAsync copied to clipboard
Problem caused by too long byte[]
It is possible to support reading byte[] of a specified length. Reading a very long byte[] now requires writing a lot of unpacking logic.Like this:
public static ByteString read(InputStream in, int byteCount) throws IOException {
if (in == null) throw new IllegalArgumentException("in == null");
if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
byte[] result = new byte[byteCount];
for (int offset = 0, read; offset < byteCount; offset += read) {
read = in.read(result, offset, byteCount - offset);
if (read == -1) throw new EOFException();
}
return new ByteString(result);
}