public StringAsyncEntityConsumer(final int capacityIncrement) { Args.positive(capacityIncrement, "Capacity increment"); this.capacityIncrement = capacityIncrement; this.content = new CharArrayBuffer(1024); }
List<NameValuePair> parse(final String s) { if (s == null) { return null; } final CharArrayBuffer buffer = new CharArrayBuffer(s.length()); buffer.append(s); final ParserCursor cursor = new ParserCursor(0, s.length()); return parse(buffer, cursor); }
public static Header format(final String name, final Set<String> tokens) { Args.notBlank(name, "Header name"); if (tokens == null || tokens.isEmpty()) { return null; } final CharArrayBuffer buffer = new CharArrayBuffer(256); buffer.append(name); buffer.append(": "); formatTokens(buffer, tokens); return BufferedHeader.create(buffer); }
@Test(expected=CharacterCodingException.class) public void testMalformedInputActionReport() throws Exception { final byte[] tmp = constructString(SWISS_GERMAN_HELLO).getBytes(StandardCharsets.ISO_8859_1); final CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPORT); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, decoder); final ByteArrayInputStream inputStream = new ByteArrayInputStream(tmp); final CharArrayBuffer chbuffer = new CharArrayBuffer(32); inBuffer.readLine(chbuffer, inputStream); }
public static Header format(final String name, final String... tokens) { Args.notBlank(name, "Header name"); if (tokens == null || tokens.length == 0) { return null; } final CharArrayBuffer buffer = new CharArrayBuffer(256); buffer.append(name); buffer.append(": "); formatTokens(buffer, tokens); return BufferedHeader.create(buffer); }
@Test(expected=CharacterCodingException.class) public void testUnmappableInputActionReport() throws Exception { final String s = "This text contains a circumflex \u0302 !!!"; final CharsetEncoder encoder = StandardCharsets.ISO_8859_1.newEncoder(); encoder.onMalformedInput(CodingErrorAction.IGNORE); encoder.onUnmappableCharacter(CodingErrorAction.REPORT); final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(16, encoder); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final CharArrayBuffer chbuffer = new CharArrayBuffer(32); chbuffer.append(s); outbuffer.writeLine(chbuffer, outputStream); }
public static Header format(final String name, final String... tokens) { Args.notBlank(name, "Header name"); if (tokens == null || tokens.length == 0) { return null; } final CharArrayBuffer buffer = new CharArrayBuffer(256); buffer.append(name); buffer.append(": "); formatTokens(buffer, tokens); return BufferedHeader.create(buffer); }
@Test public void testMalformedInputActionReplace() throws Exception { final byte[] tmp = constructString(SWISS_GERMAN_HELLO).getBytes(StandardCharsets.ISO_8859_1); final CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPLACE); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, decoder); final ByteArrayInputStream inputStream = new ByteArrayInputStream(tmp); final CharArrayBuffer chbuffer = new CharArrayBuffer(32); inBuffer.readLine(chbuffer, inputStream); Assert.assertEquals("Gr\ufffdezi_z\ufffdm\ufffd", chbuffer.toString()); }
@Test public void testAppendCharArrayBuffer() throws Exception { final CharArrayBuffer buffer1 = new CharArrayBuffer(8); buffer1.append(" and more stuff"); final CharArrayBuffer buffer2 = new CharArrayBuffer(8); buffer2.append("stuff"); buffer2.append(buffer1); Assert.assertEquals("stuff and more stuff", buffer2.toString()); }
@Test //HTTPCORE-472 public void testLineLimit3() throws Exception { final String s = "012345678\r\nblaaaaaaaaaaaaaaaaaah"; final byte[] tmp = s.getBytes(StandardCharsets.US_ASCII); final SessionInputBuffer inBuffer1 = new SessionInputBufferImpl(128); final ByteArrayInputStream inputStream = new ByteArrayInputStream(tmp); final CharArrayBuffer chbuffer = new CharArrayBuffer(16); inBuffer1.readLine(chbuffer, inputStream); Assert.assertEquals("012345678", chbuffer.toString()); }
@Test public void testAppendNullString() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((String)null); Assert.assertEquals("null", buffer.toString()); }
@Test public void testInputMatchesBufferLength() throws Exception { final String s1 = "abcde"; final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5); final CharArrayBuffer chbuffer = new CharArrayBuffer(16); chbuffer.append(s1); outbuf.writeLine(chbuffer); }
@Test public void testSetLength() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(4); buffer.setLength(2); Assert.assertEquals(2, buffer.length()); }
@Test public void testAppendNullByteArrayBuffer() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((ByteArrayBuffer)null, 0, 0); Assert.assertEquals("", buffer.toString()); }
@Test public void testAppendString() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append("stuff"); buffer.append(" and more stuff"); Assert.assertEquals("stuff and more stuff", buffer.toString()); }
@Test public void testAppendNullCharArrayBuffer() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(8); buffer.append((CharArrayBuffer)null); buffer.append((CharArrayBuffer)null, 0, 0); Assert.assertEquals("", buffer.toString()); }
@Test public void testRLFormatting() throws Exception { final RequestLine requestline = new RequestLine("GET", "/stuff", HttpVersion.HTTP_1_1); final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatRequestLine(buf, requestline); Assert.assertEquals("GET /stuff HTTP/1.1", buf.toString()); }
@Test public void testEnsureCapacity() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(4); buffer.ensureCapacity(2); Assert.assertEquals(4, buffer.capacity()); buffer.ensureCapacity(8); Assert.assertEquals(8, buffer.capacity()); }
@Test public void testAppendSingleChar() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(4); buffer.append('1'); buffer.append('2'); buffer.append('3'); buffer.append('4'); buffer.append('5'); buffer.append('6'); Assert.assertEquals("123456", buffer.toString()); }
@Test public void testSubstring() { final CharArrayBuffer buffer = new CharArrayBuffer(16); buffer.append(" name: value "); Assert.assertEquals(5, buffer.indexOf(':')); Assert.assertEquals(" name", buffer.substring(0, 5)); Assert.assertEquals(" value ", buffer.substring(6, buffer.length())); Assert.assertEquals("name", buffer.substringTrimmed(0, 5)); Assert.assertEquals("value", buffer.substringTrimmed(6, buffer.length())); Assert.assertEquals("", buffer.substringTrimmed(13, buffer.length())); }