本文整理汇总了Java中org.apache.tomcat.util.buf.MessageBytes.setChars方法的典型用法代码示例。如果您正苦于以下问题:Java MessageBytes.setChars方法的具体用法?Java MessageBytes.setChars怎么用?Java MessageBytes.setChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.buf.MessageBytes
的用法示例。
在下文中一共展示了MessageBytes.setChars方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertMB
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的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: convertMB
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的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);
}
示例3: convertMB
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的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);
}
示例4: testContextListConcurrencyBug56653
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
@Test
public void testContextListConcurrencyBug56653() throws Exception {
final Object host = new Object(); // "localhost";
final Object contextRoot = new Object(); // "ROOT";
final Object context1 = new Object(); // "foo";
final Object context2 = new Object(); // "foo#bar";
final Object context3 = new Object(); // "foo#bar#bla";
final Object context4 = new Object(); // "foo#bar#bla#baz";
mapper.addHost("localhost", new String[] { "alias" }, host);
mapper.setDefaultHostName("localhost");
mapper.addContextVersion("localhost", host, "", "0", contextRoot,
new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo", "0", context1,
new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo/bar", "0", context2,
new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo/bar/bla", "0",
context3, new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo/bar/bla/baz", "0",
context4, new String[0], null, null, false, false);
final AtomicBoolean running = new AtomicBoolean(true);
Thread t = new Thread() {
@Override
public void run() {
for (int i = 0; i < 100000; i++) {
mapper.removeContextVersion("localhost",
"/foo/bar/bla/baz", "0");
mapper.addContextVersion("localhost", host,
"/foo/bar/bla/baz", "0", context4, new String[0],
null, null, false, false);
}
running.set(false);
}
};
MappingData mappingData = new MappingData();
MessageBytes hostMB = MessageBytes.newInstance();
hostMB.setString("localhost");
MessageBytes aliasMB = MessageBytes.newInstance();
aliasMB.setString("alias");
MessageBytes uriMB = MessageBytes.newInstance();
char[] uri = "/foo/bar/bla/bobou/foo".toCharArray();
uriMB.setChars(uri, 0, uri.length);
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
mappingData.recycle();
uriMB.setChars(uri, 0, uri.length);
mapper.map(aliasMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
t.start();
while (running.get()) {
mappingData.recycle();
uriMB.setChars(uri, 0, uri.length);
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
mappingData.recycle();
uriMB.setChars(uri, 0, uri.length);
mapper.map(aliasMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
}
}