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

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

Introduction

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

Prototype

ContentType DEFAULT_BINARY

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

Click Source Link

Usage

From source file:org.matmaul.freeboxos.internal.InpuStreamBody.java

public InpuStreamBody(InputStream in, long length, String filename) {
    super(in, ContentType.DEFAULT_BINARY, filename);
    this.length = length;
}

From source file:io.confluent.support.metrics.utils.WebClient.java

/**
 * Sends a POST request to a web server//  w  ww .  ja  v a  2  s  . c o  m
 * @param customerId: customer Id on behalf of which the request is sent
 * @param bytes: request payload
 * @param httpPost: A POST request structure
 * @return an HTTP Status code
 */
public static int send(String customerId, byte[] bytes, HttpPost httpPost) {
    int statusCode = DEFAULT_STATUS_CODE;
    if (bytes != null && bytes.length > 0 && httpPost != null && customerId != null) {

        // add the body to the request
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addTextBody("cid", customerId);
        builder.addBinaryBody("file", bytes, ContentType.DEFAULT_BINARY, "filename");
        httpPost.setEntity(builder.build());

        // set the HTTP config
        final RequestConfig config = RequestConfig.custom().setConnectTimeout(requestTimeoutMs)
                .setConnectionRequestTimeout(requestTimeoutMs).setSocketTimeout(requestTimeoutMs).build();

        // send request
        try (CloseableHttpClient httpclient = HttpClientBuilder.create().setDefaultRequestConfig(config)
                .build(); CloseableHttpResponse response = httpclient.execute(httpPost)) {
            log.debug("POST request returned {}", response.getStatusLine().toString());
            statusCode = response.getStatusLine().getStatusCode();
        } catch (IOException e) {
            log.debug("Could not submit metrics to Confluent: {}", e.getMessage());
        }
    } else {
        statusCode = HttpStatus.SC_BAD_REQUEST;
    }
    return statusCode;
}

From source file:com.jaeksoft.searchlib.remote.UriWriteStream.java

public UriWriteStream(URI uri, File file) throws IOException {
    HttpPut httpPut = new HttpPut(uri.toASCIIString());
    httpPut.setConfig(requestConfig);/* w w w.j a  va  2s  .c  o  m*/
    FileEntity fre = new FileEntity(file, ContentType.DEFAULT_BINARY);
    httpPut.setEntity(fre);
    execute(httpPut);
}

From source file:com.portfolio.data.utils.PostForm.java

public static boolean sendFile(String sessionid, String backend, String user, String uuid, String lang,
        File file) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    try {/*ww  w . j a v  a  2s.  com*/
        // Server + "/resources/resource/file/" + uuid +"?lang="+ lang
        // "http://"+backend+"/user/"+user+"/file/"+uuid+"/"+lang+"ptype/fs";
        String url = "http://" + backend + "/resources/resource/file/" + uuid + "?lang=" + lang;
        HttpPost post = new HttpPost(url);
        post.setHeader("Cookie", "JSESSIONID=" + sessionid); // So that the receiving servlet allow us

        /// Remove import language tag
        String filename = file.getName(); /// NOTE: Since it's used with zip import, specific code.
        int langindex = filename.lastIndexOf("_");
        filename = filename.substring(0, langindex) + filename.substring(langindex + 3);

        FileBody bin = new FileBody(file, ContentType.DEFAULT_BINARY, filename); // File from import

        /// Form info
        HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("uploadfile", bin).build();
        post.setEntity(reqEntity);

        CloseableHttpResponse response = httpclient.execute(post);

        /*
        try
        {
           HttpEntity resEntity = response.getEntity();   /// Will be JSON
           if( resEntity != null )
           {
              BufferedReader reader = new BufferedReader(new InputStreamReader(resEntity.getContent(), "UTF-8"));
              StringBuilder builder = new StringBuilder();
              for( String line = null; (line = reader.readLine()) != null; )
          builder.append(line).append("\n");
                
              updateResource( sessionid, backend, uuid, lang, builder.toString() );
           }
           EntityUtils.consume(resEntity);
        }
        finally
        {
           response.close();
        }
        //*/
    } finally {
        httpclient.close();
    }

    return true;
}

From source file:eu.matejkormuth.crawler2.documents.BinaryDocument.java

@Override
public ContentType getContentType() {
    return ContentType.DEFAULT_BINARY;
}

From source file:com.liferay.mobile.android.http.file.UploadData.java

public UploadData(InputStream is, String fileName, FileProgressCallback callback) {

    this(is, ContentType.DEFAULT_BINARY, fileName, callback);
}

From source file:com.ls.http.base.handler.multipart.StreamMultipartEntityPart.java

@Override
public ContentBody getContentBody() {
    return new InputStreamBody(this.value, ContentType.DEFAULT_BINARY);
}

From source file:org.lokra.seaweedfs.core.VolumeWrapperTest.java

@Test
public void checkFileExist() throws Exception {
    AssignFileKeyParams params = new AssignFileKeyParams();
    AssignFileKeyResult result = masterWrapper.assignFileKey(params);
    volumeWrapper.uploadFile(result.getUrl(), result.getFid(), "test.txt",
            new ByteArrayInputStream("@checkFileExist".getBytes()), null, ContentType.DEFAULT_BINARY);
    Assert.assertTrue(volumeWrapper.checkFileExist(result.getUrl(), result.getFid()));
}

From source file:com.sonatype.nexus.perftest.maven.ArtifactDeployer.java

/**
 * Deploys provided file under specified groupId, artifactId and version with packaging=jar.
 */// ww  w. j a  v  a  2 s  .  c  o m
public void deployJar(String groupId, String artifactId, String version, File jar) throws IOException {
    HttpEntity jarEntity = new FileEntity(jar, ContentType.DEFAULT_BINARY);
    deploy(jarEntity, groupId, artifactId, version, ".jar");
}

From source file:org.lokra.seaweedfs.core.VolumeWrapperTest.java

@Test
public void getFileStream() throws Exception {
    AssignFileKeyParams params = new AssignFileKeyParams();
    AssignFileKeyResult result = masterWrapper.assignFileKey(params);
    volumeWrapper.uploadFile(result.getUrl(), result.getFid(), "test.txt",
            new ByteArrayInputStream("@getFileContent".getBytes()), null, ContentType.DEFAULT_BINARY);

    StreamResponse cache = volumeWrapper.getFileStream(result.getUrl(), result.getFid());
    Assert.assertTrue(cache.getOutputStream().toString().equals("@getFileContent"));
}