本文整理汇总了Java中org.apache.tomcat.util.buf.ByteChunk.getBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ByteChunk.getBuffer方法的具体用法?Java ByteChunk.getBuffer怎么用?Java ByteChunk.getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.buf.ByteChunk
的用法示例。
在下文中一共展示了ByteChunk.getBuffer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertMB
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Character conversion of the a US-ASCII MessageBytes.
*/
protected void convertMB(MessageBytes mb) {
// This is of course only meaningful for bytes
if (mb.getType() != MessageBytes.T_BYTES) {
return;
}
ByteChunk bc = mb.getByteChunk();
CharChunk cc = mb.getCharChunk();
int length = bc.getLength();
cc.allocate(length, -1);
// 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);
}
mb.setChars(cbuf, 0, length);
}
示例2: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
@Override
public int doWrite(ByteChunk chunk, Response res) throws IOException {
try {
int len = chunk.getLength();
int start = chunk.getStart();
byte[] b = chunk.getBuffer();
addToBB(b, start, len);
byteCount += chunk.getLength();
return chunk.getLength();
} catch (IOException ioe) {
response.action(ActionCode.CLOSE_NOW, ioe);
// Re-throw
throw ioe;
}
}
示例3: unescapeDoubleQuotes
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Unescapes any double quotes in the given cookie value.
*
* @param bc The cookie value to modify
*/
private static void unescapeDoubleQuotes(ByteChunk bc) {
if (bc == null || bc.getLength() == 0 || bc.indexOf('"', 0) == -1) {
return;
}
int src = bc.getStart();
int end = bc.getEnd();
int dest = src;
byte[] buffer = bc.getBuffer();
while (src < end) {
if (buffer[src] == '\\' && src < end && buffer[src+1] == '"') {
src++;
}
buffer[dest] = buffer[src];
dest ++;
src ++;
}
bc.setEnd(dest);
}
示例4: convertMB
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Character conversion of the a US-ASCII MessageBytes.
*/
protected void convertMB(MessageBytes mb) {
// This is of course only meaningful for bytes
if (mb.getType() != MessageBytes.T_BYTES) {
return;
}
ByteChunk bc = mb.getByteChunk();
CharChunk cc = mb.getCharChunk();
int length = bc.getLength();
cc.allocate(length, -1);
// 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);
}
mb.setChars(cbuf, 0, length);
}
示例5: convertMB
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Character conversion of the a US-ASCII MessageBytes.
*/
protected void convertMB(MessageBytes mb) {
// This is of course only meaningful for bytes
if (mb.getType() != MessageBytes.T_BYTES)
return;
ByteChunk bc = mb.getByteChunk();
CharChunk cc = mb.getCharChunk();
int length = bc.getLength();
cc.allocate(length, -1);
// 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);
}
mb.setChars(cbuf, 0, length);
}
示例6: findBytes
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Specialized utility method: find a sequence of lower case bytes inside
* a ByteChunk.
*/
protected int findBytes(ByteChunk bc, byte[] b) {
byte first = b[0];
byte[] buff = bc.getBuffer();
int start = bc.getStart();
int end = bc.getEnd();
// Look for first char
int srcEnd = b.length;
for (int i = start; i <= (end - srcEnd); i++) {
if (Ascii.toLower(buff[i]) != first) continue;
// found first char, now look for a match
int myPos = i+1;
for (int srcPos = 1; srcPos < srcEnd; ) {
if (Ascii.toLower(buff[myPos++]) != b[srcPos++])
break;
if (srcPos == srcEnd) return i - start; // found it
}
}
return -1;
}
示例7: unescapeDoubleQuotes
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Unescapes any double quotes in the given cookie value.
*
* @param bc The cookie value to modify
*/
public static void unescapeDoubleQuotes(ByteChunk bc) {
if (bc == null || bc.getLength() == 0 || bc.indexOf('"', 0) == -1) {
return;
}
int src = bc.getStart();
int end = bc.getEnd();
int dest = src;
byte[] buffer = bc.getBuffer();
while (src < end) {
if (buffer[src] == '\\' && src < end && buffer[src+1] == '"') {
src++;
}
buffer[dest] = buffer[src];
dest ++;
src ++;
}
bc.setEnd(dest);
}
示例8: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
@Override
public int doWrite(ByteChunk chunk, Response res) throws IOException {
try {
int len = chunk.getLength();
int start = chunk.getStart();
byte[] b = chunk.getBuffer();
while (len > 0) {
int thisTime = len;
if (bbuf.position() == bbuf.capacity()) {
flushBuffer();
}
if (thisTime > bbuf.capacity() - bbuf.position()) {
thisTime = bbuf.capacity() - bbuf.position();
}
bbuf.put(b, start, thisTime);
len = len - thisTime;
start = start + thisTime;
}
byteCount += chunk.getLength();
return chunk.getLength();
} catch (IOException ioe) {
response.action(ActionCode.CLOSE_NOW, ioe);
// Re-throw
throw ioe;
}
}
示例9: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
@Override
public int doWrite(ByteChunk chunk, Response res) throws IOException {
try {
int len = chunk.getLength();
int start = chunk.getStart();
byte[] b = chunk.getBuffer();
while (len > 0) {
int thisTime = len;
if (bbuf.position() == bbuf.capacity()) {
flushBuffer();
}
if (thisTime > bbuf.capacity() - bbuf.position()) {
thisTime = bbuf.capacity() - bbuf.position();
}
bbuf.put(b, start, thisTime);
len = len - thisTime;
start = start + thisTime;
}
byteCount += chunk.getLength();
return chunk.getLength();
} catch (IOException ioe) {
response.action(ActionCode.CLOSE_NOW, ioe);
// Re-throw
throw ioe;
}
}
示例10: findBytes
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Specialized utility method: find a sequence of lower case bytes inside a
* ByteChunk.
*/
protected int findBytes(ByteChunk bc, byte[] b) {
byte first = b[0];
byte[] buff = bc.getBuffer();
int start = bc.getStart();
int end = bc.getEnd();
// Look for first char
int srcEnd = b.length;
for (int i = start; i <= (end - srcEnd); i++) {
if (Ascii.toLower(buff[i]) != first) {
continue;
}
// found first char, now look for a match
int myPos = i + 1;
for (int srcPos = 1; srcPos < srcEnd;) {
if (Ascii.toLower(buff[myPos++]) != b[srcPos++]) {
break;
}
if (srcPos == srcEnd) {
return i - start; // found it
}
}
}
return -1;
}
示例11: decode
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Decodes Base64 data into octets
*
* @param base64DataBC Byte array containing Base64 data
* @param decodedDataCC The decoded data chars
*/
public static void decode( ByteChunk base64DataBC, CharChunk decodedDataCC)
{
int start = base64DataBC.getStart();
int end = base64DataBC.getEnd();
byte[] base64Data = base64DataBC.getBuffer();
decodedDataCC.recycle();
// handle the edge case, so we don't have to worry about it later
if(end - start == 0) { return; }
int numberQuadruple = (end - start)/FOURBYTE;
byte b1=0,b2=0,b3=0, b4=0, marker0=0, marker1=0;
// Throw away anything not in base64Data
int encodedIndex = 0;
int dataIndex = start;
char[] decodedData = null;
{
// this sizes the output array properly - rlw
int lastData = end - start;
// ignore the '=' padding
while (base64Data[start+lastData-1] == PAD)
{
if (--lastData == 0)
{
return;
}
}
decodedDataCC.allocate(lastData - numberQuadruple, -1);
decodedDataCC.setEnd(lastData - numberQuadruple);
decodedData = decodedDataCC.getBuffer();
}
for (int i = 0; i < numberQuadruple; i++)
{
dataIndex = start + i * 4;
marker0 = base64Data[dataIndex + 2];
marker1 = base64Data[dataIndex + 3];
b1 = base64Alphabet[base64Data[dataIndex]];
b2 = base64Alphabet[base64Data[dataIndex +1]];
if (marker0 != PAD && marker1 != PAD)
{
//No PAD e.g 3cQl
b3 = base64Alphabet[ marker0 ];
b4 = base64Alphabet[ marker1 ];
decodedData[encodedIndex] = (char) (( b1 <<2 | b2>>4 ) & 0xff);
decodedData[encodedIndex + 1] =
(char) ((((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ) & 0xff);
decodedData[encodedIndex + 2] = (char) (( b3<<6 | b4 ) & 0xff);
}
else if (marker0 == PAD)
{
//Two PAD e.g. 3c[Pad][Pad]
decodedData[encodedIndex] = (char) (( b1 <<2 | b2>>4 ) & 0xff);
}
else if (marker1 == PAD)
{
//One PAD e.g. 3cQ[Pad]
b3 = base64Alphabet[ marker0 ];
decodedData[encodedIndex] = (char) (( b1 <<2 | b2>>4 ) & 0xff);
decodedData[encodedIndex + 1] =
(char) ((((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ) & 0xff);
}
encodedIndex += 3;
}
}
示例12: decode
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Decodes Base64 data into octets
*
* @param base64DataBC
* Byte array containing Base64 data
* @param decodedDataBC
* The decoded data bytes
*/
public static void decode(ByteChunk base64DataBC, ByteChunk decodedDataBC) {
int start = base64DataBC.getStart();
int end = base64DataBC.getEnd();
byte[] base64Data = base64DataBC.getBuffer();
decodedDataBC.recycle();
// handle the edge case, so we don't have to worry about it later
if (end - start == 0) {
return;
}
int numberQuadruple = (end - start) / FOURBYTE;
byte b1 = 0, b2 = 0, b3 = 0, b4 = 0, marker0 = 0, marker1 = 0;
// Throw away anything not in base64Data
int encodedIndex = 0;
int dataIndex = start;
byte[] decodedData = null;
{
// this sizes the output array properly - rlw
int lastData = end - start;
// ignore the '=' padding
while (base64Data[start + lastData - 1] == PAD) {
if (--lastData == 0) {
return;
}
}
decodedDataBC.allocate(lastData - numberQuadruple, -1);
decodedDataBC.setEnd(lastData - numberQuadruple);
decodedData = decodedDataBC.getBuffer();
}
for (int i = 0; i < numberQuadruple; i++) {
dataIndex = start + i * 4;
marker0 = base64Data[dataIndex + 2];
marker1 = base64Data[dataIndex + 3];
b1 = base64Alphabet[base64Data[dataIndex]];
b2 = base64Alphabet[base64Data[dataIndex + 1]];
if (marker0 != PAD && marker1 != PAD) {
// No PAD e.g 3cQl
b3 = base64Alphabet[marker0];
b4 = base64Alphabet[marker1];
decodedData[encodedIndex] = (byte) ((b1 << 2 | b2 >> 4) & 0xff);
decodedData[encodedIndex + 1] = (byte) ((((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)) & 0xff);
decodedData[encodedIndex + 2] = (byte) ((b3 << 6 | b4) & 0xff);
} else if (marker0 == PAD) {
// Two PAD e.g. 3c[Pad][Pad]
decodedData[encodedIndex] = (byte) ((b1 << 2 | b2 >> 4) & 0xff);
} else if (marker1 == PAD) {
// One PAD e.g. 3cQ[Pad]
b3 = base64Alphabet[marker0];
decodedData[encodedIndex] = (byte) ((b1 << 2 | b2 >> 4) & 0xff);
decodedData[encodedIndex + 1] = (byte) ((((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)) & 0xff);
}
encodedIndex += 3;
}
}
示例13: decode
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Decodes Base64 data into octects
*
* @param base64DataBC Byte array containing Base64 data
* @param decodedDataCC The decoded data chars
*/
public static void decode( ByteChunk base64DataBC, CharChunk decodedDataCC)
{
int start = base64DataBC.getStart();
int end = base64DataBC.getEnd();
byte[] base64Data = base64DataBC.getBuffer();
decodedDataCC.recycle();
// handle the edge case, so we don't have to worry about it later
if(end - start == 0) { return; }
int numberQuadruple = (end - start)/FOURBYTE;
byte b1=0,b2=0,b3=0, b4=0, marker0=0, marker1=0;
// Throw away anything not in base64Data
int encodedIndex = 0;
int dataIndex = start;
char[] decodedData = null;
{
// this sizes the output array properly - rlw
int lastData = end - start;
// ignore the '=' padding
while (base64Data[start+lastData-1] == PAD)
{
if (--lastData == 0)
{
return;
}
}
decodedDataCC.allocate(lastData - numberQuadruple, -1);
decodedDataCC.setEnd(lastData - numberQuadruple);
decodedData = decodedDataCC.getBuffer();
}
for (int i = 0; i < numberQuadruple; i++)
{
dataIndex = start + i * 4;
marker0 = base64Data[dataIndex + 2];
marker1 = base64Data[dataIndex + 3];
b1 = base64Alphabet[base64Data[dataIndex]];
b2 = base64Alphabet[base64Data[dataIndex +1]];
if (marker0 != PAD && marker1 != PAD)
{
//No PAD e.g 3cQl
b3 = base64Alphabet[ marker0 ];
b4 = base64Alphabet[ marker1 ];
decodedData[encodedIndex] = (char) (( b1 <<2 | b2>>4 ) & 0xff);
decodedData[encodedIndex + 1] =
(char) ((((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ) & 0xff);
decodedData[encodedIndex + 2] = (char) (( b3<<6 | b4 ) & 0xff);
}
else if (marker0 == PAD)
{
//Two PAD e.g. 3c[Pad][Pad]
decodedData[encodedIndex] = (char) (( b1 <<2 | b2>>4 ) & 0xff);
}
else if (marker1 == PAD)
{
//One PAD e.g. 3cQ[Pad]
b3 = base64Alphabet[ marker0 ];
decodedData[encodedIndex] = (char) (( b1 <<2 | b2>>4 ) & 0xff);
decodedData[encodedIndex + 1] =
(char) ((((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ) & 0xff);
}
encodedIndex += 3;
}
}
示例14: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
public int doWrite(ByteChunk chunk, Response res)
throws IOException {
// If non blocking (comet) and there are leftover bytes,
// put all remaining bytes in the leftover buffer (they are
// part of the same write operation)
if (leftover.getLength() > 0) {
leftover.append(chunk);
return chunk.getLength();
}
int len = chunk.getLength();
int start = chunk.getStart();
byte[] b = chunk.getBuffer();
while (len > 0) {
int thisTime = len;
if (bbuf.position() == bbuf.capacity()) {
flushBuffer();
if (leftover.getLength() > 0) {
// If non blocking (comet) and there are leftover bytes,
// put all remaining bytes in the leftover buffer (they are
// part of the same write operation)
int oldStart = chunk.getOffset();
chunk.setOffset(start);
leftover.append(chunk);
chunk.setOffset(oldStart);
// After that, all content has been "written"
return chunk.getLength();
}
}
if (thisTime > bbuf.capacity() - bbuf.position()) {
thisTime = bbuf.capacity() - bbuf.position();
}
bbuf.put(b, start, thisTime);
len = len - thisTime;
start = start + thisTime;
}
return chunk.getLength();
}