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 a88fd641434fae0f9d713334b42ae10114eedbb5 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat Mar 1 15:24:53 2025 -0500 Better internal API names Use "All" like in NIO Files APIs --- .../archivers/zip/FileRandomAccessOutputStream.java | 2 +- .../archivers/zip/RandomAccessOutputStream.java | 17 +++++++++-------- .../zip/SeekableChannelRandomAccessOutputStream.java | 2 +- .../compress/archivers/zip/ZipArchiveOutputStream.java | 16 ++++++++-------- .../compress/archivers/zip/ZipSplitOutputStream.java | 2 +- .../archivers/zip/FileRandomAccessOutputStreamTest.java | 10 +++++----- .../archivers/zip/RandomAccessOutputStreamTest.java | 4 ++-- .../SeekableChannelRandomAccessOutputStreamTest.java | 10 +++++----- 8 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java index 556eef821..fb230ecda 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java @@ -71,7 +71,7 @@ public synchronized void write(final byte[] b, final int off, final int len) thr } @Override - public void writeFully(final byte[] b, final int off, final int len, final long atPosition) throws IOException { + public void writeAll(final byte[] b, final int off, final int len, final long atPosition) throws IOException { final ByteBuffer buf = ByteBuffer.wrap(b, off, len); for (long currentPos = atPosition; buf.hasRemaining();) { final int written = this.channel.write(buf, currentPos); diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStream.java index 8595efd89..e5f909504 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStream.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; @@ -41,24 +42,24 @@ public void write(final int b) throws IOException { } /** - * Writes the given data to specific position. + * Writes all given bytes at a position. * * @param position position in the stream - * @param b data to write - * @param off offset of the start of data in param b + * @param bytes data to write + * @param offset offset of the start of data in param bytes * @param len the length of data to write * @throws IOException if an I/O error occurs. */ - abstract void writeFully(byte[] b, int off, int len, long position) throws IOException; + abstract void writeAll(byte[] bytes, int offset, int len, long position) throws IOException; /** - * Writes the given data to specific position. + * Writes all given bytes at a position. * * @param position position in the stream - * @param b data to write + * @param bytes data to write * @throws IOException if an I/O error occurs. */ - void writeFully(final byte[] b, final long position) throws IOException { - writeFully(b, 0, b.length, position); + void writeAll(final byte[] bytes, final long position) throws IOException { + writeAll(bytes, 0, bytes.length, position); } } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStream.java index de8c2eb64..3860fa10c 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStream.java @@ -50,7 +50,7 @@ public synchronized void write(final byte[] b, final int off, final int len) thr } @Override - public synchronized void writeFully(final byte[] b, final int off, final int len, final long position) throws IOException { + public synchronized void writeAll(final byte[] b, final int off, final int len, final long position) throws IOException { final long saved = channel.position(); try { channel.position(position); diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java index 441067a6f..d0ccb78f6 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java @@ -1250,13 +1250,13 @@ private void rewriteSizesAndCrc(final boolean actuallyNeedsZip64) throws IOExcep } long position = dataStart; - randomStream.writeFully(ZipLong.getBytes(entry.entry.getCrc()), position); position += ZipConstants.WORD; + randomStream.writeAll(ZipLong.getBytes(entry.entry.getCrc()), position); position += ZipConstants.WORD; if (!hasZip64Extra(entry.entry) || !actuallyNeedsZip64) { - randomStream.writeFully(ZipLong.getBytes(entry.entry.getCompressedSize()), position); position += ZipConstants.WORD; - randomStream.writeFully(ZipLong.getBytes(entry.entry.getSize()), position); + randomStream.writeAll(ZipLong.getBytes(entry.entry.getCompressedSize()), position); position += ZipConstants.WORD; + randomStream.writeAll(ZipLong.getBytes(entry.entry.getSize()), position); } else { - randomStream.writeFully(ZipLong.ZIP64_MAGIC.getBytes(), position); position += ZipConstants.WORD; - randomStream.writeFully(ZipLong.ZIP64_MAGIC.getBytes(), position); + randomStream.writeAll(ZipLong.ZIP64_MAGIC.getBytes(), position); position += ZipConstants.WORD; + randomStream.writeAll(ZipLong.ZIP64_MAGIC.getBytes(), position); } position += ZipConstants.WORD; @@ -1267,14 +1267,14 @@ private void rewriteSizesAndCrc(final boolean actuallyNeedsZip64) throws IOExcep position = dataStart + 3 * ZipConstants.WORD + 2 * ZipConstants.SHORT + nameLen + 2 * ZipConstants.SHORT; // inside the ZIP64 extra uncompressed size comes // first, unlike the LFH, CD or data descriptor - randomStream.writeFully(ZipEightByteInteger.getBytes(entry.entry.getSize()), position); position += ZipConstants.DWORD; - randomStream.writeFully(ZipEightByteInteger.getBytes(entry.entry.getCompressedSize()), position); position += ZipConstants.DWORD; + randomStream.writeAll(ZipEightByteInteger.getBytes(entry.entry.getSize()), position); position += ZipConstants.DWORD; + randomStream.writeAll(ZipEightByteInteger.getBytes(entry.entry.getCompressedSize()), position); position += ZipConstants.DWORD; if (!actuallyNeedsZip64) { // do some cleanup: // * rewrite version needed to extract position = dataStart - 5 * ZipConstants.SHORT; - randomStream.writeFully(ZipShort.getBytes(versionNeededToExtract(entry.entry.getMethod(), false, false)), position); + randomStream.writeAll(ZipShort.getBytes(versionNeededToExtract(entry.entry.getMethod(), false, false)), position); position += ZipConstants.SHORT; // * remove ZIP64 extra, so it doesn't get written diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java index 6d3b768eb..e18fbcff2 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java @@ -276,7 +276,7 @@ public void write(final int i) throws IOException { } @Override - public void writeFully(final byte[] b, final int off, final int len, final long atPosition) throws IOException { + public void writeAll(final byte[] b, final int off, final int len, final long atPosition) throws IOException { long remainingPosition = atPosition; for (int remainingOff = off, remainingLen = len; remainingLen > 0; ) { final Map.Entry<Long, Path> segment = positionToFiles.floorEntry(remainingPosition); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java index 5ac47c4dd..754f7967b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java @@ -89,8 +89,8 @@ public void testWriteFullyAt_whenFullAtOnce_thenSucceed() throws IOException { ((ByteBuffer) answer.getArgument(0)).position(6); return 6; }); - stream.writeFully("hello".getBytes(StandardCharsets.UTF_8), 20); - stream.writeFully("world\n".getBytes(StandardCharsets.UTF_8), 30); + stream.writeAll("hello".getBytes(StandardCharsets.UTF_8), 20); + stream.writeAll("world\n".getBytes(StandardCharsets.UTF_8), 30); verify(channel, times(1)).write((ByteBuffer) any(), eq(20L)); verify(channel, times(1)).write((ByteBuffer) any(), eq(30L)); @@ -114,8 +114,8 @@ public void testWriteFullyAt_whenFullButPartial_thenSucceed() throws IOException ((ByteBuffer) answer.getArgument(0)).position(6); return 6; }); - stream.writeFully("hello".getBytes(StandardCharsets.UTF_8), 20); - stream.writeFully("world\n".getBytes(StandardCharsets.UTF_8), 30); + stream.writeAll("hello".getBytes(StandardCharsets.UTF_8), 20); + stream.writeAll("world\n".getBytes(StandardCharsets.UTF_8), 30); verify(channel, times(1)).write((ByteBuffer) any(), eq(20L)); verify(channel, times(1)).write((ByteBuffer) any(), eq(23L)); @@ -133,7 +133,7 @@ public void testWriteFullyAt_whenPartial_thenFail() throws IOException { return 3; }); when(channel.write((ByteBuffer) any(), eq(23L))).thenAnswer(answer -> 0); - assertThrows(IOException.class, () -> stream.writeFully("hello".getBytes(StandardCharsets.UTF_8), 20)); + assertThrows(IOException.class, () -> stream.writeAll("hello".getBytes(StandardCharsets.UTF_8), 20)); verify(channel, times(1)).write((ByteBuffer) any(), eq(20L)); verify(channel, times(1)).write((ByteBuffer) any(), eq(23L)); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStreamTest.java index 943872cda..db1a7586b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/RandomAccessOutputStreamTest.java @@ -50,8 +50,8 @@ public void write(final byte[] b, final int off, final int len) throws IOExcepti } @Override - void writeFully(final byte[] b, final int off, final int len, final long position) throws IOException { - delegate.writeFully(b, off, len, position); + void writeAll(final byte[] b, final int off, final int len, final long position) throws IOException { + delegate.writeAll(b, off, len, position); } }; stream.write('\n'); diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStreamTest.java index e8fe3e936..6767483b1 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/SeekableChannelRandomAccessOutputStreamTest.java @@ -89,8 +89,8 @@ public void testWriteFullyAt_whenFullAtOnce_thenSucceed() throws IOException { return 6; }); - stream.writeFully("hello".getBytes(StandardCharsets.UTF_8), 20); - stream.writeFully("world\n".getBytes(StandardCharsets.UTF_8), 30); + stream.writeAll("hello".getBytes(StandardCharsets.UTF_8), 20); + stream.writeAll("world\n".getBytes(StandardCharsets.UTF_8), 30); verify(channel, times(2)).write((ByteBuffer) any()); verify(channel, times(1)).position(eq(50L)); @@ -116,8 +116,8 @@ public void testWriteFullyAt_whenFullButPartial_thenSucceed() throws IOException return 6; }); - stream.writeFully("hello".getBytes(StandardCharsets.UTF_8), 20); - stream.writeFully("world\n".getBytes(StandardCharsets.UTF_8), 30); + stream.writeAll("hello".getBytes(StandardCharsets.UTF_8), 20); + stream.writeAll("world\n".getBytes(StandardCharsets.UTF_8), 30); verify(channel, times(3)).write((ByteBuffer) any()); verify(channel, times(1)).position(eq(50L)); @@ -137,7 +137,7 @@ public void testWriteFullyAt_whenPartial_thenFail() throws IOException { return 3; }).thenAnswer(answer -> 0); - assertThrows(IOException.class, () -> stream.writeFully("hello".getBytes(StandardCharsets.UTF_8), 20)); + assertThrows(IOException.class, () -> stream.writeAll("hello".getBytes(StandardCharsets.UTF_8), 20)); verify(channel, times(2)).write((ByteBuffer) any());