本文整理汇总了Java中org.apache.http.util.EncodingUtils.getAsciiBytes方法的典型用法代码示例。如果您正苦于以下问题:Java EncodingUtils.getAsciiBytes方法的具体用法?Java EncodingUtils.getAsciiBytes怎么用?Java EncodingUtils.getAsciiBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.EncodingUtils
的用法示例。
在下文中一共展示了EncodingUtils.getAsciiBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleException
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Handles the given exception and generates an HTTP response to be sent
* back to the client to inform about the exceptional condition encountered
* in the course of the request processing.
*
* @param ex the exception.
* @param response the HTTP response.
*/
protected void handleException(final HttpException ex, final HttpResponse response) {
if (ex instanceof MethodNotSupportedException) {
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
} else if (ex instanceof UnsupportedHttpVersionException) {
response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
} else if (ex instanceof ProtocolException) {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
} else {
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
String message = ex.getMessage();
if (message == null) {
message = ex.toString();
}
byte[] msg = EncodingUtils.getAsciiBytes(message);
ByteArrayEntity entity = new ByteArrayEntity(msg);
entity.setContentType("text/plain; charset=US-ASCII");
response.setEntity(entity);
}
示例2: setUsernamePassword
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Method used to set the authentication data in the request.
* @param username The user name to set
* @param password The password to set
*/
public void setUsernamePassword(String username, String password) {
/*
* Encode the data
*/
byte[] ascii = EncodingUtils.getAsciiBytes(username + password);
/*
* The code should not end with the EOL character
*/
String authentication = SecurityUtils.base64Encode(ascii);
/*
* Add the authentication to the header
*/
headerFields.put("Authorization", authentication);
}
示例3: Boundary
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
Boundary(String boundary) {
if (TextUtils.isEmpty(boundary)) {
boundary = generateBoundary();
}
this.boundary = boundary;
final String starting = "--" + boundary + MultipartEntity.CRLF; //$NON-NLS-1$
final String closing = "--" + boundary + "--" + MultipartEntity.CRLF; //$NON-NLS-1$
startingBoundary = EncodingUtils.getAsciiBytes(starting);
closingBoundary = EncodingUtils.getAsciiBytes(closing);
}
示例4: getMultipartBoundary
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Returns the MIME boundary string that is used to demarcate boundaries of
* this part. The first call to this method will implicitly create a new
* boundary string. To create a boundary string first the
* HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise
* a random one is generated.
*
* @return The boundary string of this entity in ASCII encoding.
*/
protected byte[] getMultipartBoundary() {
if (multipartBoundary == null) {
String temp = null;
if (params != null) {
temp = (String) params.getParameter(MULTIPART_BOUNDARY);
}
if (temp != null) {
multipartBoundary = EncodingUtils.getAsciiBytes(temp);
} else {
multipartBoundary = generateMultipartBoundary();
}
}
return multipartBoundary;
}
示例5: CBBoundary
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
CBBoundary(String boundary) {
if (boundary == null || "".equals(boundary)) {
boundary = generateBoundary();
}
this.boundary = boundary;
final String starting = "--" + boundary + CBMultipartEntity.CRLF; //$NON-NLS-1$
final String closing = "--" + boundary + "--" + CBMultipartEntity.CRLF; //$NON-NLS-1$
startingBoundary = EncodingUtils.getAsciiBytes(starting);
closingBoundary = EncodingUtils.getAsciiBytes(closing);
}
示例6: getMultipartBoundary
import org.apache.http.util.EncodingUtils; //导入方法依赖的package包/类
/**
* Returns the MIME boundary string that is used to demarcate boundaries of
* this part. The first call to this method will implicitly create a new
* boundary string. To create a boundary string first the
* HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise
* a random one is generated.
*
* @return The boundary string of this entity in ASCII encoding.
*/
protected byte[] getMultipartBoundary() {
if (this.multipartBoundary == null) {
String temp = null;
if (this.params != null) {
temp = (String) this.params.getParameter(MULTIPART_BOUNDARY);
}
if (temp != null) {
this.multipartBoundary = EncodingUtils.getAsciiBytes(temp);
} else {
this.multipartBoundary = generateMultipartBoundary();
}
}
return this.multipartBoundary;
}