Skip to content

Commit

Permalink
Internal refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Mar 1, 2025
1 parent 68f94a4 commit 31b9721
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,7 @@ public synchronized void write(final byte[] b, final int off, final int len) thr

@Override
public void writeAll(final byte[] b, final int off, final int len, final long pos) throws IOException {
final ByteBuffer buf = ByteBuffer.wrap(b, off, len);
for (long currentPos = pos; buf.hasRemaining();) {
final int written = channel.write(buf, currentPos);
if (written <= 0) {
throw new IOException("Failed to fully write to file: written=" + written);
}
currentPos += written;
}
ZipIoUtil.writeAll(channel, ByteBuffer.wrap(b, off, len), pos);
position += len;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ final class ZipIoUtil {
* @throws IOException If some I/O error occurs or fails or fails to write all bytes.
*/
static void writeAll(final FileChannel channel, final ByteBuffer buffer, final long position) throws IOException {
for (long currentPosition = position; buffer.hasRemaining();) {
for (long currentPos = position; buffer.hasRemaining();) {
final int remaining = buffer.remaining();
final int written = channel.write(buffer, currentPosition);
final int written = channel.write(buffer, currentPos);
if (written <= 0) {
throw new IOException("Failed to write all bytes in the buffer for channel=" + channel + ", length=" + remaining + ", written=" + written);
}
currentPosition += written;
currentPos += written;
}
}

Expand Down

0 comments on commit 31b9721

Please sign in to comment.