@Test public void testWriteStream() throws Exception { InputStream in = new ByteArrayInputStream("Hello, world!".getBytes()); OutputStream out = new ByteArrayOutputStream(); ByteRange range = new ByteRange(7, 11); DownloadServlet.writeStream(in, out, range); assertEquals("world", out.toString()); }
public static void writeStream(InputStream in, OutputStream out, ByteRange range) throws IOException { BufferingServletOutputStream.stopBuffering(out); byte[] buffer = new byte[BUFFER_SIZE]; long read; long offset = range.getStart(); in.skip(offset); while (offset <= range.getEnd() && (read = in.read(buffer)) != -1) { read = Math.min(read, range.getEnd() - offset + 1); out.write(buffer, 0, (int) read); out.flush(); offset += read; } }
DownloadServlet extends HttpServlet { public static void writeStream(InputStream in, OutputStream out, ByteRange range) throws IOException { BufferingServletOutputStream.stopBuffering(out); byte[] buffer = new byte[BUFFER_SIZE]; long read; long offset = range.getStart(); in.skip(offset); while (offset <= range.getEnd() && (read = in.read(buffer)) != -1) { read = Math.min(read, range.getEnd() - offset + 1); out.write(buffer, 0, (int) read); out.flush(); offset += read; } } }
DownloadServlet extends HttpServlet { public static void writeStream(InputStream in, OutputStream out, ByteRange range) throws IOException { BufferingServletOutputStream.stopBuffering(out); byte[] buffer = new byte[BUFFER_SIZE]; long read; long offset = range.getStart(); in.skip(offset); while (offset <= range.getEnd() && (read = in.read(buffer)) != -1) { read = Math.min(read, range.getEnd() - offset + 1); out.write(buffer, 0, (int) read); out.flush(); offset += read; } }  }
DownloadServlet extends HttpServlet { public static void writeStream(InputStream in, OutputStream out, ByteRange range) throws IOException { BufferingServletOutputStream.stopBuffering(out); byte[] buffer = new byte[BUFFER_SIZE]; long read; long offset = range.getStart(); in.skip(offset); while (offset <= range.getEnd() && (read = in.read(buffer)) != -1) { read = Math.min(read, range.getEnd() - offset + 1); out.write(buffer, 0, (int) read); out.flush(); offset += read; } }  void handleClientDisconnect(IOException ioe); static void writeStream(InputStream in, OutputStream out,
            ByteRange range); static ByteRange parseRange(String range, long fileSize); }
DownloadServlet extends HttpServlet { public static void writeStream(InputStream in, OutputStream out, ByteRange range) throws IOException { BufferingServletOutputStream.stopBuffering(out); byte[] buffer = new byte[BUFFER_SIZE]; long read; long offset = range.getStart(); in.skip(offset); while (offset <= range.getEnd() && (read = in.read(buffer)) != -1) { read = Math.min(read, range.getEnd() - offset + 1); out.write(buffer, 0, (int) read); out.flush(); offset += read; } }  void handleClientDisconnect(IOException ioe); static void writeStream(InputStream in, OutputStream out,
            ByteRange range); static ByteRange parseRange(String range, long fileSize);  }