List of usage examples for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM
ContentType APPLICATION_OCTET_STREAM
To view the source code for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM.
Click Source Link
From source file:com.google.devtools.build.lib.remote.blobstore.RestBlobStore.java
@Override public void put(String key, long length, InputStream in) throws IOException { put(CAS_PREFIX, key, new InputStreamEntity(in, length, ContentType.APPLICATION_OCTET_STREAM)); }
From source file:org.apache.sling.replication.servlet.ReplicationAgentServlet.java
private void doRemove(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType(ContentType.APPLICATION_OCTET_STREAM.toString()); String queueName = request.getParameter(ReplicationHeader.QUEUE.toString()); ReplicationAgent agent = request.getResource().adaptTo(ReplicationAgent.class); /* directly polling an agent queue is only possible if such an agent doesn't have its own endpoint (that is it just adds items to its queue to be polled remotely)*/ if (agent != null) { try {/*from ww w . jav a 2 s. c o m*/ // TODO : consider using queue distribution strategy and validating who's making this request log.info("getting item from queue {}", queueName); // get first item ReplicationPackage head = agent.removeHead(queueName); if (head != null) { InputStream inputStream = null; int bytesCopied = -1; try { inputStream = head.createInputStream(); bytesCopied = IOUtils.copy(inputStream, response.getOutputStream()); } finally { IOUtils.closeQuietly(inputStream); } setPackageHeaders(response, head); // delete the package permanently head.delete(); log.info("{} bytes written into the response", bytesCopied); } else { log.info("nothing to fetch"); } } catch (Exception e) { response.setStatus(503); log.error("error while reverse replicating from agent", e); } // everything ok response.setStatus(200); } else { response.setStatus(404); } }
From source file:net.ychron.unirestinst.request.HttpRequestWithBody.java
public MultipartBody field(String name, InputStream stream, String fileName) { MultipartBody body = field(name, stream, ContentType.APPLICATION_OCTET_STREAM, fileName); this.body = body; return body;/*from ww w . j av a 2 s.c om*/ }
From source file:com.threatconnect.sdk.conn.HttpRequestExecutor.java
/** * Execute an HTTP request and return the raw input stream. <i>Caller is responsible for closing InputStream.</i> * * @param path url to issue request to/*from ww w .j a va 2 s .co m*/ * @return raw input stream from response * @throws IOException On error */ @Override public InputStream executeDownloadByteStream(String path) throws IOException { if (this.conn.getConfig() == null) { throw new IllegalStateException("Can't execute HTTP request when configuration is undefined."); } InputStream stream = null; String fullPath = this.conn.getConfig().getTcApiUrl() + path.replace("/api/", "/"); logger.trace("Calling GET: " + fullPath); HttpRequestBase httpBase = getBase(fullPath, HttpMethod.GET); String headerPath = httpBase.getURI().getRawPath() + "?" + httpBase.getURI().getRawQuery(); ConnectionUtil.applyHeaders(this.conn.getConfig(), httpBase, httpBase.getMethod(), headerPath, conn.getConfig().getContentType(), ContentType.APPLICATION_OCTET_STREAM.toString()); logger.trace("Request: " + httpBase.getRequestLine()); logger.trace("Headers: " + Arrays.toString(httpBase.getAllHeaders())); CloseableHttpResponse response = this.conn.getApiClient().execute(httpBase); logger.trace(response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); if (entity != null) { stream = entity.getContent(); logger.trace(String.format("Result stream size: %d, encoding: %s", entity.getContentLength(), entity.getContentEncoding())); } return stream; }
From source file:com.jivesoftware.jivesdk.impl.auth.jiveauth.JiveSignatureValidatorImpl.java
@Nonnull private RestPostRequest createValidationPostRequest(@Nonnull InstanceRegistrationRequest request) throws NoSuchAlgorithmException { Map<String, String> headers = Maps.newHashMap(); headers.put("X-Jive-MAC", request.getJiveSignature()); headers.put(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString()); String body = createSignatureValidationRequest(request); return RestRequestFactory.createPostRequestBuilder(request.getJiveSignatureURL()).withHeaders(headers) .withEntity(new StringEntity(body, ContentType.APPLICATION_OCTET_STREAM)); }
From source file:com.google.devtools.build.lib.remote.blobstore.RestBlobStore.java
@Override public void putActionResult(String key, byte[] in) throws IOException, InterruptedException { put(ACTION_CACHE_PREFIX, key, new ByteArrayEntity(in, ContentType.APPLICATION_OCTET_STREAM)); }
From source file:org.eclipse.jgit.lfs.server.fs.LfsServerTest.java
protected AnyLongObjectId putContent(AnyLongObjectId id, String s) throws ClientProtocolException, IOException { try (CloseableHttpClient client = HttpClientBuilder.create().build()) { HttpEntity entity = new StringEntity(s, ContentType.APPLICATION_OCTET_STREAM); String hexId = id.name(); HttpPut request = new HttpPut(server.getURI() + "/lfs/objects/" + hexId); request.setEntity(entity);/*w w w . j a v a2 s .c o m*/ try (CloseableHttpResponse response = client.execute(request)) { StatusLine statusLine = response.getStatusLine(); int status = statusLine.getStatusCode(); if (status >= 400) { throw new RuntimeException("Status: " + status + ". " + statusLine.getReasonPhrase()); } } return id; } }
From source file:net.ychron.unirestinst.request.body.MultipartBody.java
public MultipartBody field(String name, byte[] bytes, String fileName) { return field(name, new ByteArrayBody(bytes, ContentType.APPLICATION_OCTET_STREAM, fileName), true, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); }