@Test public void testMaxLengthCheckEquals() throws IOException { long maxLength = 50; PipedInputStream inputStream = getInputStream(maxLength); IOHelper.write(inputStream, new NullOutputStream(), maxLength); }
public static long write(InputStream in, OutputStream out, long maxLength) throws IOException { byte[] b = new byte[1024]; int len; long overall = 0; do { len = in.read(b); if (len > 0) { overall += len; out.write(b, 0, len); } if (maxLength > 0 && maxLength < overall) { throw new MaxLengthReachedException(); } } while (len > 0); return overall; }
IOHelper { public static long write(InputStream in, OutputStream out, long maxLength) throws IOException { byte[] b = new byte[1024]; int len; long overall = 0; do { len = in.read(b); if (len > 0) { overall += len; out.write(b, 0, len); } if (maxLength > 0 && maxLength < overall) { throw new MaxLengthReachedException(); } } while (len > 0); return overall; } }
IOHelper { public static long write(InputStream in, OutputStream out, long maxLength) throws IOException { byte[] b = new byte[1024]; int len; long overall = 0; do { len = in.read(b); if (len > 0) { overall += len; out.write(b, 0, len); } if (maxLength > 0 && maxLength < overall) { throw new MaxLengthReachedException(); } } while (len > 0); return overall; } private  IOHelper(); }
IOHelper { public static long write(InputStream in, OutputStream out, long maxLength) throws IOException { byte[] b = new byte[1024]; int len; long overall = 0; do { len = in.read(b); if (len > 0) { overall += len; out.write(b, 0, len); } if (maxLength > 0 && maxLength < overall) { throw new MaxLengthReachedException(); } } while (len > 0); return overall; } private  IOHelper(); static void close(AutoCloseable closable); static void close(Closeable closeable); static long write(InputStream in, OutputStream out, long maxLength); }
IOHelper { public static long write(InputStream in, OutputStream out, long maxLength) throws IOException { byte[] b = new byte[1024]; int len; long overall = 0; do { len = in.read(b); if (len > 0) { overall += len; out.write(b, 0, len); } if (maxLength > 0 && maxLength < overall) { throw new MaxLengthReachedException(); } } while (len > 0); return overall; } private  IOHelper(); static void close(AutoCloseable closable); static void close(Closeable closeable); static long write(InputStream in, OutputStream out, long maxLength);  }