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


Java EncodingUtils.getAsciiBytes方法代碼示例

本文整理匯總了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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:HttpService.java

示例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);
}
 
開發者ID:jiahaoliuliu,項目名稱:sampleaccountandserver,代碼行數:21,代碼來源:HttpRequest.java

示例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);
}
 
開發者ID:barterli,項目名稱:barterli_android,代碼行數:13,代碼來源:Boundary.java

示例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;
}
 
開發者ID:erickok,項目名稱:transdroid,代碼行數:24,代碼來源:MultipartEntity.java

示例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);
}
 
開發者ID:cloudbase-io,項目名稱:CBHelper-Java,代碼行數:13,代碼來源:CBBoundary.java

示例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;
}
 
開發者ID:haku,項目名稱:Onosendai,代碼行數:24,代碼來源:MultipartEntity.java


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