HttpHeader { public byte[] toWireFormat() { int fieldBodyLength = fieldBody == null ? 0 : fieldBody.length(); int length = fieldName.length() + fieldBodyLength + 2; byte[] bytes = new byte[length]; System.arraycopy(fieldName.getBytes(), 0, bytes, 0, fieldName.length()); bytes[fieldName.length()] = ':'; bytes[fieldName.length() + 1] = ' '; if (fieldBody != null) { System.arraycopy(fieldBody.getBytes(), 0, bytes, fieldName.length() + 2, fieldBodyLength); } return bytes; } HttpHeader(String fieldName, String fieldBody);  HttpHeader(HttpHeaderDefinition headerDefinition, String fieldBody); static HttpHeader parseHeader(byte[] content, int from, int to); String getFieldName(); HttpHeaderDefinition getHeaderDefinition(); String getFieldBody(); byte[] toWireFormat(); @Override String toString();  }
@Test public void toWireFormat() throws Exception { HttpHeader h = new HttpHeader("Some-Field-Name", "some value"); byte[] b = h.toWireFormat(); String expected = "Some-Field-Name: some value"; assertEquals(expected, new String(b)); }
@Test public void toWireFormat_NullBody() throws Exception { HttpHeader h = new HttpHeader("Some-Field-Name", null); byte[] b = h.toWireFormat(); String expected = "Some-Field-Name: "; assertEquals(expected, new String(b)); }