|
20 | 20 | import static java.util.concurrent.Executors.callable; |
21 | 21 |
|
22 | 22 | import com.google.api.services.storage.model.StorageObject; |
| 23 | +import com.google.gcloud.RetryHelper; |
23 | 24 | import com.google.gcloud.spi.StorageRpc; |
24 | 25 |
|
25 | 26 | import java.io.IOException; |
@@ -68,12 +69,16 @@ private void writeObject(ObjectOutputStream out) throws IOException { |
68 | 69 | private void flush(boolean compact) { |
69 | 70 | if (limit >= chunkSize || compact && limit >= MIN_CHUNK_SIZE) { |
70 | 71 | final int length = limit - limit % MIN_CHUNK_SIZE; |
71 | | - runWithRetries(callable(new Runnable() { |
72 | | - @Override |
73 | | - public void run() { |
74 | | - storageRpc.write(uploadId, buffer, 0, storageObject, position, length, false); |
75 | | - } |
76 | | - }), options.retryParams(), StorageImpl.EXCEPTION_HANDLER); |
| 72 | + try { |
| 73 | + runWithRetries(callable(new Runnable() { |
| 74 | + @Override |
| 75 | + public void run() { |
| 76 | + storageRpc.write(uploadId, buffer, 0, storageObject, position, length, false); |
| 77 | + } |
| 78 | + }), options.retryParams(), StorageImpl.EXCEPTION_HANDLER); |
| 79 | + } catch (RetryHelper.RetryHelperException e) { |
| 80 | + throw StorageException.translateAndThrow(e); |
| 81 | + } |
77 | 82 | position += length; |
78 | 83 | limit -= length; |
79 | 84 | byte[] temp = new byte[compact ? limit : chunkSize]; |
@@ -124,12 +129,16 @@ public boolean isOpen() { |
124 | 129 | @Override |
125 | 130 | public void close() throws IOException { |
126 | 131 | if (isOpen) { |
127 | | - runWithRetries(callable(new Runnable() { |
128 | | - @Override |
129 | | - public void run() { |
130 | | - storageRpc.write(uploadId, buffer, 0, storageObject, position, limit, true); |
131 | | - } |
132 | | - }), options.retryParams(), StorageImpl.EXCEPTION_HANDLER); |
| 132 | + try { |
| 133 | + runWithRetries(callable(new Runnable() { |
| 134 | + @Override |
| 135 | + public void run() { |
| 136 | + storageRpc.write(uploadId, buffer, 0, storageObject, position, limit, true); |
| 137 | + } |
| 138 | + }), options.retryParams(), StorageImpl.EXCEPTION_HANDLER); |
| 139 | + } catch (RetryHelper.RetryHelperException e) { |
| 140 | + throw StorageException.translateAndThrow(e); |
| 141 | + } |
133 | 142 | position += buffer.length; |
134 | 143 | isOpen = false; |
135 | 144 | buffer = null; |
|
0 commit comments