List of usage examples for com.google.common.hash PrimitiveSink putBytes
PrimitiveSink putBytes(byte[] bytes, int off, int len);
From source file:com.tinspx.util.io.ByteUtils.java
/** * Copies the entire contents of {@code from} into {@code to}. * /*from w w w . ja v a2 s .c om*/ * @param from the source to read bytes from * @param to the destination to copy bytes read from {@code from} into * @throws IOException if an IOException occurs * @throws NullPointerException if either {@code from} or {@code to} is null */ @ThreadLocalArray(8192) public static void copy(@NonNull ByteBuffer from, @NonNull PrimitiveSink to) { if (!from.hasRemaining()) { return; } if (from.hasArray()) { to.putBytes(from.array(), from.arrayOffset() + from.position(), from.remaining()); from.position(from.limit()); return; } final byte bytes[] = threadLocalArray8K(); do { int r = Math.min(bytes.length, from.remaining()); from.get(bytes, 0, r); to.putBytes(bytes, 0, r); } while (from.hasRemaining()); }
From source file:com.tinspx.util.io.ByteUtils.java
/** * Copies at most {@code limit} bytes from {@code from} into {@code to}, * returning the total number of bytes copied. Neither {@code from} nor * {@code to} is closed, and {@code to} is not flushed. * /*from w w w. j a v a 2 s .co m*/ * @param from the source to read bytes from * @param to the destination to copy bytes read from {@code from} into * @param limit the maximum number of bytes to copy * @return the total number of bytes copied from {@code from} to {@code to} * @throws IOException if an IOException occurs * @throws NullPointerException if either {@code from} or {@code to} is null * @throws IllegalArgumentException if {@code limit} is negative */ @ThreadLocalArray(8192) public static long copy(@NonNull @WillNotClose InputStream from, @NonNull PrimitiveSink to, long limit) throws IOException { checkLimit(limit); final byte[] buf = threadLocalArray8K(); long total = 0; while (total < limit) { int r = from.read(buf, 0, (int) Math.min(buf.length, limit - total)); if (r > 0) { to.putBytes(buf, 0, r); total += r; } else if (r < 0) { break; } } return total; }