/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.tomcat.util.buf;
/* * Test for {@code findByte} vs. {@code indexOf} methods difference. * * <p> * As discussed in the "Re: r944918" thread on dev@, {@code * ByteChunk.indexOf()} works for 0-127 ASCII chars only, and cannot find * any chars outside of the range. {@code ByteChunk.findByte()} works for * any ISO-8859-1 chars.
*/
@Test publicvoid testFindByte() throws UnsupportedEncodingException { // 0xa0 = 160 = character byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1"); finalint len = bytes.length;
// indexOf() does not work outside of 0-127 Assert.assertEquals(5, ByteChunk.findByte(bytes, 0, len, (byte) '\u00a0')); Assert.assertEquals(-1, ByteChunk.indexOf(bytes, 0, len, '\u00a0'));
@Ignore // Requires a 6GB heap (on markt's desktop - YMMV)
@Test publicvoid testAppend() throws Exception {
ByteChunk bc = new ByteChunk();
bc.setByteOutputChannel(new Sink()); // Defaults to no limit
byte data[] = newbyte[32 * 1024 * 1024];
for (int i = 0; i < 100; i++) {
bc.append(data, 0, data.length);
}
@Test publicvoid testToString() {
ByteChunk bc = new ByteChunk(); Assert.assertNull(bc.toString()); byte[] data = newbyte[8];
bc.setBytes(data, 0, data.length); Assert.assertNotNull(bc.toString());
bc.recycle(); // toString() should behave consistently for new ByteChunk and // immediately after a call to recycle(). Assert.assertNull(bc.toString());
}
}
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.