File tree 2 files changed +31
-0
lines changed
google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 20
20
import com .google .cloud .storage .BlobInfo ;
21
21
import com .google .cloud .storage .Storage ;
22
22
import com .google .cloud .storage .Storage .BlobSourceOption ;
23
+ import com .google .cloud .storage .StorageException ;
23
24
import com .google .common .io .ByteStreams ;
24
25
import java .nio .channels .FileChannel ;
25
26
import java .nio .file .Path ;
@@ -64,6 +65,20 @@ public DownloadSegment call() {
64
65
rc .limit (endPosition );
65
66
wc .position (startPosition );
66
67
bytesCopied = ByteStreams .copy (rc , wc );
68
+ long bytesExpected = endPosition - startPosition ;
69
+ if (bytesCopied != bytesExpected ) {
70
+ return DownloadSegment .newBuilder (originalBlob , TransferStatus .FAILED_TO_FINISH )
71
+ .setException (
72
+ new StorageException (
73
+ 0 ,
74
+ "Unexpected end of stream, read "
75
+ + bytesCopied
76
+ + " expected "
77
+ + bytesExpected
78
+ + " from object "
79
+ + originalBlob .getBlobId ().toGsUtilUriWithGeneration ()))
80
+ .build ();
81
+ }
67
82
} catch (Exception e ) {
68
83
if (bytesCopied == -1 ) {
69
84
return DownloadSegment .newBuilder (originalBlob , TransferStatus .FAILED_TO_START )
Original file line number Diff line number Diff line change 21
21
import com .google .cloud .storage .BlobInfo ;
22
22
import com .google .cloud .storage .Storage ;
23
23
import com .google .cloud .storage .Storage .BlobSourceOption ;
24
+ import com .google .cloud .storage .StorageException ;
24
25
import com .google .common .io .ByteStreams ;
25
26
import java .nio .channels .FileChannel ;
26
27
import java .nio .file .Path ;
@@ -60,6 +61,21 @@ public DownloadResult call() {
60
61
StandardOpenOption .CREATE ,
61
62
StandardOpenOption .TRUNCATE_EXISTING );
62
63
bytesCopied = ByteStreams .copy (rc , wc );
64
+ if (originalBlob .getSize () != null ) {
65
+ if (bytesCopied != originalBlob .getSize ()) {
66
+ return DownloadResult .newBuilder (originalBlob , TransferStatus .FAILED_TO_FINISH )
67
+ .setException (
68
+ new StorageException (
69
+ 0 ,
70
+ "Unexpected end of stream, read "
71
+ + bytesCopied
72
+ + " expected "
73
+ + originalBlob .getSize ()
74
+ + " from object "
75
+ + originalBlob .getBlobId ().toGsUtilUriWithGeneration ()))
76
+ .build ();
77
+ }
78
+ }
63
79
} catch (Exception e ) {
64
80
if (bytesCopied == -1 ) {
65
81
return DownloadResult .newBuilder (originalBlob , TransferStatus .FAILED_TO_START )
You can’t perform that action at this time.
0 commit comments