@@ -154,7 +154,7 @@ public Blob create(BlobInfo blobInfo, BlobTargetOption... options) {
|
154 | 154 | .setMd5(EMPTY_BYTE_ARRAY_MD5)
|
155 | 155 | .setCrc32c(EMPTY_BYTE_ARRAY_CRC32C)
|
156 | 156 | .build();
|
157 |
| -return internalCreate(updatedInfo, EMPTY_BYTE_ARRAY, options); |
| 157 | +return internalCreate(updatedInfo, EMPTY_BYTE_ARRAY, 0, 0, options); |
158 | 158 | }
|
159 | 159 |
|
160 | 160 | @Override
|
@@ -168,23 +168,26 @@ public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... option
|
168 | 168 | BaseEncoding.base64()
|
169 | 169 | .encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt())))
|
170 | 170 | .build();
|
171 |
| -return internalCreate(updatedInfo, content, options); |
| 171 | +return internalCreate(updatedInfo, content, 0, content.length, options); |
172 | 172 | }
|
173 | 173 |
|
174 | 174 | @Override
|
175 | 175 | public Blob create(
|
176 | 176 | BlobInfo blobInfo, byte[] content, int offset, int length, BlobTargetOption... options) {
|
177 | 177 | content = firstNonNull(content, EMPTY_BYTE_ARRAY);
|
178 |
| -byte[] subContent = Arrays.copyOfRange(content, offset, offset + length); |
179 | 178 | BlobInfo updatedInfo =
|
180 | 179 | blobInfo
|
181 | 180 | .toBuilder()
|
182 |
| -.setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(subContent).asBytes())) |
| 181 | +.setMd5( |
| 182 | +BaseEncoding.base64() |
| 183 | +.encode(Hashing.md5().hashBytes(content, offset, length).asBytes())) |
183 | 184 | .setCrc32c(
|
184 | 185 | BaseEncoding.base64()
|
185 |
| -.encode(Ints.toByteArray(Hashing.crc32c().hashBytes(subContent).asInt()))) |
| 186 | +.encode( |
| 187 | +Ints.toByteArray( |
| 188 | +Hashing.crc32c().hashBytes(content, offset, length).asInt()))) |
186 | 189 | .build();
|
187 |
| -return internalCreate(updatedInfo, subContent, options); |
| 190 | +return internalCreate(updatedInfo, content, offset, length, options); |
188 | 191 | }
|
189 | 192 |
|
190 | 193 | @Override
|
@@ -199,7 +202,12 @@ public Blob create(BlobInfo blobInfo, InputStream content, BlobWriteOption... op
|
199 | 202 | return Blob.fromPb(this, storageRpc.create(blobPb, inputStreamParam, optionsMap));
|
200 | 203 | }
|
201 | 204 |
|
202 |
| -private Blob internalCreate(BlobInfo info, final byte[] content, BlobTargetOption... options) { |
| 205 | +private Blob internalCreate( |
| 206 | +BlobInfo info, |
| 207 | +final byte[] content, |
| 208 | +final int offset, |
| 209 | +final int length, |
| 210 | +BlobTargetOption... options) { |
203 | 211 | Preconditions.checkNotNull(content);
|
204 | 212 | final StorageObject blobPb = info.toPb();
|
205 | 213 | final Map<StorageRpc.Option, ?> optionsMap = optionMap(info, options);
|
@@ -210,7 +218,8 @@ private Blob internalCreate(BlobInfo info, final byte[] content, BlobTargetOptio
|
210 | 218 | new Callable<StorageObject>() {
|
211 | 219 | @Override
|
212 | 220 | public StorageObject call() {
|
213 |
| -return storageRpc.create(blobPb, new ByteArrayInputStream(content), optionsMap); |
| 221 | +return storageRpc.create( |
| 222 | +blobPb, new ByteArrayInputStream(content, offset, length), optionsMap); |
214 | 223 | }
|
215 | 224 | },
|
216 | 225 | getOptions().getRetrySettings(),
|
|
0 commit comments