### Question:
StreamFunctions { public static int completeSkip(final InputStream input, final int length) throws MyRuleException, IOException { for (int i = 0, l; i < length; i += l) { if (isEof(input)) { throw new MyRuleException("Skip only " + i + " bytes smaller than required size ( " + length + " )."); } l = (int) input.skip(length - i); } return length; } private  StreamFunctions(); static byte[] completeRead(final InputStream input, final int length); static int completeRead(final InputStream input, final byte[] out, final int offset, final int length); static int completeSkip(final InputStream input, final int length); static boolean isEof(final InputStream input);  }### Answer:
@Test(expected = MyRuleException.class) public void testCompleteSkipEof() throws MyRuleException, IOException { final byte[] buff = new byte[100]; try (final InputStream rawInput = new ByteArrayInputStream(buff); final InputStream input = new BufferedInputStream(rawInput)) { StreamFunctions.completeSkip(input, 150); } }
@Test public void testCompleteSkip() throws MyRuleException, IOException { final int[] lengths = new int[20]; final long seed = System.nanoTime(); final Random random = new Random(seed); final int maxLength = 500; int sum = 0; for (int i = 0; i < lengths.length; i++) { lengths[i] = random.nextInt(maxLength); sum += lengths[i]; } final byte[] buff = new byte[sum]; try (final ByteArrayInputStream rawInput = new ByteArrayInputStream(buff); final InputStream input = new BufferedInputStream(rawInput)) { for (final int length : lengths) { StreamFunctions.completeSkip(input, length); } Assert.assertTrue(StreamFunctions.isEof(input)); } }