From 498c095f246b888b71d6f533c1d350355821ee87 Mon Sep 17 00:00:00 2001 From: Jeroen van Erp Date: Wed, 15 Mar 2023 23:24:50 +0100 Subject: [PATCH] Converting bytes written to long (Fixes #740) Signed-off-by: Jeroen van Erp --- .../java/com/hierynomus/smbj/share/File.java | 12 ++++---- .../com/hierynomus/smbj/share/SMB2Writer.java | 30 +++++++++---------- .../com/hierynomus/smbj/utils/SmbFiles.java | 4 +-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/hierynomus/smbj/share/File.java b/src/main/java/com/hierynomus/smbj/share/File.java index 926b2f5c..ab06cbe8 100644 --- a/src/main/java/com/hierynomus/smbj/share/File.java +++ b/src/main/java/com/hierynomus/smbj/share/File.java @@ -57,7 +57,7 @@ public class File extends DiskEntry { * @param fileOffset The offset, in bytes, into the file to which the data should be written * @return the actual number of bytes that was written to the file */ - public int write(byte[] buffer, long fileOffset) { + public long write(byte[] buffer, long fileOffset) { return writer.write(buffer, fileOffset); } @@ -70,7 +70,7 @@ public int write(byte[] buffer, long fileOffset) { * @param length the number of bytes that are written * @return the actual number of bytes that was written to the file */ - public int write(byte[] buffer, long fileOffset, int offset, int length) { + public long write(byte[] buffer, long fileOffset, int offset, int length) { return writer.write(buffer, fileOffset, offset, length); } @@ -81,7 +81,7 @@ public int write(byte[] buffer, long fileOffset, int offset, int length) { * @param provider the byte chunk provider * @return the actual number of bytes that was written to the file */ - public int write(ByteChunkProvider provider) { + public long write(ByteChunkProvider provider) { return writer.write(provider); } @@ -93,7 +93,7 @@ public int write(ByteChunkProvider provider) { * @param progressListener an optional callback that will be invoked when data has been written to the file * @return the actual number of bytes that was written to the file */ - public int write(ByteChunkProvider provider, ProgressListener progressListener) { + public long write(ByteChunkProvider provider, ProgressListener progressListener) { return writer.write(provider, progressListener); } @@ -105,7 +105,7 @@ public int write(ByteChunkProvider provider, ProgressListener progressListener) * @param length the number of bytes that are written * @return A Future containing the total number of bytes written to the remote. */ - public Future writeAsync(byte[] buffer, long fileOffset, int offset, int length) { + public Future writeAsync(byte[] buffer, long fileOffset, int offset, int length) { return writer.writeAsync(buffer, fileOffset, offset, length); } @@ -116,7 +116,7 @@ public Future writeAsync(byte[] buffer, long fileOffset, int offset, in * @param provider the byte chunk provider * @return A future containing the total number of bytes written to the remote. */ - public Future writeAsync(ByteChunkProvider provider) { + public Future writeAsync(ByteChunkProvider provider) { return writer.writeAsync(provider); } diff --git a/src/main/java/com/hierynomus/smbj/share/SMB2Writer.java b/src/main/java/com/hierynomus/smbj/share/SMB2Writer.java index f2b18f7b..1a2dc2f9 100644 --- a/src/main/java/com/hierynomus/smbj/share/SMB2Writer.java +++ b/src/main/java/com/hierynomus/smbj/share/SMB2Writer.java @@ -56,7 +56,7 @@ public SMB2Writer(Share share, SMB2FileId fileId, String entryName) { * should be written * @return the actual number of bytes that was written to the file */ - public int write(byte[] buffer, long fileOffset) { + public long write(byte[] buffer, long fileOffset) { return write(buffer, fileOffset, 0, buffer.length); } @@ -70,7 +70,7 @@ public int write(byte[] buffer, long fileOffset) { * @param length the number of bytes that are written * @return the actual number of bytes that was written to the file */ - public int write(byte[] buffer, long fileOffset, int offset, int length) { + public long write(byte[] buffer, long fileOffset, int offset, int length) { return write(new ArrayByteChunkProvider(buffer, offset, length, fileOffset), null); } @@ -82,7 +82,7 @@ public int write(byte[] buffer, long fileOffset, int offset, int length) { * @param provider the byte chunk provider * @return the actual number of bytes that was written to the file */ - public int write(ByteChunkProvider provider) { + public long write(ByteChunkProvider provider) { return write(provider, null); } @@ -96,7 +96,7 @@ public int write(ByteChunkProvider provider) { * has been written to the file * @return the actual number of bytes that was written to the file */ - public int write(ByteChunkProvider provider, ProgressListener progressListener) { + public long write(ByteChunkProvider provider, ProgressListener progressListener) { int bytesWritten = 0; while (provider.isAvailable()) { logger.debug("Writing to {} from offset {}", this.entryName, provider.getOffset()); @@ -118,7 +118,7 @@ public int write(ByteChunkProvider provider, ProgressListener progressListener) * @param length the number of bytes that are written * @return A Future containing the total number of bytes written */ - public Future writeAsync(byte[] buffer, long fileOffset, int offset, int length) { + public Future writeAsync(byte[] buffer, long fileOffset, int offset, int length) { return writeAsync(new ArrayByteChunkProvider(buffer, offset, length, fileOffset)); } @@ -130,18 +130,18 @@ public Future writeAsync(byte[] buffer, long fileOffset, int offset, in * @param provider the byte chunk provider * @return the List of write response future */ - public Future writeAsync(ByteChunkProvider provider) { - final List> wrespFutureList = new ArrayList>(); + public Future writeAsync(ByteChunkProvider provider) { + final List> wrespFutureList = new ArrayList>(); while (provider.isAvailable()) { // maybe more than one time, need array list to store the write response future logger.debug("Sending async write request to {} from offset {}", this.entryName, provider.getOffset()); Future resp = share.writeAsync(fileId, provider); - final int bytesWritten = provider.getLastWriteSize(); + final long bytesWritten = provider.getLastWriteSize(); wrespFutureList.add(Futures.transform(resp, - new AFuture.Function() { + new AFuture.Function() { @Override - public Integer apply(SMB2WriteResponse t) { - int receivedBytes = t.getBytesWritten(); + public Long apply(SMB2WriteResponse t) { + long receivedBytes = t.getBytesWritten(); if (receivedBytes == bytesWritten) { return bytesWritten; } @@ -152,10 +152,10 @@ public Integer apply(SMB2WriteResponse t) { })); } - return Futures.transform(Futures.sequence(wrespFutureList), new AFuture.Function, Integer>(){ - public Integer apply(List a) { - int sum = 0; - for (Integer i : a) { + return Futures.transform(Futures.sequence(wrespFutureList), new AFuture.Function, Long>(){ + public Long apply(List a) { + long sum = 0; + for (Long i : a) { sum += i; } return sum; diff --git a/src/main/java/com/hierynomus/smbj/utils/SmbFiles.java b/src/main/java/com/hierynomus/smbj/utils/SmbFiles.java index 06a238dc..d9459532 100644 --- a/src/main/java/com/hierynomus/smbj/utils/SmbFiles.java +++ b/src/main/java/com/hierynomus/smbj/utils/SmbFiles.java @@ -43,8 +43,8 @@ public class SmbFiles { * @throws java.io.FileNotFoundException * @throws java.io.IOException */ - public static int copy(File source, DiskShare share, String destPath, boolean overwrite) throws IOException { - int r = 0; + public static long copy(File source, DiskShare share, String destPath, boolean overwrite) throws IOException { + long r = 0; if (source != null && source.exists() && source.canRead() && source.isFile()) { try (InputStream is = new java.io.FileInputStream(source)) {