kvr000 commented on code in PR #455:
URL: https://github.com/apache/commons-compress/pull/455#discussion_r1438714929
##########
src/main/java/org/apache/commons/compress/utils/IOUtils.java:
##########
@@ -275,6 +277,49 @@ public static byte[] readRange(final ReadableByteChannel
input, final int len) t
return output.toByteArray();
}
+ /**
+ * Writes full buffer to channel.
+ *
+ * @param channel
+ * channel to write to
+ * @param buf
+ * buffer to write
+ * @throws IOException
+ * when writing fails
+ */
+ public static void writeFully(SeekableByteChannel channel, ByteBuffer buf)
throws IOException {
+ while (buf.hasRemaining()) {
+ int remaining = buf.remaining();
+ int written = channel.write(buf);
+ if (written <= 0) {
+ throw new IOException("Failed to fully write: channel=" +
channel + " length=" + remaining + " written=" + written);
+ }
+ }
+ }
+
+ /**
+ * Writes full buffer to channel at specified position.
+ *
+ * @param channel
+ * channel to write to
+ * @param buf
+ * buffer to write
+ * @param position
+ * position to write at
+ * @throws IOException
+ * when writing fails
+ */
+ public static void writeFullyAt(FileChannel channel, ByteBuffer buf, long
position) throws IOException {
Review Comment:
Moved to package private ZipIoUtil as requested above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]