Example usage for org.apache.commons.compress.utils Charsets US_ASCII

List of usage examples for org.apache.commons.compress.utils Charsets US_ASCII

Introduction

In this page you can find the example usage for org.apache.commons.compress.utils Charsets US_ASCII.

Prototype

Charset US_ASCII

To view the source code for org.apache.commons.compress.utils Charsets US_ASCII.

Click Source Link

Document

Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.

Usage

From source file:android.framework.util.jar.InitManifest.java

private void readName() throws IOException {
    int mark = pos;

    while (pos < buf.length) {
        if (buf[pos++] != ':') {
            continue;
        }//from  w w w. j a va 2 s  .c om

        String name = new String(buf, mark, pos - mark - 1, Charsets.US_ASCII);

        if (buf[pos++] != ' ') {
            throw new IOException(String.format("Invalid value for attribute '%s'", name));
        }

        try {
            this.name = new Attributes.Name(name);
        } catch (IllegalArgumentException e) {
            // new Attributes.Name() throws IllegalArgumentException but we declare IOException
            throw new IOException(e.getMessage());
        }
        return;
    }
}

From source file:android.framework.util.jar.Manifest.java

private static void writeEntry(OutputStream os, Attributes.Name name, String value, CharsetEncoder encoder,
        ByteBuffer bBuf) throws IOException {
    String nameString = name.getName();
    os.write(nameString.getBytes(Charsets.US_ASCII));
    os.write(VALUE_SEPARATOR);/*from ww  w  .  j ava  2s . c o  m*/

    encoder.reset();
    bBuf.clear().limit(LINE_LENGTH_LIMIT - nameString.length() - 2);

    CharBuffer cBuf = CharBuffer.wrap(value);

    while (true) {
        CoderResult r = encoder.encode(cBuf, bBuf, true);
        if (CoderResult.UNDERFLOW == r) {
            r = encoder.flush(bBuf);
        }
        os.write(bBuf.array(), bBuf.arrayOffset(), bBuf.position());
        os.write(LINE_SEPARATOR);
        if (CoderResult.UNDERFLOW == r) {
            break;
        }
        os.write(' ');
        bBuf.clear().limit(LINE_LENGTH_LIMIT - 1);
    }
}