List of usage examples for org.apache.http.entity ByteArrayEntity ByteArrayEntity
public ByteArrayEntity(byte[] bArr, int i, int i2)
From source file:com.jaeksoft.searchlib.util.array.BytesOutputStream.java
final public HttpEntity getHttpEntity() { return new ByteArrayEntity(buf, 0, size()); }
From source file:co.cask.cdap.client.rest.RestStreamWriter.java
@Override public ListenableFuture<Void> write(ByteBuffer buffer, Map<String, String> headers) throws IllegalArgumentException { Preconditions.checkArgument(buffer != null, "ByteBuffer parameter is null."); HttpEntity content;/*from www.j a va 2 s . com*/ if (buffer.hasArray()) { content = new ByteArrayEntity(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes); content = new ByteArrayEntity(bytes); } return write(content, headers); }
From source file:org.apache.solr.handler.TestBlobHandler.java
public static void postData(CloudSolrClient cloudClient, String baseUrl, String blobName, ByteBuffer bytarr) throws IOException { HttpPost httpPost = null;//from w w w . j a v a2 s . co m HttpEntity entity; String response = null; try { httpPost = new HttpPost(baseUrl + "/.system/blob/" + blobName); httpPost.setHeader("Content-Type", "application/octet-stream"); httpPost.setEntity(new ByteArrayEntity(bytarr.array(), bytarr.arrayOffset(), bytarr.limit())); entity = cloudClient.getLbClient().getHttpClient().execute(httpPost).getEntity(); try { response = EntityUtils.toString(entity, StandardCharsets.UTF_8); Map m = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response))); assertFalse("Error in posting blob " + getAsString(m), m.containsKey("error")); } catch (JSONParser.ParseException e) { log.error("$ERROR$", response, e); fail(); } } finally { httpPost.releaseConnection(); } }