27
27
import com .google .cloud .storage .UnbufferedReadableByteChannelSession .UnbufferedReadableByteChannel ;
28
28
import com .google .storage .v2 .ChecksummedData ;
29
29
import com .google .storage .v2 .Object ;
30
- import com .google .storage .v2 .ObjectChecksums ;
31
30
import com .google .storage .v2 .ReadObjectRequest ;
32
31
import com .google .storage .v2 .ReadObjectResponse ;
33
32
import java .io .Closeable ;
@@ -50,12 +49,9 @@ final class GapicUnbufferedReadableByteChannel
50
49
51
50
private boolean open = true ;
52
51
private boolean complete = false ;
53
- private boolean ioExceptionAlreadyThrown = false ;
54
52
private long blobOffset ;
55
- private Crc32cLengthKnown cumulativeCrc32c ;
56
53
57
54
private Object metadata ;
58
- private ObjectChecksums objectChecksums ;
59
55
60
56
private ByteBuffer leftovers ;
61
57
@@ -110,30 +106,16 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
110
106
result .set (metadata );
111
107
}
112
108
}
113
- if (resp .hasObjectChecksums ()) {
114
- ObjectChecksums checksums = resp .getObjectChecksums ();
115
- if (this .objectChecksums == null ) {
116
- this .objectChecksums = checksums ;
117
- } else if (!objectChecksums .equals (checksums )) {
118
- throw closeWithError (
119
- String .format (
120
- "Mismatch checksums between subsequent reads. Expected %s but received %s" ,
121
- Crc32cValue .fmtCrc32cValue (objectChecksums .getCrc32C ()),
122
- Crc32cValue .fmtCrc32cValue (checksums .getCrc32C ())));
123
- }
124
- }
125
109
ChecksummedData checksummedData = resp .getChecksummedData ();
126
110
ByteBuffer content = checksummedData .getContent ().asReadOnlyByteBuffer ();
127
111
// very important to know whether a crc32c value is set. Without checking, protobuf will
128
112
// happily return 0, which is a valid crc32c value.
129
113
if (checksummedData .hasCrc32C ()) {
130
114
Crc32cLengthKnown expected =
131
115
Crc32cValue .of (checksummedData .getCrc32C (), checksummedData .getContent ().size ());
132
- cumulativeCrc32c = hasher .nullSafeConcat (cumulativeCrc32c , expected );
133
116
try {
134
117
hasher .validate (expected , content ::duplicate );
135
118
} catch (IOException e ) {
136
- ioExceptionAlreadyThrown = true ;
137
119
close ();
138
120
throw e ;
139
121
}
@@ -161,18 +143,6 @@ public boolean isOpen() {
161
143
162
144
@ Override
163
145
public void close () throws IOException {
164
- if (!ioExceptionAlreadyThrown
165
- && cumulativeCrc32c != null
166
- && objectChecksums != null
167
- && objectChecksums .hasCrc32C ()) {
168
- Crc32cLengthKnown expected = Crc32cValue .of (objectChecksums .getCrc32C (), metadata .getSize ());
169
- if (!expected .eqValue (cumulativeCrc32c )) {
170
- throw new IOException (
171
- String .format (
172
- "Mismatch checksum value. Expected %s actual %s" ,
173
- expected .debugString (), cumulativeCrc32c .debugString ()));
174
- }
175
- }
176
146
open = false ;
177
147
iter .close ();
178
148
}
@@ -187,7 +157,6 @@ private void copy(ReadCursor c, ByteBuffer content, ByteBuffer[] dsts, int offse
187
157
}
188
158
189
159
private IOException closeWithError (String message ) throws IOException {
190
- ioExceptionAlreadyThrown = true ;
191
160
close ();
192
161
StorageException cause =
193
162
new StorageException (HttpStatusCodes .STATUS_CODE_PRECONDITION_FAILED , message );
0 commit comments