@Test public void testIterableSliceWithRepeatingByteSourceLargerPartSize() throws IOException { PayloadSlicer slicer = new BasePayloadSlicer(); ByteSource byteSource = ByteSource.wrap("aaaaaaaaaabbbbbbbbbbccccc".getBytes(Charsets.UTF_8)); Payload payload = new ByteSourcePayload(byteSource); Iterator<Payload> iter = slicer.slice(payload, 50).iterator(); Payload part; assertTrue(iter.hasNext(), "Not enough results"); part = iter.next(); assertEquals(Strings2.toStringAndClose(part.getInput()), "aaaaaaaaaabbbbbbbbbbccccc"); assertEquals(part.getContentMetadata().getContentLength(), Long.valueOf(25)); assertFalse(iter.hasNext()); }
@Override public Payload slice(Payload input, long offset, long length) { checkNotNull(input); checkArgument(offset >= 0, "offset is negative"); checkArgument(length >= 0, "length is negative"); Payload returnVal; if (input.getRawContent() instanceof File) { returnVal = doSlice((File) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof String) { returnVal = doSlice((String) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof byte[]) { returnVal = doSlice((byte[]) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof InputStream) { returnVal = doSlice((InputStream) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof ByteSource) { returnVal = doSlice((ByteSource) input.getRawContent(), offset, length); } else { returnVal = doSlice(input, offset, length); } return copyMetadataAndSetLength(input, returnVal, length); }
BasePayloadSlicer implements PayloadSlicer { @Override public Payload slice(Payload input, long offset, long length) { checkNotNull(input); checkArgument(offset >= 0, "offset is negative"); checkArgument(length >= 0, "length is negative"); Payload returnVal; if (input.getRawContent() instanceof File) { returnVal = doSlice((File) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof String) { returnVal = doSlice((String) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof byte[]) { returnVal = doSlice((byte[]) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof InputStream) { returnVal = doSlice((InputStream) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof ByteSource) { returnVal = doSlice((ByteSource) input.getRawContent(), offset, length); } else { returnVal = doSlice(input, offset, length); } return copyMetadataAndSetLength(input, returnVal, length); } }
BasePayloadSlicer implements PayloadSlicer { @Override public Payload slice(Payload input, long offset, long length) { checkNotNull(input); checkArgument(offset >= 0, "offset is negative"); checkArgument(length >= 0, "length is negative"); Payload returnVal; if (input.getRawContent() instanceof File) { returnVal = doSlice((File) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof String) { returnVal = doSlice((String) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof byte[]) { returnVal = doSlice((byte[]) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof InputStream) { returnVal = doSlice((InputStream) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof ByteSource) { returnVal = doSlice((ByteSource) input.getRawContent(), offset, length); } else { returnVal = doSlice(input, offset, length); } return copyMetadataAndSetLength(input, returnVal, length); }  }
BasePayloadSlicer implements PayloadSlicer { @Override public Payload slice(Payload input, long offset, long length) { checkNotNull(input); checkArgument(offset >= 0, "offset is negative"); checkArgument(length >= 0, "length is negative"); Payload returnVal; if (input.getRawContent() instanceof File) { returnVal = doSlice((File) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof String) { returnVal = doSlice((String) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof byte[]) { returnVal = doSlice((byte[]) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof InputStream) { returnVal = doSlice((InputStream) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof ByteSource) { returnVal = doSlice((ByteSource) input.getRawContent(), offset, length); } else { returnVal = doSlice(input, offset, length); } return copyMetadataAndSetLength(input, returnVal, length); }  @Override Payload slice(Payload input, long offset, long length); @Override Iterable<Payload> slice(Payload input, long size); }
BasePayloadSlicer implements PayloadSlicer { @Override public Payload slice(Payload input, long offset, long length) { checkNotNull(input); checkArgument(offset >= 0, "offset is negative"); checkArgument(length >= 0, "length is negative"); Payload returnVal; if (input.getRawContent() instanceof File) { returnVal = doSlice((File) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof String) { returnVal = doSlice((String) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof byte[]) { returnVal = doSlice((byte[]) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof InputStream) { returnVal = doSlice((InputStream) input.getRawContent(), offset, length); } else if (input.getRawContent() instanceof ByteSource) { returnVal = doSlice((ByteSource) input.getRawContent(), offset, length); } else { returnVal = doSlice(input, offset, length); } return copyMetadataAndSetLength(input, returnVal, length); }  @Override Payload slice(Payload input, long offset, long length); @Override Iterable<Payload> slice(Payload input, long size);  }