byte[] (InputStream stream) { byte[] buf = myBuffer; if (buf == null) { buf = new byte[512]; myBuffer = buf; } final ByteArrayOutputStream result = new ByteArrayOutputStream(); try { while (true) { int n = stream.read(buf, 0, buf.length); if (n <= 0) { break; } result.write(buf, 0, n); } result.close(); } catch (IOException ignored) { } return result.toByteArray(); }