List of usage examples for java.io ByteArrayOutputStream write
public synchronized void write(byte b[], int off, int len)
From source file:com.crosstreelabs.junited.elasticsearch.ElasticsearchRule.java
protected static byte[] toByteArray(final InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int length = 0; byte[] buf = new byte[256]; while ((length = is.read(buf)) > 0) { baos.write(buf, 0, length); }//ww w . ja va 2s . c o m return baos.toByteArray(); }
From source file:org.surveydroid.android.coms.WebClient.java
private static String getInputStreamAsString(Context ctxt, InputStream is) { byte[] sBuffer = new byte[512]; ByteArrayOutputStream content = new ByteArrayOutputStream(); // Read response into a buffered stream int readBytes = 0; try {// ww w . ja va 2 s . c om while ((readBytes = is.read(sBuffer)) != -1) { content.write(sBuffer, 0, readBytes); } } catch (IOException e) { Util.e(null, TAG, Util.fmt(e)); } return new String(content.toByteArray()); }
From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java
private static byte[] readFullInputStream(final InputStream in) throws IOException { final byte[] buffer = new byte[16384]; final ByteArrayOutputStream result = new ByteArrayOutputStream(16384); while (true) { final int read = in.read(buffer); if (read < 0) { break; }/*from w ww .j av a 2 s.co m*/ result.write(buffer, 0, read); } return result.toByteArray(); }
From source file:com.jrummyapps.busybox.utils.Utils.java
/** * Get a list of binaries in the assets directory * * @return a list of binaries from the assets in this APK file. *//* www.jav a2 s. c o m*/ public static ArrayList<BinaryInfo> getBinariesFromAssets() { ArrayList<BinaryInfo> binaries = new ArrayList<>(); try { ByteArrayOutputStream output = new ByteArrayOutputStream(); InputStream input = getContext().getResources().openRawResource(R.raw.binaries); byte[] buffer = new byte[4096]; int n; while ((n = input.read(buffer)) != -1) { output.write(buffer, 0, n); } input.close(); JSONArray jsonArray = new JSONArray(output.toString()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String name = jsonObject.getString("name"); String filename = jsonObject.getString("filename"); String abi = jsonObject.getString("abi"); String flavor = jsonObject.getString("flavor"); String url = jsonObject.getString("url"); String md5sum = jsonObject.getString("md5sum"); long size = jsonObject.getLong("size"); binaries.add(new BinaryInfo(name, filename, abi, flavor, url, md5sum, size)); } } catch (Exception e) { Crashlytics.logException(e); } return binaries; }
From source file:id.nci.stm_9.HkpKeyServer.java
static private String readAll(InputStream in, String encoding) throws IOException { ByteArrayOutputStream raw = new ByteArrayOutputStream(); byte buffer[] = new byte[1 << 16]; int n = 0;/* ww w . j a v a 2 s . c o m*/ while ((n = in.read(buffer)) != -1) { raw.write(buffer, 0, n); } if (encoding == null) { encoding = "utf8"; } return raw.toString(encoding); }