List of usage examples for org.apache.http.util ByteArrayBuffer ByteArrayBuffer
public ByteArrayBuffer(int i)
From source file:Main.java
public static byte[] hexToBytes(String hex) { ByteArrayBuffer bytes = new ByteArrayBuffer(hex.length() / 2); for (int i = 0; i < hex.length(); i++) { if (hex.charAt(i) == ' ') { continue; }// w w w. jav a 2 s . c o m String hexByte; if (i + 1 < hex.length()) { hexByte = hex.substring(i, i + 2).trim(); i++; } else { hexByte = hex.substring(i, i + 1); } bytes.append(Integer.parseInt(hexByte, 16)); } return bytes.buffer(); }
From source file:Main.java
public static byte[] downloadImage(String imageUrl) { if (imageUrl.endsWith(".jpg") || imageUrl.endsWith(".bmp") || imageUrl.endsWith(".png") || imageUrl.endsWith(".gif")) { try {// ww w.j a va 2 s . c om URL url = new URL(imageUrl); URLConnection urlConn = url.openConnection(); InputStream is = urlConn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } return baf.toByteArray(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:com.digitallizard.bbcnewsreader.resource.web.ImageDownloader.java
public static byte[] getImage(URL url) throws Exception { URLConnection connection = url.openConnection(); InputStream stream = connection.getInputStream(); BufferedInputStream inputbuffer = new BufferedInputStream(stream, 8000); ByteArrayBuffer arraybuffer = new ByteArrayBuffer(50); int current = 0; while ((current = inputbuffer.read()) != -1) { arraybuffer.append((byte) current); }// w ww .j ava2s. co m byte[] image = arraybuffer.toByteArray(); return image; }
From source file:com.digitallizard.bbcnewsreader.resource.web.HtmlParser.java
/** * @param args// w w w . j a v a 2 s . c o m * @throws IOException * @throws ClientProtocolException */ public static byte[] getPage(String stringUrl) throws Exception { URL url = new URL(stringUrl); URLConnection connection = url.openConnection(); InputStream stream = connection.getInputStream(); BufferedInputStream inputbuffer = new BufferedInputStream(stream); ByteArrayBuffer arraybuffer = new ByteArrayBuffer(50); int current = 0; while ((current = inputbuffer.read()) != -1) { arraybuffer.append((byte) current); } return arraybuffer.toByteArray(); }
From source file:com.net.plus.common.Utils.Util.java
public static byte[] toByteArray(HttpEntity entity) { InputStream instream = null;/*from w ww .j av a 2 s. c o m*/ byte[] ret = null; try { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } instream = entity.getContent(); if (instream == null) { return null; } int i = (int) entity.getContentLength(); if (i < 0) { i = 4096; } ByteArrayBuffer buffer = new ByteArrayBuffer(i); byte tmp[] = new byte[4096]; int l; while ((l = instream.read(tmp)) != -1) { buffer.append(tmp, 0, l); } ret = buffer.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (instream != null) { instream.close(); } } catch (IOException e) { } } return ret; }
From source file:com.mondospider.android.lib.LibHTTP.java
public static String get(String url) { String ReturnHTML = ""; // Log.d("LibHTTP->get->url",url); try {//from w w w . ja v a 2s.c o m URLConnection urlConn = new URL(url).openConnection(); InputStream is = urlConn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, 16000); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } ReturnHTML = new String(baf.toByteArray()); } catch (Exception e) { ReturnHTML = e.getMessage(); } // Log.d("LibHTTP->get->ReturnHTML", ReturnHTML); return ReturnHTML; }
From source file:com.shopgun.android.sdk.network.impl.NetworkImpl.java
private static byte[] entityToBytes(HttpEntity entity) throws IllegalStateException, IOException { // Find best buffer size int init_buf = 0 <= entity.getContentLength() ? (int) entity.getContentLength() : BUFFER_SIZE; ByteArrayBuffer bytes = new ByteArrayBuffer(init_buf); InputStream is = entity.getContent(); if (is == null) return bytes.toByteArray(); byte[] buf = new byte[init_buf]; int c = -1;/* www . ja va2 s .c om*/ while ((c = is.read(buf)) != -1) { bytes.append(buf, 0, c); } return bytes.toByteArray(); }
From source file:android.wulongdao.thirdparty.mime.HttpMultipart.java
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;/*from w ww . j a va2 s. co m*/ }
From source file:org.simalliance.openmobileapi.service.security.AccessControlDB.java
public byte[] readAPCertificate() throws AccessControlException, CardException { ByteArrayBuffer bytes = new ByteArrayBuffer(1024); ByteArrayBuffer buffer = new ByteArrayBuffer(256); int offset = 0; int length = 0; while (!mApplet.readAPCertificate(buffer, offset, length)) { if (buffer.length() == 0) { break; }/*from w ww . ja va 2s .c o m*/ offset += buffer.length(); bytes.append(buffer.toByteArray(), 0, buffer.length()); } return bytes.toByteArray(); }
From source file:com.knowledgecode.cordova.websocket.AbstractWebSocket.java
/** * Constructor */ public AbstractWebSocket() { _buffer = new ByteArrayBuffer(BUFFER_SIZE); }