Example usage for org.apache.http.util EncodingUtils getAsciiBytes

List of usage examples for org.apache.http.util EncodingUtils getAsciiBytes

Introduction

In this page you can find the example usage for org.apache.http.util EncodingUtils getAsciiBytes.

Prototype

public static byte[] getAsciiBytes(String str) 

Source Link

Usage

From source file:com.android.pwdhashandroid.pwdhash.PasswordHasher.java

protected String B64HmacMd5(String password, String realm) throws GeneralSecurityException {

    Log.d(tag, "B64HmacMd5:");
    Log.d(tag, "password:\t" + password);
    Log.d(tag, "realm:\t\t" + realm);

    // Put data in byte arrays to use for MD5      
    byte[] key = EncodingUtils.getAsciiBytes(password);
    byte[] data = EncodingUtils.getAsciiBytes(realm);

    // Create our hash
    HMACMD5 hmac = new HMACMD5(key);
    byte[] hashb = hmac.ComputeHash(data);

    // Store it as a base-64 string
    String hash = Base64Coder.encode(hashb);

    // Remove trailing "=="'s, which are added for strict adherence
    // to MD5 RFC.

    //        Pattern p = Pattern.compile("=+$");
    //        Matcher m = p.matcher(hash);
    //        String newhash = m.replaceAll("");

    String newhash = hash.replaceAll("=+$", "");

    Log.d(tag, "hash:\t\t" + newhash);

    return newhash;
}

From source file:com.subgraph.vega.internal.http.proxy.VegaHttpService.java

private void sendCertificateDownloadResponse(VegaHttpServerConnection connection, HttpContext context)
        throws HttpException, IOException {
    final String pem = sslContextRepository.getCaCertificatePem();
    final byte[] body = EncodingUtils.getAsciiBytes(pem);
    ByteArrayEntity entity = new ByteArrayEntity(body);
    entity.setContentType("application/x-x509-ca-cert; charset=US-ASCII");
    sendResponseOk(connection, context, entity);
}

From source file:local.apache.MultipartEntity.java

/**
 * 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.//from w ww . j a  va  2 s . co  m
 *
 * @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;
}

From source file:com.android.internal.http.multipart.MultipartEntity.java

/**
 * 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.//  w  w w .  j av  a 2  s.c om
 * 
 * @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;
}

From source file:com.android.internalcopy.http.multipart.BitCometFilePart.java

/**
 * Write the disposition header to the output stream
 * @param out The output stream//  www.  ja  v  a2 s.co  m
 * @throws IOException If an IO problem occurs
 * @see Part#sendDispositionHeader(OutputStream)
 */
@Override
protected void sendDispositionHeader(OutputStream out) throws IOException {
    super.sendDispositionHeader(out);
    String filename = this.source.getFileName();
    if (filename != null) {
        out.write(FILE_NAME_BYTES);
        out.write(QUOTE_BYTES);
        out.write(EncodingUtils.getAsciiBytes(filename));
        out.write(QUOTE_BYTES);
    }
}

From source file:com.chanapps.four.multipartmime.FilePart.java

/**
 * Write the disposition header to the output stream
 * @param out The output stream//from w w  w.ja  v  a  2  s  .  c o  m
 * @throws IOException If an IO problem occurs
 * @see Part#sendDispositionHeader(OutputStream)
 */
@Override
protected void sendDispositionHeader(OutputStream out) throws IOException {
    if (DEBUG)
        Log.d(TAG, "enter sendDispositionHeader(OutputStream out)");
    super.sendDispositionHeader(out);
    String filename = this.source.getFileName();
    if (filename != null) {
        out.write(FILE_NAME_BYTES);
        out.write(QUOTE_BYTES);
        out.write(EncodingUtils.getAsciiBytes(filename));
        out.write(QUOTE_BYTES);
    }
}

From source file:com.android.internal.http.multipart.FilePart.java

/**
 * Write the disposition header to the output stream
 * @param out The output stream/*from  ww  w.j a  v  a  2s .  co m*/
 * @throws IOException If an IO problem occurs
 * @see Part#sendDispositionHeader(OutputStream)
 */
@Override
protected void sendDispositionHeader(OutputStream out) throws IOException {
    LOG.trace("enter sendDispositionHeader(OutputStream out)");
    super.sendDispositionHeader(out);
    String filename = this.source.getFileName();
    if (filename != null) {
        out.write(FILE_NAME_BYTES);
        out.write(QUOTE_BYTES);
        out.write(EncodingUtils.getAsciiBytes(filename));
        out.write(QUOTE_BYTES);
    }
}

From source file:com.nhn.android.me2day.sample.multipart.FilePart.java

/**
 * Write the disposition header to the output stream
 * @param out The output stream// w w w  .  j a  v a  2 s .  co  m
 * @throws IOException If an IO problem occurs
 * @see Part#sendDispositionHeader(OutputStream)
 */
@Override
protected void sendDispositionHeader(OutputStream out) throws IOException {
    Log.d("FilePart", "enter sendDispositionHeader(OutputStream out)");
    super.sendDispositionHeader(out);
    String filename = this.source.getFileName();
    if (filename != null) {
        out.write(FILE_NAME_BYTES);
        out.write(QUOTE_BYTES);
        if (headerFileName == null)
            out.write(EncodingUtils.getAsciiBytes(filename));
        else
            out.write(EncodingUtils.getAsciiBytes(headerFileName));
        out.write(QUOTE_BYTES);
    }
}

From source file:com.android.internalcopy.http.multipart.Part.java

/**
 * Write the content disposition header to the specified output stream
 * /*from www . j  ava 2s  .c  o  m*/
 * @param out The output stream
 * @throws IOException If an IO problem occurs.
 */
protected void sendDispositionHeader(OutputStream out) throws IOException {
    out.write(CONTENT_DISPOSITION_BYTES);
    out.write(QUOTE_BYTES);
    out.write(EncodingUtils.getAsciiBytes(getName()));
    out.write(QUOTE_BYTES);
}

From source file:com.nhn.android.me2day.sample.multipart.Part.java

/**
 * Write the content disposition header to the specified output stream
 * //from   w  ww.  ja va  2 s  .  c om
 * @param out The output stream
 * @throws IOException If an IO problem occurs.
 */
protected void sendDispositionHeader(OutputStream out) throws IOException {
    Log.d("Part", "enter sendDispositionHeader(OutputStream out)");
    out.write(CONTENT_DISPOSITION_BYTES);
    out.write(QUOTE_BYTES);
    out.write(EncodingUtils.getAsciiBytes(getName()));
    out.write(QUOTE_BYTES);
}