@Test public void testHeaderFormattingInvalidInput() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(64); final Header header = new BasicHeader("name", "value"); try { this.formatter.formatHeader(null, header); Assert.fail("NullPointerException should habe been thrown"); } catch (final NullPointerException ex) { } try { this.formatter.formatHeader(buf, null); Assert.fail("NullPointerException should habe been thrown"); } catch (final NullPointerException ex) { } }
@Override public void formatHeader(final CharArrayBuffer buffer, final Header header) { Args.notNull(buffer, "Char array buffer"); Args.notNull(header, "Header"); buffer.append(header.getName()); buffer.append(": "); final String value = header.getValue(); if (value != null) { buffer.ensureCapacity(buffer.length() + value.length()); for (int valueIndex = 0; valueIndex < value.length(); valueIndex++) { char valueChar = value.charAt(valueIndex); if (valueChar == '\r' || valueChar == '\n' || valueChar == '\f' || valueChar == 0x0b) { valueChar = ' '; } buffer.append(valueChar); } } }
BasicLineFormatter implements LineFormatter { @Override public void formatHeader(final CharArrayBuffer buffer, final Header header) { Args.notNull(buffer, "Char array buffer"); Args.notNull(header, "Header"); buffer.append(header.getName()); buffer.append(": "); final String value = header.getValue(); if (value != null) { buffer.ensureCapacity(buffer.length() + value.length()); for (int valueIndex = 0; valueIndex < value.length(); valueIndex++) { char valueChar = value.charAt(valueIndex); if (valueChar == '\r' || valueChar == '\n' || valueChar == '\f' || valueChar == 0x0b) { valueChar = ' '; } buffer.append(valueChar); } } } }
BasicLineFormatter implements LineFormatter { @Override public void formatHeader(final CharArrayBuffer buffer, final Header header) { Args.notNull(buffer, "Char array buffer"); Args.notNull(header, "Header"); buffer.append(header.getName()); buffer.append(": "); final String value = header.getValue(); if (value != null) { buffer.ensureCapacity(buffer.length() + value.length()); for (int valueIndex = 0; valueIndex < value.length(); valueIndex++) { char valueChar = value.charAt(valueIndex); if (valueChar == '\r' || valueChar == '\n' || valueChar == '\f' || valueChar == 0x0b) { valueChar = ' '; } buffer.append(valueChar); } } } BasicLineFormatter(); }
BasicLineFormatter implements LineFormatter { @Override public void formatHeader(final CharArrayBuffer buffer, final Header header) { Args.notNull(buffer, "Char array buffer"); Args.notNull(header, "Header"); buffer.append(header.getName()); buffer.append(": "); final String value = header.getValue(); if (value != null) { buffer.ensureCapacity(buffer.length() + value.length()); for (int valueIndex = 0; valueIndex < value.length(); valueIndex++) { char valueChar = value.charAt(valueIndex); if (valueChar == '\r' || valueChar == '\n' || valueChar == '\f' || valueChar == 0x0b) { valueChar = ' '; } buffer.append(valueChar); } } } BasicLineFormatter(); @Override void formatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline); @Override void formatStatusLine(final CharArrayBuffer buffer, final StatusLine statusLine); @Override void formatHeader(final CharArrayBuffer buffer, final Header header); }
BasicLineFormatter implements LineFormatter { @Override public void formatHeader(final CharArrayBuffer buffer, final Header header) { Args.notNull(buffer, "Char array buffer"); Args.notNull(header, "Header"); buffer.append(header.getName()); buffer.append(": "); final String value = header.getValue(); if (value != null) { buffer.ensureCapacity(buffer.length() + value.length()); for (int valueIndex = 0; valueIndex < value.length(); valueIndex++) { char valueChar = value.charAt(valueIndex); if (valueChar == '\r' || valueChar == '\n' || valueChar == '\f' || valueChar == 0x0b) { valueChar = ' '; } buffer.append(valueChar); } } } BasicLineFormatter(); @Override void formatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline); @Override void formatStatusLine(final CharArrayBuffer buffer, final StatusLine statusLine); @Override void formatHeader(final CharArrayBuffer buffer, final Header header); final static BasicLineFormatter INSTANCE; }