Skip to content

Commit

Permalink
Converting bytes written to long (Fixes #740)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen van Erp <[email protected]>
  • Loading branch information
hierynomus committed May 8, 2023
1 parent b667395 commit 498c095
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/hierynomus/smbj/share/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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<Integer> writeAsync(byte[] buffer, long fileOffset, int offset, int length) {
public Future<Long> writeAsync(byte[] buffer, long fileOffset, int offset, int length) {
return writer.writeAsync(buffer, fileOffset, offset, length);
}

Expand All @@ -116,7 +116,7 @@ public Future<Integer> 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<Integer> writeAsync(ByteChunkProvider provider) {
public Future<Long> writeAsync(ByteChunkProvider provider) {
return writer.writeAsync(provider);
}

Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/hierynomus/smbj/share/SMB2Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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());
Expand All @@ -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<Integer> writeAsync(byte[] buffer, long fileOffset, int offset, int length) {
public Future<Long> writeAsync(byte[] buffer, long fileOffset, int offset, int length) {
return writeAsync(new ArrayByteChunkProvider(buffer, offset, length, fileOffset));
}

Expand All @@ -130,18 +130,18 @@ public Future<Integer> writeAsync(byte[] buffer, long fileOffset, int offset, in
* @param provider the byte chunk provider
* @return the List of write response future
*/
public Future<Integer> writeAsync(ByteChunkProvider provider) {
final List<Future<Integer>> wrespFutureList = new ArrayList<Future<Integer>>();
public Future<Long> writeAsync(ByteChunkProvider provider) {
final List<Future<Long>> wrespFutureList = new ArrayList<Future<Long>>();
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<SMB2WriteResponse> resp = share.writeAsync(fileId, provider);
final int bytesWritten = provider.getLastWriteSize();
final long bytesWritten = provider.getLastWriteSize();
wrespFutureList.add(Futures.transform(resp,
new AFuture.Function<SMB2WriteResponse, Integer>() {
new AFuture.Function<SMB2WriteResponse, Long>() {
@Override
public Integer apply(SMB2WriteResponse t) {
int receivedBytes = t.getBytesWritten();
public Long apply(SMB2WriteResponse t) {
long receivedBytes = t.getBytesWritten();
if (receivedBytes == bytesWritten) {
return bytesWritten;
}
Expand All @@ -152,10 +152,10 @@ public Integer apply(SMB2WriteResponse t) {
}));
}

return Futures.transform(Futures.sequence(wrespFutureList), new AFuture.Function<List<Integer>, Integer>(){
public Integer apply(List<Integer> a) {
int sum = 0;
for (Integer i : a) {
return Futures.transform(Futures.sequence(wrespFutureList), new AFuture.Function<List<Long>, Long>(){
public Long apply(List<Long> a) {
long sum = 0;
for (Long i : a) {
sum += i;
}
return sum;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/hierynomus/smbj/utils/SmbFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 498c095

Please sign in to comment.