Parser { protected String parseStringTill(byte endSequence) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); while (true) { byte b = parseByteField(1); stream.write(b); if (b == endSequence) { return new String(stream.toByteArray()); } } } Parser(int startposition, byte[] array); int getPointer(); void setPointer(int pointer); int getStartPoint(); abstract T parse();  }
@Test public void testParseString() { byte[] bytesToParse = "This is a test\t\nabc".getBytes(Charset.defaultCharset()); parser = new ParserImpl(0, bytesToParse); assertEquals("This is a test\t\n", parser.parseStringTill((byte) 0x0A)); }