private int appendLastBoundaryDeliminator(byte[] output, int destPos) { byte[] slice = (NEW_LINE + rangePartHeaderSerializer.serializeLastBoundaryDeliminator(BOUNDARY)) .getBytes(StandardCharsets.UTF_8); System.arraycopy(slice, 0, output, destPos, slice.length); return slice.length; } }
/** * Serves multiple ranges of the input stream to the output stream. * * @param inputStream * @param outputStream * @param rangeList * @param boundary * @param contentType * @param totalLength * @throws IOException */ public void serveMultiRangeStream(final InputStream inputStream, final OutputStream outputStream, final List<Range> rangeList, final String boundary, final String contentType, final long totalLength) throws IOException { inputStream.mark(0); serveMultiRangeStream(new ByteArrayInputStream(NEW_LINE.getBytes(StandardCharsets.UTF_8)), outputStream); for (Range range : rangeList) { doServeRangePartHeader(outputStream, boundary, contentType, totalLength, range); doServeRangeStream(inputStream, outputStream, range); serveMultiRangeStream(new ByteArrayInputStream(NEW_LINE.getBytes(StandardCharsets.UTF_8)), outputStream); } serveMultiRangeStream(new ByteArrayInputStream(rangePartHeaderSerializer .serializeLastBoundaryDeliminator(boundary).getBytes(StandardCharsets.UTF_8)), outputStream); }
partHeadersLength += serializeLastBoundaryDeliminator(boundary).length();