Java源码示例:org.apache.tomcat.util.buf.C2BConverter

示例1
private static C2BConverter createConverter(final Charset charset) throws IOException {
    if (Globals.IS_SECURITY_ENABLED) {
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<C2BConverter>() {
                @Override
                public C2BConverter run() throws IOException {
                    return new C2BConverter(charset);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception e = ex.getException();
            if (e instanceof IOException) {
                throw (IOException) e;
            } else {
                throw new IOException(ex);
            }
        }
    } else {
        return new C2BConverter(charset);
    }
}
 
示例2
private void sendMessage(String message, boolean finalFragment)
        throws IOException {
    ByteChunk bc = new ByteChunk(8192);
    CharChunk cc = new CharChunk(8192);
    C2BConverter c2b = new C2BConverter("UTF-8");
    cc.append(message);
    c2b.convert(cc, bc);

    int len = bc.getLength();
    assertTrue(len < 126);

    byte first;
    if (isContinuation) {
        first = Constants.OPCODE_CONTINUATION;
    } else {
        first = Constants.OPCODE_TEXT;
    }
    if (finalFragment) {
        first = (byte) (0x80 | first);
    }
    os.write(first);

    os.write(0x80 | len);

    // Zero mask
    os.write(0);
    os.write(0);
    os.write(0);
    os.write(0);

    // Payload
    os.write(bc.getBytes(), bc.getStart(), len);

    os.flush();

    // Will the next frame be a continuation frame
    isContinuation = !finalFragment;
}
 
示例3
private void sendMessage(String message, boolean finalFragment)
        throws IOException {
    ByteChunk bc = new ByteChunk(8192);
    CharChunk cc = new CharChunk(8192);
    C2BConverter c2b = new C2BConverter("UTF-8");
    cc.append(message);
    c2b.convert(cc, bc);

    int len = bc.getLength();
    assertTrue(len < 126);

    byte first;
    if (isContinuation) {
        first = Constants.OPCODE_CONTINUATION;
    } else {
        first = Constants.OPCODE_TEXT;
    }
    if (finalFragment) {
        first = (byte) (0x80 | first);
    }
    os.write(first);

    os.write(0x80 | len);

    // Zero mask
    os.write(0);
    os.write(0);
    os.write(0);
    os.write(0);

    // Payload
    os.write(bc.getBytes(), bc.getStart(), len);

    os.flush();

    // Will the next frame be a continuation frame
    isContinuation = !finalFragment;
}