@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
public void testSlice_illegalArguments() { try { source.slice(-1, 0); fail("expected IllegalArgumentException for call to slice with offset -1: " + source); } catch (IllegalArgumentException expected) { } try { source.slice(0, -1); fail("expected IllegalArgumentException for call to slice with length -1: " + source); } catch (IllegalArgumentException expected) { } }
@Override public ByteSource createSource(byte[] bytes) throws IOException { return factory.createSource(bytes).slice(off, len); }
public void testSlice_constrainedRange() throws IOException { long size = source.read().length; if (size >= 2) { ByteSource sliced = source.slice(1, size - 2); assertEquals(size - 2, sliced.read().length); ByteSource resliced = sliced.slice(0, size - 1); assertTrue(sliced.contentEquals(resliced)); } }
/** * @param input the size of the input source * @param offset the first argument to {@link ByteSource#slice} * @param length the second argument to {@link ByteSource#slice} * @param expectRead the number of bytes we expect to read */ private static void assertCorrectSlice(int input, int offset, long length, int expectRead) throws IOException { checkArgument(expectRead == (int) Math.max(0, Math.min(input, offset + length) - offset)); byte[] expected = newPreFilledByteArray(offset, expectRead); ByteSource source = new TestByteSource(newPreFilledByteArray(input)); ByteSource slice = source.slice(offset, length); assertArrayEquals(expected, slice.read()); }
@Override protected void _send(final byte[] bytes) throws Exception { List<Integer[]> lines = split(bytes); if (lines.size() == 1) { data = ByteSource.concat(data, DATA, ByteSource.wrap(bytes), NL); } else { for (Integer[] line : lines) { data = ByteSource.concat(data, DATA, ByteSource.wrap(bytes) .slice(line[0], line[1] - line[0]), NL); } } }
public void testConcat_infiniteIterable() throws IOException { ByteSource source = ByteSource.wrap(new byte[] {0, 1, 2, 3}); Iterable<ByteSource> cycle = Iterables.cycle(ImmutableList.of(source)); ByteSource concatenated = ByteSource.concat(cycle); byte[] expected = {0, 1, 2, 3, 0, 1, 2, 3}; assertArrayEquals(expected, concatenated.slice(0, 8).read()); }
assertTrue(ByteSource.wrap(data).slice(0, chunk1).contentEquals(source));
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); long maxLength = this.length - offset; return ByteSource.this.slice(this.offset + offset, Math.min(length, maxLength)); }
protected Payload doSlice(byte[] content, long offset, long length) { checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array"); checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array"); // TODO(adriancole): Make ByteArrayPayload carry offset, length as opposed to wrapping here. return Payloads.newByteSourcePayload(ByteSource.wrap(content).slice(offset, length)); }
public void testSlice_illegalArguments() { try { source.slice(-1, 0); fail("expected IllegalArgumentException for call to slice with offset -1: " + source); } catch (IllegalArgumentException expected) { } try { source.slice(0, -1); fail("expected IllegalArgumentException for call to slice with length -1: " + source); } catch (IllegalArgumentException expected) { } }
public void testSlice_constrainedRange() throws IOException { long size = source.read().length; if (size >= 2) { ByteSource sliced = source.slice(1, size - 2); assertEquals(size - 2, sliced.read().length); ByteSource resliced = sliced.slice(0, size - 1); assertTrue(sliced.contentEquals(resliced)); } }
private static String getExpectedStringValue(int index, int size) { try { return ByteSource.concat(cycle(ByteSource.wrap(String.valueOf(index).getBytes(UTF_8)))).slice(0, size).asCharSource(UTF_8).read(); } catch (IOException e) { throw Throwables.propagate(e); } }
private static String getExpectedStringValue(int index, int size) { try { return ByteSource.concat(cycle(ByteSource.wrap(String.valueOf(index).getBytes(UTF_8)))).slice(0, size).asCharSource(UTF_8).read(); } catch (IOException e) { throw Throwables.propagate(e); } }
public void testConcat_infiniteIterable() throws IOException { ByteSource source = ByteSource.wrap(new byte[] {0, 1, 2, 3}); Iterable<ByteSource> cycle = Iterables.cycle(ImmutableList.of(source)); ByteSource concatenated = ByteSource.concat(cycle); byte[] expected = {0, 1, 2, 3, 0, 1, 2, 3}; assertArrayEquals(expected, concatenated.slice(0, 8).read()); }