当前位置: 首页>>代码示例>>Java>>正文


Java CharChunk.append方法代码示例

本文整理汇总了Java中org.apache.tomcat.util.buf.CharChunk.append方法的典型用法代码示例。如果您正苦于以下问题:Java CharChunk.append方法的具体用法?Java CharChunk.append怎么用?Java CharChunk.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tomcat.util.buf.CharChunk的用法示例。


在下文中一共展示了CharChunk.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import org.apache.tomcat.util.buf.CharChunk; //导入方法依赖的package包/类
private void sendMessage(String message, boolean finalFragment)
        throws IOException {
    ByteChunk bc = new ByteChunk(8192);
    CharChunk cc = new CharChunk(8192);
    C2BConverter c2b = new C2BConverter("UTF-8");
    cc.append(message);
    c2b.convert(cc, bc);

    int len = bc.getLength();
    assertTrue(len < 126);

    byte first;
    if (isContinuation) {
        first = Constants.OPCODE_CONTINUATION;
    } else {
        first = Constants.OPCODE_TEXT;
    }
    if (finalFragment) {
        first = (byte) (0x80 | first);
    }
    os.write(first);

    os.write(0x80 | len);

    // Zero mask
    os.write(0);
    os.write(0);
    os.write(0);
    os.write(0);

    // Payload
    os.write(bc.getBytes(), bc.getStart(), len);

    os.flush();

    // Will the next frame be a continuation frame
    isContinuation = !finalFragment;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:39,代码来源:TestWebSocket.java

示例2: normalize

import org.apache.tomcat.util.buf.CharChunk; //导入方法依赖的package包/类
private void normalize(CharChunk cc) {
	// Strip query string and/or fragment first as doing it this way makes
	// the normalization logic a lot simpler
	int truncate = cc.indexOf('?');
	if (truncate == -1) {
		truncate = cc.indexOf('#');
	}
	char[] truncateCC = null;
	if (truncate > -1) {
		truncateCC = Arrays.copyOfRange(cc.getBuffer(), cc.getStart() + truncate, cc.getEnd());
		cc.setEnd(cc.getStart() + truncate);
	}

	if (cc.endsWith("/.") || cc.endsWith("/..")) {
		try {
			cc.append('/');
		} catch (IOException e) {
			throw new IllegalArgumentException(cc.toString(), e);
		}
	}

	char[] c = cc.getChars();
	int start = cc.getStart();
	int end = cc.getEnd();
	int index = 0;
	int startIndex = 0;

	// Advance past the first three / characters (should place index just
	// scheme://host[:port]

	for (int i = 0; i < 3; i++) {
		startIndex = cc.indexOf('/', startIndex + 1);
	}

	// Remove /./
	index = startIndex;
	while (true) {
		index = cc.indexOf("/./", 0, 3, index);
		if (index < 0) {
			break;
		}
		copyChars(c, start + index, start + index + 2, end - start - index - 2);
		end = end - 2;
		cc.setEnd(end);
	}

	// Remove /../
	index = startIndex;
	int pos;
	while (true) {
		index = cc.indexOf("/../", 0, 4, index);
		if (index < 0) {
			break;
		}
		// Can't go above the server root
		if (index == startIndex) {
			throw new IllegalArgumentException();
		}
		int index2 = -1;
		for (pos = start + index - 1; (pos >= 0) && (index2 < 0); pos--) {
			if (c[pos] == (byte) '/') {
				index2 = pos;
			}
		}
		copyChars(c, start + index2, start + index + 3, end - start - index - 3);
		end = end + index2 - index - 3;
		cc.setEnd(end);
		index = index2;
	}

	// Add the query string and/or fragment (if present) back in
	if (truncateCC != null) {
		try {
			cc.append(truncateCC, 0, truncateCC.length);
		} catch (IOException ioe) {
			throw new IllegalArgumentException(ioe);
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:80,代码来源:Response.java


注:本文中的org.apache.tomcat.util.buf.CharChunk.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。