本文整理汇总了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();
}
}
示例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);
}
}