當前位置: 首頁>>代碼示例>>Java>>正文


Java FileEntity.setContentType方法代碼示例

本文整理匯總了Java中org.apache.http.entity.FileEntity.setContentType方法的典型用法代碼示例。如果您正苦於以下問題:Java FileEntity.setContentType方法的具體用法?Java FileEntity.setContentType怎麽用?Java FileEntity.setContentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.entity.FileEntity的用法示例。


在下文中一共展示了FileEntity.setContentType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: putFileToServerFromLocal

import org.apache.http.entity.FileEntity; //導入方法依賴的package包/類
public static boolean putFileToServerFromLocal(String url, File fileManager, String fileType) {
  try {
    url = url.replaceAll(" ", "%20");
    // if (ExoConnectionUtils.getResponseCode(url) != 1) {
    // if (!ExoConnectionUtils.onReLogin()) {
    // return false;
    // }
    // }

    HttpPut put = new HttpPut(url);
    FileEntity fileEntity = new FileEntity(fileManager, fileType);
    put.setEntity(fileEntity);
    fileEntity.setContentType(fileType);
    HttpResponse response = ExoConnectionUtils.httpClient.execute(put);
    int status = response.getStatusLine().getStatusCode();
    if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
      return true;
    } else {
      return false;
    }
  } catch (IOException e) {
    return false;
  } finally {
    fileManager.delete();
  }

}
 
開發者ID:paristote,項目名稱:mobile-android-studio,代碼行數:28,代碼來源:ExoDocumentUtils.java

示例2: preparePostMethod

import org.apache.http.entity.FileEntity; //導入方法依賴的package包/類
public void preparePostMethod(String method, Object[] params, File tempFile) throws IOException, XMLRPCException, IllegalArgumentException, IllegalStateException {
    // prepare POST body
    if (method.equals("wp.uploadFile")) {
        if (!tempFile.exists() && !tempFile.mkdirs()) {
            throw new XMLRPCException("Path to file could not be created.");
        }

        FileWriter fileWriter = new FileWriter(tempFile);
        mSerializer.setOutput(fileWriter);

        mSerializer.startDocument(null, null);
        mSerializer.startTag(null, TAG_METHOD_CALL);
        // set method name
        mSerializer.startTag(null, TAG_METHOD_NAME).text(method).endTag(null, TAG_METHOD_NAME);
        if (params != null && params.length != 0) {
            // set method params
            mSerializer.startTag(null, TAG_PARAMS);
            for (int i = 0; i < params.length; i++) {
                mSerializer.startTag(null, TAG_PARAM).startTag(null, XMLRPCSerializer.TAG_VALUE);
                XMLRPCSerializer.serialize(mSerializer, params[i]);
                mSerializer.endTag(null, XMLRPCSerializer.TAG_VALUE).endTag(null, TAG_PARAM);
            }
            mSerializer.endTag(null, TAG_PARAMS);
        }
        mSerializer.endTag(null, TAG_METHOD_CALL);
        mSerializer.endDocument();

        fileWriter.flush();
        fileWriter.close();

        FileEntity fEntity = new FileEntity(tempFile, "text/xml; charset=\"UTF-8\"") {
            // Hook in a CountingOutputStream to keep track of bytes uploaded
            @Override
            public void writeTo(final OutputStream outstream) throws IOException {
                super.writeTo(new CountingOutputStream(outstream));
            }
        };

        fEntity.setContentType("text/xml");
        mPostMethod.setEntity(fEntity);
    } else {
        StringWriter bodyWriter = new StringWriter();
        mSerializer.setOutput(bodyWriter);

        mSerializer.startDocument(null, null);
        mSerializer.startTag(null, TAG_METHOD_CALL);
        // set method name
        mSerializer.startTag(null, TAG_METHOD_NAME).text(method).endTag(null, TAG_METHOD_NAME);
        if (params != null && params.length != 0) {
            // set method params
            mSerializer.startTag(null, TAG_PARAMS);
            for (int i = 0; i < params.length; i++) {
                mSerializer.startTag(null, TAG_PARAM).startTag(null, XMLRPCSerializer.TAG_VALUE);
                if (method.equals("metaWeblog.editPost") || method.equals("metaWeblog.newPost")) {
                    XMLRPCSerializer.serialize(mSerializer, params[i]);
                } else {
                    XMLRPCSerializer.serialize(mSerializer, params[i]);
                }
                mSerializer.endTag(null, XMLRPCSerializer.TAG_VALUE).endTag(null, TAG_PARAM);
            }
            mSerializer.endTag(null, TAG_PARAMS);
        }
        mSerializer.endTag(null, TAG_METHOD_CALL);
        mSerializer.endDocument();

        HttpEntity entity = new StringEntity(bodyWriter.toString());
        mPostMethod.setEntity(entity);
    }
}
 
開發者ID:ldsddn,項目名稱:wordpress_app_android,代碼行數:70,代碼來源:XMLRPCClient.java


注:本文中的org.apache.http.entity.FileEntity.setContentType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。