Refine search
BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = new FileOutputStream(file); fos.write(buffer.toByteArray());
byte[] logoImage = getLogoImage(IMAGEURL); private byte[] getLogoImage(String url){ try { URL imageUrl = new URL(url); URLConnection ucon = imageUrl.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(500); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } return baf.toByteArray(); } catch (Exception e) { Log.d("ImageManager", "Error: " + e.toString()); } return null; }
BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(bis.count); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte)current); } byte[] imageData = baf.toByteArray();
public static byte[] toByteArray(final HttpEntity entity) throws IOException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } InputStream instream = entity.getContent(); if (instream == null) { return new byte[] {}; } if (entity.getContentLength() > Integer.MAX_VALUE) { throw new IllegalArgumentException("HTTP entity too large to be buffered in memory"); } int i = (int)entity.getContentLength(); if (i < 0) { i = 4096; } ByteArrayBuffer buffer = new ByteArrayBuffer(i); try { byte[] tmp = new byte[4096]; int l; while((l = instream.read(tmp)) != -1) { buffer.append(tmp, 0, l); } } finally { instream.close(); } return buffer.toByteArray(); }
/* Open a connection to that URL. */ URLConnection ucon = url.openConnection(); ... ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); }
private class DownloadFileTask extends AsyncTask<URL, Integer, Long> { protected Long doInBackground(URL... urls) { Url url = urls[0]; //connect to url here ....... try { InputStream myInput = urlconnect.getInputStream(); BufferedInputStream buffinput = new BufferedInputStream(myInput); ByteArrayBuffer baf = new ByteArrayBuffer(capacity); int current = 0; while((current = buffinput.read()) != -1) { baf.append((byte) current); //here you can send data to onProgressUpdate publishProgress((int) (((float)baf.length()/ (float)sizefile) * 100)); } File outputfile = new File(createRepertory(app, 0), Filename); FileOutputStream myOutPut = new FileOutputStream(outputfile); myOutPut.write(baf.toByteArray()); ... } protected void onProgressUpdate(Integer... progress) { //here you can set progress bar in UI thread progressBarStatus = progress; }
private static byte[] toByteArray(final HttpEntity entity) throws IOException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } InputStream instream = entity.getContent(); if (instream == null) { return new byte[]{}; } if (entity.getContentLength() > Integer.MAX_VALUE) { throw new IllegalArgumentException("HTTP entity too large to be buffered in memory"); } int count = (int) entity.getContentLength(); if (count < 0) { count = 4096; } ByteArrayBuffer buffer = new ByteArrayBuffer(count); try { byte[] tmp = new byte[4096]; int len; while ((len = instream.read(tmp)) != -1) { buffer.append(tmp, 0, len); } } finally { instream.close(); } return buffer.toByteArray(); }
ByteArrayBuffer myBABuffer = new ByteArrayBuffer(50); int current = 0; while ((current = myBis.read()) != -1) { myBABuffer.append((byte) current); } FileOutputStream fos = new FileOutputStream(imgFile);
ByteArrayBuffer baf = new ByteArrayBuffer(5000); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); fos.write(baf.toByteArray()); fos.flush(); fos.close();
private static ByteArrayBuffer encode(final Charset charset, final String input) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(input)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); ByteArrayBuffer buffer = new ByteArrayBuffer(50); int current = 0; while ((current = bufferedInputStream.read()) != -1) { buffer.append((byte) current); stream.write(buffer.toByteArray()); stream.close();
private static ByteArrayBuffer encode( final Charset charset, final String string) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
ByteArrayBuffer buffer = new ByteArrayBuffer(readBufferLength); dataLength = maxBytes - buffer.length(); buffer.append(tmpBuff, 0, dataLength); if (truncated) { break; return buffer.toByteArray();
private static ByteArrayBuffer encode( final Charset charset, final String string) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
private byte[] getLogoImage(String url){ try { URL imageUrl = new URL(url); URLConnection ucon = imageUrl.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(500); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } return baf.toByteArray(); } catch (Exception e) { Log.d("ImageManager", "Error: " + e.toString()); return null; } }
private static ByteArrayBuffer encode( final Charset charset, final String string) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
public static byte[] getLogoImage(String url){ try { URL imageUrl = new URL(url); URLConnection ucon = imageUrl.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(500); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } return baf.toByteArray(); } catch (Exception e) { Log.d("ImageManager", "Error: " + e.toString()); } return null; }
private static ByteArrayBuffer encode( final Charset charset, final String string) { ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab; }
ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while((current = bis.read()) != -1){ baf.append((byte)current); String ret = new String(baf.toByteArray(),encoding); GlobalVars.LastError = ret; return true;
URL url = new URL("http://www.escapeguide.gr/en/rest/views/mobile_listings.json?display_id=sights_service"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); int status = connection.getResponseCode(); if (status == HttpURLConnection.HTTP_OK) { InputStream is = new BufferedInputStream(connection.getInputStream()); ByteArrayBuffer buffer = new ByteArrayBuffer(4096); int byteCount = 0; byte[] bytes = new byte[4096]; do buffer.append(bytes, 0, byteCount); while ((byteCount = is.read(bytes)) != -1); } JSONArray array = new JSONArray(new String(buffer));