public static BytesArray asBytes(BytesArray ba, InputStream in) throws IOException { BytesArray buf = unwrapStreamBuffer(in); if (buf != null) { ba.bytes(buf); return ba; } FastByteArrayOutputStream bos = new FastByteArrayOutputStream(ba); byte[] buffer = new byte[1024]; int read = 0; try { while ((read = in.read(buffer)) != -1) { bos.write(buffer, 0, read); } } finally { try { in.close(); } catch (IOException ex) { // ignore } // non needed but used to avoid the warnings bos.close(); } return bos.bytes(); }
public static BytesArray asBytes(BytesArray ba, InputStream in) throws IOException { BytesArray buf = unwrapStreamBuffer(in); if (buf != null) { ba.bytes(buf); return ba; } FastByteArrayOutputStream bos = new FastByteArrayOutputStream(ba); byte[] buffer = new byte[1024]; int read = 0; try { while ((read = in.read(buffer)) != -1) { bos.write(buffer, 0, read); } } finally { try { in.close(); } catch (IOException ex) { // ignore } // non needed but used to avoid the warnings bos.close(); } return bos.bytes(); }
public static BytesArray asBytes(BytesArray ba, InputStream in) throws IOException { BytesArray buf = unwrapStreamBuffer(in); if (buf != null) { ba.bytes(buf); return ba; } FastByteArrayOutputStream bos = new FastByteArrayOutputStream(ba); byte[] buffer = new byte[1024]; int read = 0; try { while ((read = in.read(buffer)) != -1) { bos.write(buffer, 0, read); } } finally { try { in.close(); } catch (IOException ex) { // ignore } // non needed but used to avoid the warnings bos.close(); } return bos.bytes(); }
public static BytesArray asBytes(BytesArray ba, InputStream in) throws IOException { BytesArray buf = unwrapStreamBuffer(in); if (buf != null) { ba.bytes(buf); return ba; } FastByteArrayOutputStream bos = new FastByteArrayOutputStream(ba); byte[] buffer = new byte[1024]; int read = 0; try { while ((read = in.read(buffer)) != -1) { bos.write(buffer, 0, read); } } finally { try { in.close(); } catch (IOException ex) { // ignore } // non needed but used to avoid the warnings bos.close(); } return bos.bytes(); }
public static BytesArray asBytes(BytesArray ba, InputStream in) throws IOException { BytesArray buf = unwrapStreamBuffer(in); if (buf != null) { ba.bytes(buf); return ba; } FastByteArrayOutputStream bos = new FastByteArrayOutputStream(ba); byte[] buffer = new byte[1024]; int read = 0; try { while ((read = in.read(buffer)) != -1) { bos.write(buffer, 0, read); } } finally { try { in.close(); } catch (IOException ex) { // ignore } // non needed but used to avoid the warnings bos.close(); } return bos.bytes(); }