### Question:
InputStreamWrapper extends InputStream { public String readLine() throws IOException, MyRuleException { for (int pointer = this.head;;) { if (pointer + this.separator.length > this.tail) { if (this.tail - this.head == this.buff.length) { throw new MyRuleException("Too long line over limit ( " + (this.buff.length - this.separator.length) + " )."); } pointer -= this.head; shift(); if (fill()) { if (this.head == this.tail) { return null; } else { final String line = new String(this.buff, this.head, this.tail - this.head, this.charset); this.head = this.tail; return line; } } } final int index = BytesFunctions.indexOf(this.buff, this.separator, pointer, this.tail); if (index < 0) { pointer = Math.max(0, this.tail - (this.separator.length - 1)); continue; } final String line = new String(this.buff, this.head, index - this.head, this.charset); this.head = index + this.separator.length; return line; } } InputStreamWrapper(final InputStream base, final Charset charset, final String separator, final int lineSize); String readLine(); @Override void close(); @Override int read(); @Override int read(final byte[] b); @Override int read(final byte[] b, final int off, final int len); @Override long skip(final long n); @Override int available(); @Override synchronized void mark(final int readlimit); @Override synchronized void reset(); @Override boolean markSupported(); @SuppressWarnings("javadoc") static void main(final String[] args);  }### Answer:
@Test public void testSample() throws Exception { final Random random = new Random(); final int loop = 100_000; final int length = 1_000; final String separator = "\r\n"; final List<String> samples = new ArrayList<>(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); for (int i = 0; i < loop; i++) { final String sample = RandomString.nextString(length / 3, random); samples.add(sample); output.write(sample.getBytes()); output.write(separator.getBytes()); } try (final InputStreamWrapper input = new InputStreamWrapper(new ByteArrayInputStream(output.toByteArray()), Charset.defaultCharset(), separator, length)) { for (int i = 0; i < samples.size(); i++) { final String line = input.readLine(); Assert.assertEquals(samples.get(i), line); } Assert.assertNull(input.readLine()); } }