Example usage for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM

List of usage examples for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM

Introduction

In this page you can find the example usage for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM.

Prototype

ContentType APPLICATION_OCTET_STREAM

To view the source code for org.apache.http.entity ContentType APPLICATION_OCTET_STREAM.

Click Source Link

Usage

From source file:com.ibm.ws.lars.rest.BaseUrlTest.java

@Test
public void testBaseUrl() throws Exception {
    Asset testAsset = AssetUtils.getTestAsset();
    Asset returnedAsset = baseUrlRepo.addAssetNoAttachments(testAsset);

    Attachment attachmentWithContent = AssetUtils.getTestAttachmentWithContent();

    String attachmentName = "attachment.txt";
    byte[] content = "This is the content.\nIt is quite short.".getBytes("UTF-8");

    Attachment createdAttachment = baseUrlRepo.doPostAttachmentWithContent(returnedAsset.get_id(),
            attachmentName, attachmentWithContent, content, ContentType.APPLICATION_OCTET_STREAM);

    String expectedUrl = "http://example.com/test" + FatUtils.LARS_APPLICATION_ROOT + "/assets/"
            + returnedAsset.get_id() + "/attachments/" + createdAttachment.get_id() + "/" + attachmentName;

    assertEquals("Created attachment URL is not correct", expectedUrl, createdAttachment.getUrl());

    Attachment returnedAttachment = baseUrlRepo.doGetOnlyAttachment(returnedAsset.get_id(),
            createdAttachment.get_id());

    assertEquals("Fetched attachment URL is not correct", expectedUrl, returnedAttachment.getUrl());

}

From source file:org.camunda.bpm.ext.sdk.DeploymentBuilder.java

public DeploymentBuilder classPathResource(String classpathResource) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
        cl = CamundaClient.class.getClassLoader();
    }//from   www. j  av a  2 s  .  c om
    InputStream inputStream = cl.getResourceAsStream(classpathResource);

    String filename = classpathResource;
    requestBuilder.addBinaryBody("resource-" + (++dataPartConter), inputStream,
            ContentType.APPLICATION_OCTET_STREAM, filename);
    return this;
}

From source file:erainformatica.utility.JSONHelper.java

public static TelegramRequestResult<JSONObject> readJsonFromUrl(String url, InputFile file) {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost uploadFile = new HttpPost(url);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    //builder.addTextBody("field1", "yes", ContentType.TEXT_PLAIN);
    builder.addBinaryBody(file.getName(), file.getFile_content(), ContentType.APPLICATION_OCTET_STREAM,
            file.getName() + "." + file.getExtension());
    HttpEntity multipart = builder.build();

    uploadFile.setEntity(multipart);/* ww w . j a va 2s. c om*/

    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(uploadFile);
    } catch (IOException ex) {
        Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    HttpEntity responseEntity = response.getEntity();

    try {
        return readJsonFromInputStream(responseEntity.getContent());
    } catch (Exception ex) {
        return new TelegramRequestResult<>(false, ex.toString(), null);
    }

}

From source file:org.camunda.bpm.ext.sdk.DeploymentBuilder.java

public DeploymentBuilder stringResource(String filename, String content) {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
    requestBuilder.addBinaryBody("resource-" + (++dataPartConter), inputStream,
            ContentType.APPLICATION_OCTET_STREAM, filename);
    return this;
}

From source file:gmusic.api.api.comm.FormBuilder.java

public final void addFile(final String name, final String fileName, final byte[] file) throws IOException {
    final StringBuilder sb = new StringBuilder();

    sb.append(String.format("\r\n--%1$s\r\n", boundary));
    sb.append(/*from  ww  w  . java 2 s. co m*/
            String.format(HttpHeaders.CONTENT_DISPOSITION + ": form-data; name=\"%1$s\"; filename=\"%2$s\"\r\n",
                    name, fileName));

    sb.append(String.format(HttpHeaders.CONTENT_TYPE + ": %1$s\r\n\r\n", ContentType.APPLICATION_OCTET_STREAM));

    outputStream.write(sb.toString().getBytes());
    outputStream.write(file, 0, file.length);
}

From source file:org.apache.hyracks.tests.integration.ApplicationDeploymentAPIIntegrationTest.java

protected void deployApplicationFile(int dataSize, String fileName) throws URISyntaxException, IOException {
    final String deployid = "testApp";

    String path = "/applications/" + deployid + "&" + fileName;
    URI uri = uri(path);/*from  w  ww .j ava 2 s .  c  o  m*/

    byte[] data = new byte[dataSize];
    for (int i = 0; i < data.length; ++i) {
        data[i] = (byte) i;
    }

    HttpClient client = HttpClients.createMinimal();

    // Put the data

    HttpPut put = new HttpPut(uri);
    HttpEntity entity = new ByteArrayEntity(data, ContentType.APPLICATION_OCTET_STREAM);
    put.setEntity(entity);
    client.execute(put);

    // Get it back

    HttpGet get = new HttpGet(uri);
    HttpResponse response = client.execute(get);
    HttpEntity respEntity = response.getEntity();
    Header contentType = respEntity.getContentType();

    // compare results

    Assert.assertEquals(ContentType.APPLICATION_OCTET_STREAM.getMimeType(), contentType.getValue());
    InputStream is = respEntity.getContent();

    for (int i = 0; i < dataSize; ++i) {
        Assert.assertEquals(data[i], (byte) is.read());
    }
    Assert.assertEquals(-1, is.read());
    is.close();
}

From source file:com.movilizer.mds.webservice.models.MovilizerUploadForm.java

/**
 * Create an HTTP multipart form to perform a request.
 *
 * @param file with the document to be uploaded.
 * @param systemId of Movilizer Cloud.// w  w w.  j  av  a 2 s  .c  o m
 * @param password for the system id.
 * @param pool to store the document at.
 * @param key to find the document in the pool.
 * @param lang of the document.
 * @param suffix ending of the document (".zip" for HTML5 apps).
 * @param ack value that the cloud will return to you when the document is uploaded.
 * @return HttpEntity to be used in the request.
 */
public HttpEntity getForm(File file, long systemId, String password, String pool, String key, String lang,
        String suffix, String ack) {
    MultipartEntityBuilder form = getForm(systemId, password, pool, key, lang, suffix, ack);
    form.addBinaryBody("file", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
    return form.build();
}

From source file:com.threatconnect.sdk.client.reader.AbstractReaderAdapter.java

protected InputStream getFile(String propName, String ownerName, Map<String, Object> paramMap)
        throws IOException {
    return getFile(propName, ownerName, paramMap, false, ContentType.APPLICATION_OCTET_STREAM);
}

From source file:co.com.soinsoftware.altablero.utils.HttpRequest.java

@Override
public Object handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
    int status = response.getStatusLine().getStatusCode();
    if (status >= 200 && status < 300) {
        HttpEntity entity = response.getEntity();
        final ContentType contentType = ContentType.getOrDefault(entity);
        if (contentType.getMimeType().equals(ContentType.APPLICATION_OCTET_STREAM.getMimeType())) {
            InputStream inputStream = null;
            byte[] zipInBytes = EntityUtils.toByteArray(entity);
            if (zipInBytes != null) {
                inputStream = new ByteArrayInputStream(zipInBytes);
            }//from   ww  w. j  av  a2  s.c  o  m
            return inputStream;
        }
        return entity != null ? EntityUtils.toString(entity) : null;
    } else {
        throw new ClientProtocolException(EXCEPTION_MESSAGE + status);
    }
}