当前位置: 首页>>代码示例>>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;未经允许,请勿转载。