本文整理汇总了Java中org.apache.tomcat.util.buf.ByteChunk.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java ByteChunk.getLength方法的具体用法?Java ByteChunk.getLength怎么用?Java ByteChunk.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.buf.ByteChunk
的用法示例。
在下文中一共展示了ByteChunk.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 length = chunk.getLength();
if (useSocketBuffer) {
socketBuffer.append(chunk.getBuffer(), chunk.getStart(),
length);
} else {
outputStream.write(chunk.getBuffer(), chunk.getStart(),
length);
}
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: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
@Override
public int doWrite(ByteChunk chunk, Response res) throws IOException {
try {
int length = chunk.getLength();
if (useSocketBuffer) {
socketBuffer.append(chunk.getBuffer(), chunk.getStart(), length);
} else {
outputStream.write(chunk.getBuffer(), chunk.getStart(), length);
}
byteCount += chunk.getLength();
return chunk.getLength();
} catch (IOException ioe) {
response.action(ActionCode.CLOSE_NOW, ioe);
// Re-throw
throw ioe;
}
}
示例5: 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);
}
示例6: doRead
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Read bytes into the specified chunk.
*/
@Override
public int doRead(ByteChunk chunk, Request req)
throws IOException {
if (endOfStream) {
return -1;
}
if (first && req.getContentLengthLong() > 0) {
// Handle special first-body-chunk
if (!receive()) {
return 0;
}
} else if (empty) {
if (!refillReadBuffer()) {
return -1;
}
}
ByteChunk bc = bodyBytes.getByteChunk();
chunk.setBytes(bc.getBuffer(), bc.getStart(), bc.getLength());
empty = true;
return chunk.getLength();
}
示例7: saveRequest
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Save the original request information into our session.
*
* @param request The request to be saved
* @param session The session to contain the saved information
* @throws IOException
*/
protected void saveRequest(Request request, Session session)
throws IOException {
// Create and populate a SavedRequest object for this request
SavedRequest saved = new SavedRequest();
Cookie cookies[] = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
saved.addCookie(cookies[i]);
}
}
Enumeration<String> names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
Enumeration<String> values = request.getHeaders(name);
while (values.hasMoreElements()) {
String value = values.nextElement();
saved.addHeader(name, value);
}
}
Enumeration<Locale> locales = request.getLocales();
while (locales.hasMoreElements()) {
Locale locale = locales.nextElement();
saved.addLocale(locale);
}
// May need to acknowledge a 100-continue expectation
request.getResponse().sendAcknowledgement();
ByteChunk body = new ByteChunk();
body.setLimit(request.getConnector().getMaxSavePostSize());
byte[] buffer = new byte[4096];
int bytesRead;
InputStream is = request.getInputStream();
while ( (bytesRead = is.read(buffer) ) >= 0) {
body.append(buffer, 0, bytesRead);
}
// Only save the request body if there is something to save
if (body.getLength() > 0) {
saved.setContentType(request.getContentType());
saved.setBody(body);
}
saved.setMethod(request.getMethod());
saved.setQueryString(request.getQueryString());
saved.setRequestURI(request.getRequestURI());
saved.setDecodedRequestURI(request.getDecodedRequestURI());
// Stash the SavedRequest in our session for later use
session.setNote(Constants.FORM_REQUEST_NOTE, saved);
}
示例8: write
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* This method will write the contents of the specified message bytes
* buffer to the output stream, without filtering. This method is meant to
* be used to write the response header.
*
* @param bc data to be written
*/
protected void write(ByteChunk bc) {
// Writing the byte chunk to the output buffer
int length = bc.getLength();
checkLengthBeforeWrite(length);
System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, length);
pos = pos + length;
}
示例9: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
public int doWrite(ByteChunk chunk, Response res)
throws IOException {
if (!response.isCommitted()) {
// Validate and write response headers
try {
prepareResponse();
} catch (IOException e) {
// Set error flag
error = true;
}
}
int len = chunk.getLength();
// 4 - hardcoded, byte[] marshalling overhead
int chunkSize = Constants.MAX_SEND_SIZE;
int off = 0;
while (len > 0) {
int thisTime = len;
if (thisTime > chunkSize) {
thisTime = chunkSize;
}
len -= thisTime;
responseHeaderMessage.reset();
responseHeaderMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK);
responseHeaderMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime);
responseHeaderMessage.end();
output.write(responseHeaderMessage.getBuffer(), 0, responseHeaderMessage.getLen());
off += thisTime;
}
return chunk.getLength();
}
示例10: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write some bytes.
*
* @return number of bytes written by the filter
*/
@Override
public int doWrite(ByteChunk chunk, Response res) throws IOException {
if (compressionStream == null) {
compressionStream = new FlushableGZIPOutputStream(fakeOutputStream);
}
compressionStream.write(chunk.getBytes(), chunk.getStart(), chunk.getLength());
return chunk.getLength();
}
示例11: doRead
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Fills the given ByteChunk with the buffered request body.
*/
public int doRead(ByteChunk chunk, Request request) throws IOException {
if (hasRead || buffered.getLength() <= 0) {
return -1;
} else {
chunk.setBytes(buffered.getBytes(), buffered.getStart(),
buffered.getLength());
hasRead = true;
}
return chunk.getLength();
}
示例12: parseHost
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Parse host.
*/
protected void parseHost(MessageBytes valueMB) {
if (valueMB == null || valueMB.isNull()) {
// HTTP/1.0
// If no host header, use the port info from the endpoint
// The host will be obtained lazily from the socket if required
// using ActionCode#REQ_LOCAL_NAME_ATTRIBUTE
request.setServerPort(endpoint.getPort());
return;
}
ByteChunk valueBC = valueMB.getByteChunk();
byte[] valueB = valueBC.getBytes();
int valueL = valueBC.getLength();
int valueS = valueBC.getStart();
int colonPos = -1;
if (hostNameC.length < valueL) {
hostNameC = new char[valueL];
}
boolean ipv6 = (valueB[valueS] == '[');
boolean bracketClosed = false;
for (int i = 0; i < valueL; i++) {
char b = (char) valueB[i + valueS];
hostNameC[i] = b;
if (b == ']') {
bracketClosed = true;
} else if (b == ':') {
if (!ipv6 || bracketClosed) {
colonPos = i;
break;
}
}
}
if (colonPos < 0) {
if (!endpoint.isSSLEnabled()) {
// 80 - Default HTTP port
request.setServerPort(80);
} else {
// 443 - Default HTTPS port
request.setServerPort(443);
}
request.serverName().setChars(hostNameC, 0, valueL);
} else {
request.serverName().setChars(hostNameC, 0, colonPos);
int port = 0;
int mult = 1;
for (int i = valueL - 1; i > colonPos; i--) {
int charValue = HexUtils.getDec(valueB[i + valueS]);
if (charValue == -1 || charValue > 9) {
// Invalid character
// 400 - Bad request
response.setStatus(400);
setErrorState(ErrorState.CLOSE_CLEAN, null);
break;
}
port = port + (charValue * mult);
mult = 10 * mult;
}
request.setServerPort(port);
}
}
示例13: parseHost
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Parse host.
*/
public void parseHost(MessageBytes valueMB) {
if (valueMB == null || (valueMB != null && valueMB.isNull()) ) {
// HTTP/1.0
request.setServerPort(request.getLocalPort());
try {
request.serverName().duplicate(request.localName());
} catch (IOException e) {
response.setStatus(400);
error = true;
}
return;
}
ByteChunk valueBC = valueMB.getByteChunk();
byte[] valueB = valueBC.getBytes();
int valueL = valueBC.getLength();
int valueS = valueBC.getStart();
int colonPos = -1;
if (hostNameC.length < valueL) {
hostNameC = new char[valueL];
}
boolean ipv6 = (valueB[valueS] == '[');
boolean bracketClosed = false;
for (int i = 0; i < valueL; i++) {
char b = (char) valueB[i + valueS];
hostNameC[i] = b;
if (b == ']') {
bracketClosed = true;
} else if (b == ':') {
if (!ipv6 || bracketClosed) {
colonPos = i;
break;
}
}
}
if (colonPos < 0) {
if (request.scheme().equalsIgnoreCase("https")) {
// 443 - Default HTTPS port
request.setServerPort(443);
} else {
// 80 - Default HTTTP port
request.setServerPort(80);
}
request.serverName().setChars(hostNameC, 0, valueL);
} else {
request.serverName().setChars(hostNameC, 0, colonPos);
int port = 0;
int mult = 1;
for (int i = valueL - 1; i > colonPos; i--) {
int charValue = HexUtils.DEC[(int) valueB[i + valueS]];
if (charValue == -1) {
// Invalid character
error = true;
// 400 - Bad request
response.setStatus(400);
break;
}
port = port + (charValue * mult);
mult = 10 * mult;
}
request.setServerPort(port);
}
}
示例14: doWrite
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/**
* Write chunk.
*/
@Override
public int doWrite(ByteChunk chunk, Response res)
throws IOException {
if (!response.isCommitted()) {
// Validate and write response headers
try {
prepareResponse();
} catch (IOException e) {
setErrorState(ErrorState.CLOSE_NOW, e);
}
}
if (!swallowResponse) {
try {
int len = chunk.getLength();
// 4 - hardcoded, byte[] marshaling overhead
// Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE;
int off = 0;
while (len > 0) {
int thisTime = len;
if (thisTime > chunkSize) {
thisTime = chunkSize;
}
len -= thisTime;
responseMessage.reset();
responseMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK);
responseMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime);
responseMessage.end();
output(responseMessage.getBuffer(), 0, responseMessage.getLen());
off += thisTime;
}
bytesWritten += chunk.getLength();
} catch (IOException ioe) {
response.action(ActionCode.CLOSE_NOW, ioe);
// Re-throw
throw ioe;
}
}
return chunk.getLength();
}
示例15: processCookies
import org.apache.tomcat.util.buf.ByteChunk; //导入方法依赖的package包/类
/** Add all Cookie found in the headers of a request.
*/
public void processCookies( MimeHeaders headers ) {
if( headers==null ) {
return;// nothing to process
}
// process each "cookie" header
int pos=0;
while( pos>=0 ) {
// Cookie2: version ? not needed
pos=headers.findHeader( "Cookie", pos );
// no more cookie headers headers
if( pos<0 ) {
break;
}
MessageBytes cookieValue=headers.getValue( pos );
if( cookieValue==null || cookieValue.isNull() ) {
pos++;
continue;
}
if( cookieValue.getType() != MessageBytes.T_BYTES ) {
Exception e = new Exception();
log.warn("Cookies: Parsing cookie as String. Expected bytes.",
e);
cookieValue.toBytes();
}
if(log.isDebugEnabled()) {
log.debug("Cookies: Parsing b[]: " + cookieValue.toString());
}
ByteChunk bc=cookieValue.getByteChunk();
if (CookieSupport.PRESERVE_COOKIE_HEADER) {
int len = bc.getLength();
if (len > 0) {
byte[] buf = new byte[len];
System.arraycopy(bc.getBytes(), bc.getOffset(), buf, 0, len);
processCookieHeader(buf, 0, len);
}
} else {
processCookieHeader( bc.getBytes(),
bc.getOffset(),
bc.getLength());
}
pos++;// search from the next position
}
}