23
23
import com .google .cloud .storage .Storage .BlobWriteOption ;
24
24
import java .io .IOException ;
25
25
import java .nio .ByteBuffer ;
26
+ import java .nio .channels .ClosedChannelException ;
26
27
import java .nio .channels .WritableByteChannel ;
27
28
import java .util .concurrent .TimeUnit ;
28
29
@@ -90,14 +91,38 @@ public interface BlobAppendableUpload extends BlobWriteSession {
90
91
* <p>This interface allows writing bytes to an Appendable Upload, and provides methods to close
91
92
* this channel -- optionally finalizing the upload.
92
93
*
94
+ * <p>The {@link #write(ByteBuffer)} method of this channel is non-blocking.
95
+ *
93
96
* @since 2.51.0 This new api is in preview and is subject to breaking changes.
94
97
*/
95
98
@ BetaApi
96
99
@ InternalExtensionOnly
97
100
interface AppendableUploadWriteableByteChannel extends WritableByteChannel {
98
101
99
102
/**
100
- * Finalize the upload and close this instance to further {@link #write(ByteBuffer)}ing. This
103
+ * <b>This method is non-blocking</b>
104
+ *
105
+ * <p>Consume as many bytes as can fit in the underlying outbound queue. The size of the
106
+ * outbound queue is determined from {@link BlobAppendableUploadConfig#getFlushPolicy()}{@code
107
+ * .}{@link FlushPolicy#getMaxPendingBytes() getMaxPendingBytes()}. If the outbound queue is
108
+ * full, and can not fit more bytes, this method will return 0.
109
+ *
110
+ * <p>This method may be invoked at any time. If another thread has already initiated a write
111
+ * operation upon this channel, however, then an invocation of this method will block until the
112
+ * first operation is complete.
113
+ *
114
+ * @param src The buffer from which bytes are to be retrieved
115
+ * @return The number of bytes written, possibly zero
116
+ * @throws ClosedChannelException If this channel is closed
117
+ * @throws IOException If some other I/O error occurs
118
+ */
119
+ @ Override
120
+ int write (ByteBuffer src ) throws IOException ;
121
+
122
+ /**
123
+ * <b>This method is blocking</b>
124
+ *
125
+ * <p>Finalize the upload and close this instance to further {@link #write(ByteBuffer)}ing. This
101
126
* will close any underlying stream and release any releasable resources once out of scope.
102
127
*
103
128
* <p>Once this method is called, and returns no more writes to the object will be allowed by
@@ -116,8 +141,11 @@ interface AppendableUploadWriteableByteChannel extends WritableByteChannel {
116
141
void finalizeAndClose () throws IOException ;
117
142
118
143
/**
119
- * Close this instance to further {@link #write(ByteBuffer)}ing without finalizing the upload.
120
- * This will close any underlying stream and release any releasable resources once out of scope.
144
+ * <b>This method is blocking</b>
145
+ *
146
+ * <p>Close this instance to further {@link #write(ByteBuffer)}ing without finalizing the
147
+ * upload. This will close any underlying stream and release any releasable resources once out
148
+ * of scope.
121
149
*
122
150
* <p>This method, {@link AppendableUploadWriteableByteChannel#finalizeAndClose()} and {@link
123
151
* AppendableUploadWriteableByteChannel#close()} are mutually exclusive. If one of the other
@@ -133,7 +161,9 @@ interface AppendableUploadWriteableByteChannel extends WritableByteChannel {
133
161
void closeWithoutFinalizing () throws IOException ;
134
162
135
163
/**
136
- * Close this instance to further {@link #write(ByteBuffer)}ing.
164
+ * <b>This method is blocking</b>
165
+ *
166
+ * <p>Close this instance to further {@link #write(ByteBuffer)}ing.
137
167
*
138
168
* <p>Whether the upload is finalized during this depends on the {@link
139
169
* BlobAppendableUploadConfig#getCloseAction()} provided to create the {@link
0 commit comments