This commit is contained in:
Redkale
2016-09-14 14:41:30 +08:00
parent 77c2f72b42
commit 4cdc1f82c5

View File

@@ -659,4 +659,19 @@ public final class Utility {
public static byte[] readBytes(InputStream in) throws IOException {
return readStream(in).toByteArray();
}
public static ByteArrayOutputStream readStreamThenClose(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] bytes = new byte[1024];
int pos;
while ((pos = in.read(bytes)) != -1) {
out.write(bytes, 0, pos);
}
in.close();
return out;
}
public static byte[] readBytesThenClose(InputStream in) throws IOException {
return readStreamThenClose(in).toByteArray();
}
}