RangePartHeaderSerializer implements Serializer<RangePartHeader> { @Override public String serialize(final RangePartHeader input) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(DASH_DASH) .append(input.getBoundary()) .append(NEW_LINE) .append(Headers.HEADER_CONTENT_TYPE) .append(": ") .append(input.getContentType()) .append(NEW_LINE) .append(Headers.HEADER_CONTENT_RANGE) .append(": bytes ") .append(input.getRange().getFrom()) .append("-") .append(input.getRange().getTo()) .append("/") .append(input.getTotalLength()) .append(NEW_LINE) .append(NEW_LINE); return stringBuilder.toString(); }  @Override String serialize(final RangePartHeader input); String serializeLastBoundaryDeliminator(final String boundary); long getPartHeadersLength(final List<Range> ranges,
                                     final String boundary,
                                     final String contentType,
                                     final long totalLength);  }
@Test public void shouldSerializeRangeProperly() { Range range = new Range(333L, 1234L); String boundary = "BBBOOUUNNNDDAARRYY"; String contentType = "application/pdf"; long totalLength = 12345L; RangePartHeader rangePartHeader = new RangePartHeader(range, boundary, contentType, totalLength); String serialized = rangePartHeaderSerializer.serialize(rangePartHeader); assertThat(serialized, startsWith("--" + boundary + "\r\n")); assertThat(serialized, endsWith("\r\n\r\n")); assertThat(serialized, containsString("\r\nContent-Type: " + contentType + "\r\n")); assertThat(serialized, containsString("\r\nContent-Range: bytes 333-1234/12345\r\n")); }