use of com.google_voltpatches.errorprone.annotations.CanIgnoreReturnValue in project voltdb by VoltDB.
the class ByteSource method copyTo.
/**
* Copies the contents of this byte source to the given {@code ByteSink}.
*
* @return the number of bytes copied
* @throws IOException if an I/O error occurs in the process of reading from this source or
* writing to {@code sink}
*/
@CanIgnoreReturnValue
public long copyTo(ByteSink sink) throws IOException {
checkNotNull(sink);
Closer closer = Closer.create();
try {
InputStream in = closer.register(openStream());
OutputStream out = closer.register(sink.openStream());
return ByteStreams.copy(in, out);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
use of com.google_voltpatches.errorprone.annotations.CanIgnoreReturnValue in project voltdb by VoltDB.
the class ByteSink method writeFrom.
/**
* Writes all the bytes from the given {@code InputStream} to this sink. Does not close
* {@code input}.
*
* @return the number of bytes written
* @throws IOException if an I/O occurs in the process of reading from {@code input} or writing to
* this sink
*/
@CanIgnoreReturnValue
public long writeFrom(InputStream input) throws IOException {
checkNotNull(input);
Closer closer = Closer.create();
try {
OutputStream out = closer.register(openStream());
long written = ByteStreams.copy(input, out);
// https://code.google.com/p/guava-libraries/issues/detail?id=1330
out.flush();
return written;
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
use of com.google_voltpatches.errorprone.annotations.CanIgnoreReturnValue in project voltdb by VoltDB.
the class CharStreams method exhaust.
/**
* Reads and discards data from the given {@code Readable} until the end of the stream is
* reached. Returns the total number of chars read. Does not close the stream.
*
* @since 20.0
*/
@CanIgnoreReturnValue
public static long exhaust(Readable readable) throws IOException {
long total = 0;
long read;
CharBuffer buf = createBuffer();
while ((read = readable.read(buf)) != -1) {
total += read;
buf.clear();
}
return total;
}
use of com.google_voltpatches.errorprone.annotations.CanIgnoreReturnValue in project voltdb by VoltDB.
the class ByteStreams method copy.
/**
* Copies all bytes from the readable channel to the writable channel. Does not close or flush
* either channel.
*
* @param from the readable channel to read from
* @param to the writable channel to write to
* @return the number of bytes copied
* @throws IOException if an I/O error occurs
*/
@CanIgnoreReturnValue
public static long copy(ReadableByteChannel from, WritableByteChannel to) throws IOException {
checkNotNull(from);
checkNotNull(to);
if (from instanceof FileChannel) {
FileChannel sourceChannel = (FileChannel) from;
long oldPosition = sourceChannel.position();
long position = oldPosition;
long copied;
do {
copied = sourceChannel.transferTo(position, ZERO_COPY_CHUNK_SIZE, to);
position += copied;
sourceChannel.position(position);
} while (copied > 0 || position < sourceChannel.size());
return position - oldPosition;
}
ByteBuffer buf = ByteBuffer.wrap(createBuffer());
long total = 0;
while (from.read(buf) != -1) {
buf.flip();
while (buf.hasRemaining()) {
total += to.write(buf);
}
buf.clear();
}
return total;
}
use of com.google_voltpatches.errorprone.annotations.CanIgnoreReturnValue in project voltdb by VoltDB.
the class CharSink method writeFrom.
/**
* Writes all the text from the given {@link Readable} (such as a {@link Reader}) to this sink.
* Does not close {@code readable} if it is {@code Closeable}.
*
* @return the number of characters written
* @throws IOException if an I/O error occurs in the process of reading from {@code readable} or
* writing to this sink
*/
@CanIgnoreReturnValue
public long writeFrom(Readable readable) throws IOException {
checkNotNull(readable);
Closer closer = Closer.create();
try {
Writer out = closer.register(openStream());
long written = CharStreams.copy(readable, out);
// https://code.google.com/p/guava-libraries/issues/detail?id=1330
out.flush();
return written;
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
Aggregations