Example usage for org.apache.http.entity FileEntity getContent

List of usage examples for org.apache.http.entity FileEntity getContent

Introduction

In this page you can find the example usage for org.apache.http.entity FileEntity getContent.

Prototype

public InputStream getContent() throws IOException 

Source Link

Usage

From source file:ch.admin.hermes.etl.load.SharePointRESTClient.java

public String postFile(String uri, File data) throws IOException {
    HttpPost request = new HttpPost(remote + uri);
    request.addHeader("Accept", "application/json;odata=verbose;charset=utf-8");
    request.addHeader("Content-Type", "application/msword");

    if (xRequestDigest != null)
        request.addHeader("X-RequestDigest", xRequestDigest);

    if (data != null) {
        FileEntity entity = new FileEntity(data);
        request.setEntity(entity);// w  ww. jav  a2s  .co m
    }

    HttpResponse response = client.execute(request);
    checkError(response, uri);

    HttpEntity entity = response.getEntity();
    BufferedReader isr = new BufferedReader(new InputStreamReader(entity.getContent()));

    StringBuffer str = new StringBuffer();
    String line = "";
    while ((line = isr.readLine()) != null)
        str.append(line);

    EntityUtils.consume(entity);
    return (str.toString());
}