HttpsHeaderParser extends Parser<HttpsHeader> { @Override public HttpsHeader parse() { HttpsHeader header; String parsedLine = parseStringTill((byte) 0x0A); String[] split = parsedLine.split(": "); if (split.length < 2) { throw new ParserException("Could not parse " + parsedLine + " as HttpsHeader"); } String headerName = split[0]; String headerValue = parsedLine.replaceFirst(split[0] + ":", "").replaceAll("\n", "").replaceAll("\r", "") .trim(); switch (headerName) { case "Host": header = new HostHeader(); break; case "Sec-Token-Binding": header = new TokenBindingHeader(); break; case "Location": header = new LocationHeader(); break; case "Content-Length": header = new ContentLengthHeader(); break; case "Expires": header = new ExpiresHeader(); break; case "Date": header = new DateHeader(); break; default: header = new GenericHttpsHeader(); } header.setHeaderName(headerName); header.setHeaderValue(headerValue); return header; } HttpsHeaderParser(int startposition, byte[] array); @Override HttpsHeader parse();  }
@Test public void testParse() { HttpsHeaderParser parser = new HttpsHeaderParser(start, message); HttpsHeader header = parser.parse(); assertEquals(headerName, header.getHeaderName().getValue()); assertEquals(headerValue, header.getHeaderValue().getValue()); }