### Question:
InputStreamWrapper extends InputStream { @Override public synchronized void mark(final int readlimit) { this.mark = this.head; this.readLimit = readlimit; final int len = this.tail - this.head; if (len == 0) { this.base.mark(readlimit); } else if (len < readlimit) { this.base.mark(readlimit - len); } else { } } 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 testMark() throws Exception { final int loop = 10_000; final int length = 1000; final Charset charset = Charset.defaultCharset(); final String separator = "\r\n"; final ByteArrayOutputStream output = new ByteArrayOutputStream(); for (int i = 0; i < loop; i++) { final String sample = RandomString.nextAsciiString(length / 3, ThreadLocalRandom.current()); output.write(sample.getBytes(charset)); output.write(separator.getBytes(charset)); } final InputStream rival = new ByteArrayInputStream(output.toByteArray()); final InputStreamWrapper instance = new InputStreamWrapper(new ByteArrayInputStream(output.toByteArray()), charset, separator, length); final byte[] buff1 = new byte[length]; final byte[] buff2 = new byte[length]; boolean marked = false; int len = 0; while (true) { if (marked) { if (len == length || ThreadLocalRandom.current().nextInt(4) == 0) { rival.reset(); instance.reset(); marked = false; } else { final int size = ThreadLocalRandom.current().nextInt(length - len); final int len1 = rival.read(buff1, 0, size); final int len2 = instance.read(buff2, 0, size); if (len1 < 0) { Assert.assertEquals(len1, len2); break; } Assert.assertArrayEquals(buff1, buff2); len += size; } } else { if (ThreadLocalRandom.current().nextInt(4) == 0) { rival.mark(length); instance.mark(length); marked = true; len = 0; } else if (ThreadLocalRandom.current().nextBoolean()) { final int size = ThreadLocalRandom.current().nextInt(length); final int len1 = rival.read(buff1, 0, size); final int len2 = instance.read(buff2, 0, size); if (len1 < 0) { Assert.assertEquals(len1, len2); break; } Assert.assertArrayEquals(buff1, buff2); } else { final String line = instance.readLine(); if (line == null) { Assert.assertEquals(-1, rival.read()); break; } else { final byte[] buff3 = line.getBytes(charset); final byte[] buff4 = StreamFunctions.completeRead(rival, buff3.length); Assert.assertEquals(new String(buff4, charset), line); rival.skip(separator.getBytes(charset).length); } } } } instance.close(); }