You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/03/01 20:54:08 UTC
(commons-compress) 02/08: Better exception messages
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 862e4b52faa4d7bd1ee7651f6e2a25d34ea52668
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 1 15:11:03 2025 -0500
Better exception messages
---
.../commons/compress/archivers/zip/ZipIoUtil.java | 25 +++++++++++-----------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipIoUtil.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipIoUtil.java
index f05a7452d..cd2516681 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipIoUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipIoUtil.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.commons.compress.archivers.zip;
import java.io.IOException;
@@ -33,15 +34,15 @@ final class ZipIoUtil {
* Writes full buffer to channel.
*
* @param channel channel to write to
- * @param buf buffer to write
+ * @param buffer buffer to write
* @throws IOException when writing fails or fails to write fully
*/
- static void writeFully(final WritableByteChannel channel, final ByteBuffer buf) throws IOException {
- while (buf.hasRemaining()) {
- final int remaining = buf.remaining();
- final int written = channel.write(buf);
+ static void writeFully(final WritableByteChannel channel, final ByteBuffer buffer) throws IOException {
+ while (buffer.hasRemaining()) {
+ final int remaining = buffer.remaining();
+ final int written = channel.write(buffer);
if (written <= 0) {
- throw new IOException("Failed to fully write: channel=" + channel + " length=" + remaining + " written=" + written);
+ throw new IOException("Failed to write all bytes in the buffer for channel=" + channel + ", length=" + remaining + ", written=" + written);
}
}
}
@@ -50,16 +51,16 @@ static void writeFully(final WritableByteChannel channel, final ByteBuffer buf)
* Writes full buffer to channel at specified position.
*
* @param channel channel to write to
- * @param buf buffer to write
+ * @param buffer buffer to write
* @param position position to write at
* @throws IOException when writing fails or fails to write fully
*/
- static void writeFullyAt(final FileChannel channel, final ByteBuffer buf, final long position) throws IOException {
- for (long currentPosition = position; buf.hasRemaining();) {
- final int remaining = buf.remaining();
- final int written = channel.write(buf, currentPosition);
+ static void writeFullyAt(final FileChannel channel, final ByteBuffer buffer, final long position) throws IOException {
+ for (long currentPosition = position; buffer.hasRemaining();) {
+ final int remaining = buffer.remaining();
+ final int written = channel.write(buffer, currentPosition);
if (written <= 0) {
- throw new IOException("Failed to fully write: channel=" + channel + " length=" + remaining + " written=" + written);
+ throw new IOException("Failed to write all bytes in the buffer for channel=" + channel + ", length=" + remaining + ", written=" + written);
}
currentPosition += written;
}