I considered your feedback and updated the code. 

I stumbled upon another issue. 
It is a combination of `ByteSources.repeatingArrayByteSource(...)` and  
`PayloadSlicer.slice(Payload, Int)` method.

Have a look at this test case

    @Test
    public void testIterableSliceWithRepeatingByteSource() throws IOException {
        String content = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"; /* 53 chars */
        byte[] contentBytes = content.getBytes(Charsets.UTF_8);
        ByteSource byteSource = 
ByteSources.repeatingArrayByteSource(contentBytes).slice(0, 1024);

        PayloadSlicer slicer = new BasePayloadSlicer();
        Payload payload = new ByteSourcePayload(byteSource);

        Iterable<Payload> slice = slicer.slice(payload, 100);
        Iterable<Payload> slice2 = slicer.slice(payload, 53);
        int count1 = 0, count2 = 0;
        for (Payload eachPayload : slice) count1++;
        for (Payload eachPayload : slice2) count2++;
        assertNotEquals(20, count2);
        assertEquals(11, count1);
    }

The correct slice count would be 11, but it is actually 20. 
This problem should always occur when:

Using `Bytesources.repeatingArrayByteSource(someArray)` method and the chunk 
size is greater than the length of `someArray` (e.g. 100 vs 53). Then 
`slicer.slice(payload, chunkSize)` will always return a Payload with content 
length of `someArray.length` (e.g. 53)

    

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/427#issuecomment-47757796

Reply via email to