public void test_multiple_ranges()

in src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RangeStreamingTest.java [118:152]


    public void test_multiple_ranges() throws IOException {
        GetMethod get = new GetMethod(rootUrl);
        get.setRequestHeader(new Header("Range", "bytes 0-9,-10"));
        int status = httpClient.executeMethod(get);
        assertEquals("Expect 206/PARTIAL CONTENT", 206, status);

        String contentType = get.getResponseHeader("Content-Type").getValue();
        assertTrue("Content Type must be multipart/byteranges",
            contentType.contains("multipart/byteranges"));
        String boundary = contentType.substring(contentType.indexOf("boundary=")
            + "boundary=".length());

        BufferedReader reader = new BufferedReader(new InputStreamReader(
            get.getResponseBodyAsStream()));

        String line = reader.readLine();
        while (!("--" + boundary).equals(line)) {
            line = reader.readLine();
        }

        assertEquals("Expected content to start with boundary",
            "--" + boundary, line);
        assertEntityHeaders(reader, "text/plain", "bytes 0-9/79");
        assertEquals("The quick ", reader.readLine());

        assertEquals("Expected content to start with boundary",
            "--" + boundary, reader.readLine());
        assertEntityHeaders(reader, "text/plain", "bytes 69-78/79");
        assertEquals("corpus sic", reader.readLine());

        char[] buf = new char[boundary.length() + 4];
        reader.read(buf);
        assertEquals("Expected content to start with boundary", "--" + boundary
            + "--", new String(buf));
    }