Java Code Examples for org.apache.tomcat.util.buf.HexUtils#getHex()

The following examples show how to use org.apache.tomcat.util.buf.HexUtils#getHex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChunkedOutputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Write some bytes.
 * 
 * @return number of bytes written by the filter
 */
@Override
public int doWrite(ByteChunk chunk, Response res)
    throws IOException {

    int result = chunk.getLength();

    if (result <= 0) {
        return 0;
    }

    // Calculate chunk header
    int pos = 7;
    int current = result;
    while (current > 0) {
        int digit = current % 16;
        current = current / 16;
        chunkLength[pos--] = HexUtils.getHex(digit);
    }
    chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos);
    buffer.doWrite(chunkHeader, res);

    buffer.doWrite(chunk, res);

    chunkHeader.setBytes(chunkLength, 8, 2);
    buffer.doWrite(chunkHeader, res);

    return result;

}
 
Example 2
Source File: ChunkedOutputFilter.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Write some bytes.
 * 
 * @return number of bytes written by the filter
 */
@Override
public int doWrite(ByteChunk chunk, Response res)
    throws IOException {

    int result = chunk.getLength();

    if (result <= 0) {
        return 0;
    }

    // Calculate chunk header
    int pos = 7;
    int current = result;
    while (current > 0) {
        int digit = current % 16;
        current = current / 16;
        chunkLength[pos--] = HexUtils.getHex(digit);
    }
    chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos);
    buffer.doWrite(chunkHeader, res);

    buffer.doWrite(chunk, res);

    chunkHeader.setBytes(chunkLength, 8, 2);
    buffer.doWrite(chunkHeader, res);

    return result;

}