URL url = new URL(DownloadUrl); //you can write here any link File file = new File(dir, fileName); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(5000); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.flush(); fos.close(); Log.d("DownloadManager", "download ready in" + ((System.currentTimeMillis() - startTime) / 1000) + " sec");
throw new IllegalArgumentException("Char array buffer may not be null"); this.linebuffer.clear(); int noRead = 0; boolean retry = true; if (i != -1) { if (this.linebuffer.isEmpty()) { this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = i + 1; } else { this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = this.bufferlen; if (this.maxLineLen > 0 && this.linebuffer.length() >= this.maxLineLen) { throw new IOException("Maximum line length limit exceeded"); if (noRead == -1 && this.linebuffer.isEmpty()) {
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());
HttpEntity entity = response.getEntity(); if (entity != null) { URL url = new URL(result.getExtra()); String fileName = url.getFile(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); ByteArrayBuffer buffer = new ByteArrayBuffer(50); int current = 0; while ((current = bufferedInputStream.read()) != -1) { buffer.append((byte) current); FileOutputStream stream = new FileOutputStream(tempFile); stream.write(buffer.toByteArray()); stream.close();
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(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));
URL url = new URL(imgBaseUrl + ss.getString("foto")); URLConnection connection = url.openConnection(); FlushedInputStream fis = new FlushedInputStream(connection.getInputStream()); ByteArrayBuffer baf = new ByteArrayBuffer(100); int current = 0; while((current = fis.read()) != -1){ baf.append((byte)current); } fis.close(); holder.resim.setImageBitmap(BitmapFactory.decodeByteArray(baf, 0, baf.length()));
ByteArrayBuffer myBABuffer = new ByteArrayBuffer(50); int current = 0; while ((current = myBis.read()) != -1) { myBABuffer.append((byte) current); } FileOutputStream fos = new FileOutputStream(imgFile);
Args.notNull(charbuffer, "Char array buffer"); int noRead = 0; boolean retry = true; if (i != -1) { if (this.linebuffer.isEmpty()) { this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = i + 1; } else { this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = this.bufferlen; if (this.maxLineLen > 0 && this.linebuffer.length() >= this.maxLineLen) { throw new IOException("Maximum line length limit exceeded"); if (noRead == -1 && this.linebuffer.isEmpty()) {
protected AbstractSessionOutputBuffer( final OutputStream outstream, final int buffersize, final Charset charset, final int minChunkLimit, final CodingErrorAction malformedCharAction, final CodingErrorAction unmappableCharAction) { super(); Args.notNull(outstream, "Input stream"); Args.notNegative(buffersize, "Buffer size"); this.outstream = outstream; this.buffer = new ByteArrayBuffer(buffersize); this.charset = charset != null ? charset : Consts.ASCII; this.ascii = this.charset.equals(Consts.ASCII); this.encoder = null; this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512; this.metrics = createTransportMetrics(); this.onMalformedCharAction = malformedCharAction != null ? malformedCharAction : CodingErrorAction.REPORT; this.onUnmappableCharAction = unmappableCharAction != null? unmappableCharAction : CodingErrorAction.REPORT; }
ByteArrayBuffer buffer = new ByteArrayBuffer(readBufferLength); if (maxBytes > 0 && (buffer.length() + dataLength) > maxBytes) { truncated = true; dataLength = maxBytes - buffer.length(); buffer.append(tmpBuff, 0, dataLength); if (truncated) { break; return buffer.toByteArray();
throws IOException { int len = this.linebuffer.length(); if (len > 0) { if (this.linebuffer.byteAt(len - 1) == HTTP.LF) { len--; if (this.linebuffer.byteAt(len - 1) == HTTP.CR) { len--; charbuffer.append(this.linebuffer, 0, len); } else { final ByteBuffer bbuf = ByteBuffer.wrap(this.linebuffer.buffer(), 0, len); len = appendDecoded(charbuffer, bbuf); this.linebuffer.clear(); return len;
/** * Creates new instance of SessionOutputBufferImpl. * * @param metrics HTTP transport metrics. * @param buffersize buffer size. Must be a positive number. * @param fragementSizeHint fragment size hint defining a minimal size of a fragment * that should be written out directly to the socket bypassing the session buffer. * Value {@code 0} disables fragment buffering. * @param charencoder charencoder to be used for encoding HTTP protocol elements. * If {@code null} simple type cast will be used for char to byte conversion. */ public SessionOutputBufferImpl( final HttpTransportMetricsImpl metrics, final int buffersize, final int fragementSizeHint, final CharsetEncoder charencoder) { super(); Args.positive(buffersize, "Buffer size"); Args.notNull(metrics, "HTTP transport metrcis"); this.metrics = metrics; this.buffer = new ByteArrayBuffer(buffersize); this.fragementSizeHint = fragementSizeHint >= 0 ? fragementSizeHint : 0; this.encoder = charencoder; }
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(); }
private int lineFromLineBuffer(final CharArrayBuffer charbuffer) throws IOException { // discard LF if found int l = this.linebuffer.length(); if (l > 0) { if (this.linebuffer.byteAt(l - 1) == HTTP.LF) { l--; this.linebuffer.setLength(l); } // discard CR if found if (l > 0) { if (this.linebuffer.byteAt(l - 1) == HTTP.CR) { l--; this.linebuffer.setLength(l); } } } l = this.linebuffer.length(); if (this.ascii) { charbuffer.append(this.linebuffer, 0, l); } else { // This is VERY memory inefficient, BUT since non-ASCII charsets are // NOT meant to be used anyway, there's no point optimizing it String s = new String(this.linebuffer.buffer(), 0, l, this.charset); charbuffer.append(s); } return l; }
public void writeLine(final CharArrayBuffer s) throws IOException { if (s == null) { return; } if (this.ascii) { int off = 0; int remaining = s.length(); while (remaining > 0) { int chunk = this.buffer.capacity() - this.buffer.length(); chunk = Math.min(chunk, remaining); if (chunk > 0) { this.buffer.append(s, off, chunk); } if (this.buffer.isFull()) { flushBuffer(); } off += chunk; remaining -= chunk; } } else { // This is VERY memory inefficient, BUT since non-ASCII charsets are // NOT meant to be used anyway, there's no point optimizing it byte[] tmp = s.toString().getBytes(this.charset); write(tmp); } write(CRLF); }
byte[] readBytes ; // Your byte array .... //for eg. readBytes = "TestBytes".getBytes(); ByteArrayBuffer mReadBuffer = new ByteArrayBuffer(0 ) ; // Instead of 0, if you know the count of expected number of bytes, nice to input here mReadBuffer.append(readBytes, 0, readBytes.length); // this copies all bytes from readBytes byte array into mReadBuffer // Any new entry of readBytes, you can just append here by repeating the same call. // Finally, if you want the result into byte[] form: byte[] result = mReadBuffer.buffer();