@@ -49,19 +49,18 @@ final class GrpcBlobReadChannel implements ReadChannel {
|
49 | 49 | boolean autoGzipDecompression) {
|
50 | 50 | this.lazyReadChannel =
|
51 | 51 | new LazyReadChannel(
|
52 |
| -Suppliers.memoize( |
53 |
| -() -> { |
54 |
| -ReadObjectRequest req = |
55 |
| -seekReadObjectRequest(request, position, sub(limit, position)); |
56 |
| -return ResumableMedia.gapic() |
57 |
| -.read() |
58 |
| -.byteChannel(read) |
59 |
| -.setHasher(Hasher.noop()) |
60 |
| -.setAutoGzipDecompression(autoGzipDecompression) |
61 |
| -.buffered(BufferHandle.allocate(chunkSize)) |
62 |
| -.setReadObjectRequest(req) |
63 |
| -.build(); |
64 |
| -})); |
| 52 | +() -> { |
| 53 | +ReadObjectRequest req = |
| 54 | +seekReadObjectRequest(request, position, sub(limit, position)); |
| 55 | +return ResumableMedia.gapic() |
| 56 | +.read() |
| 57 | +.byteChannel(read) |
| 58 | +.setHasher(Hasher.noop()) |
| 59 | +.setAutoGzipDecompression(autoGzipDecompression) |
| 60 | +.buffered(BufferHandle.allocate(chunkSize)) |
| 61 | +.setReadObjectRequest(req) |
| 62 | +.build(); |
| 63 | +}); |
65 | 64 | }
|
66 | 65 |
|
67 | 66 | @Override
|
@@ -72,7 +71,7 @@ public void setChunkSize(int chunkSize) {
|
72 | 71 |
|
73 | 72 | @Override
|
74 | 73 | public boolean isOpen() {
|
75 |
| -return false; |
| 74 | +return lazyReadChannel.isOpen() && lazyReadChannel.getChannel().isOpen(); |
76 | 75 | }
|
77 | 76 |
|
78 | 77 | @Override
|
@@ -81,8 +80,8 @@ public void close() {
|
81 | 80 | try {
|
82 | 81 | lazyReadChannel.getChannel().close();
|
83 | 82 | } catch (IOException e) {
|
84 |
| -// TODO: why does ReadChannel remove IOException?! |
85 |
| -throw new RuntimeException(e); |
| 83 | +// why does ReadChannel remove IOException?! |
| 84 | +throw StorageException.coalesce(e); |
86 | 85 | }
|
87 | 86 | }
|
88 | 87 | }
|
@@ -149,13 +148,24 @@ private static final class LazyReadChannel {
|
149 | 148 | private final Supplier<BufferedReadableByteChannelSession<Object>> session;
|
150 | 149 | private final Supplier<BufferedReadableByteChannel> channel;
|
151 | 150 |
|
| 151 | +private boolean open = false; |
| 152 | + |
152 | 153 | public LazyReadChannel(Supplier<BufferedReadableByteChannelSession<Object>> session) {
|
153 | 154 | this.session = session;
|
154 |
| -this.channel = Suppliers.memoize(() -> session.get().open()); |
| 155 | +this.channel = |
| 156 | +Suppliers.memoize( |
| 157 | +() -> { |
| 158 | +open = true; |
| 159 | +return session.get().open(); |
| 160 | +}); |
155 | 161 | }
|
156 | 162 |
|
157 | 163 | public BufferedReadableByteChannel getChannel() {
|
158 | 164 | return channel.get();
|
159 | 165 | }
|
| 166 | + |
| 167 | +public boolean isOpen() { |
| 168 | +return open; |
| 169 | +} |
160 | 170 | }
|
161 | 171 | }
|
0 commit comments