Search in sources :

Example 1 with B2CConverter

use of org.glassfish.grizzly.http.util.B2CConverter in project Payara by payara.

the class Request method convertURI.

// START CR 6309511
/**
 * Character conversion of the URI.
 */
protected void convertURI(MessageBytes uri) throws Exception {
    ByteChunk bc = uri.getByteChunk();
    CharChunk cc = uri.getCharChunk();
    int length = bc.getLength();
    cc.allocate(length, -1);
    String enc = connector.getURIEncoding();
    if (enc != null && !enc.isEmpty() && !Globals.ISO_8859_1_ENCODING.equalsIgnoreCase(enc)) {
        B2CConverter conv = getURIConverter();
        try {
            if (conv == null) {
                conv = new B2CConverter(enc);
                setURIConverter(conv);
            }
        } catch (IOException e) {
            // Ignore
            log.log(Level.SEVERE, LogFacade.INVALID_URI_ENCODING);
            connector.setURIEncoding(null);
        }
        if (conv != null) {
            try {
                conv.convert(bc, cc, cc.getBuffer().length - cc.getEnd());
                uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength());
                return;
            } catch (IOException e) {
                log.log(Level.SEVERE, LogFacade.INVALID_URI_CHAR_ENCODING);
                cc.recycle();
            }
        }
    }
    // Default encoding: fast conversion
    byte[] bbuf = bc.getBuffer();
    char[] cbuf = cc.getBuffer();
    int start = bc.getStart();
    for (int i = 0; i < length; i++) {
        cbuf[i] = (char) (bbuf[i + start] & 0xff);
    }
    uri.setChars(cbuf, 0, length);
}
Also used : B2CConverter(org.glassfish.grizzly.http.util.B2CConverter) ByteChunk(org.glassfish.grizzly.http.util.ByteChunk) IOException(java.io.IOException) CharChunk(org.glassfish.grizzly.http.util.CharChunk)

Aggregations

IOException (java.io.IOException)1 B2CConverter (org.glassfish.grizzly.http.util.B2CConverter)1 ByteChunk (org.glassfish.grizzly.http.util.ByteChunk)1 CharChunk (org.glassfish.grizzly.http.util.CharChunk)1