本文整理匯總了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;
}