You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add create to Storage that takes an InputStream #172
I don't like having various flavors of the same method/functionality, especially when the difference is so subtle because at some point it makes the API less readable (what about adding also ByteBuffer option,....). This method should be used when content can live in memory. I picked bytes[] because I thought it is a good common denominator but could be convinced to pick something else.
It is fairly simple to convert a InputStream to byte[] (e.g. by using Guava).
I see your point but let me play the devil's advocate here.
It could argued that having both methods makes the library easier to use, as for instance, a user with a small FileInputStream is not required to read the stream to a byte array (even if it is farly simple) but can upload that with a single library call.
I assume that your suggestion includes also using a different RPC (apiary with an inputstream for media uploader - see here) rather than us reading the content into a byte array and using the same rpc?
It would make more sense in that case even though I think generally we should recommend using resumable uploads for big files (via BlobWriteChannel) and non-resumables for small ones. Can you check if current implementation of the MediaUploader will really chunk when using direct/non-resumable upload rather than itself reading all in memory before sending the request?
Yes I was planning on adding a different RPC which makes use of InputStreamContent (see here) rather than ByteArrayContent.
From the docs of MediaHttpUploader I read:
For resumable uploads, when the media content length is known, if the provided InputStream has InputStream.markSupported() as false then it is wrapped in an BufferedInputStream to support the InputStream.mark(int) and InputStream.reset() methods required for handling server errors. If the media content length is unknown then each chunk is stored temporarily in memory. This is required to determine when the last chunk is reached.
Which makes me think that is always tries to use resumable uploads (even for ByteArrayContent).
Yes, unless we pass true to setDirectUploadEnabled. see here. So my understanding (but I didn't dig deep) is that using this apiary client resumable downloads can work in chunks (for all input types) but for non-resumable (which is what I think we want here) one need to specify direct-upload and I was not sure if that will not load the complete content to memory before sending it (conceptually it does not have to). Can you verify these assumptions?
When directUploadEnabled is set to true, whether data are read in chunks or not depends on the type of XXXContent. In the case of all subclasses of AbstractInputStreamContent data reads happen in chunks of 2048 bytes.
I might be wrong but doesn't AbstractInputStreamContent use IOUtils.copy which then calls BufferStreams.copy? That should work in chunks (4096B actually).
Ok, if you are sure that the destination (out) is streamed when directUploadEnable is true (which would make sense) rather than buffered and sent as one blob then I think your proposal of adding this method (and an extra RPC) make sense. Maybe we can use one RPC with InputStream then....
Activity
aozarov commentedon Sep 22, 2015
I don't like having various flavors of the same method/functionality, especially when the difference is so subtle because at some point it makes the API less readable (what about adding also
ByteBufferoption,....). This method should be used when content can live in memory. I pickedbytes[]because I thought it is a good common denominator but could be convinced to pick something else.It is fairly simple to convert a
InputStreamtobyte[](e.g. by using Guava).mziccard commentedon Sep 22, 2015
I see your point but let me play the devil's advocate here.
It could argued that having both methods makes the library easier to use, as for instance, a user with a small
FileInputStreamis not required to read the stream to a byte array (even if it is farly simple) but can upload that with a single library call.aozarov commentedon Sep 23, 2015
I assume that your suggestion includes also using a different RPC (apiary with an inputstream for media uploader - see here) rather than us reading the content into a byte array and using the same rpc?
It would make more sense in that case even though I think generally we should recommend using resumable uploads for big files (via BlobWriteChannel) and non-resumables for small ones. Can you check if current implementation of the MediaUploader will really chunk when using direct/non-resumable upload rather than itself reading all in memory before sending the request?
mziccard commentedon Sep 23, 2015
Yes I was planning on adding a different RPC which makes use of
InputStreamContent(see here) rather thanByteArrayContent.From the docs of
MediaHttpUploaderI read:Which makes me think that is always tries to use resumable uploads (even for
ByteArrayContent).aozarov commentedon Sep 23, 2015
Yes, unless we pass
truetosetDirectUploadEnabled. see here. So my understanding (but I didn't dig deep) is that using this apiary client resumable downloads can work in chunks (for all input types) but for non-resumable (which is what I think we want here) one need to specify direct-upload and I was not sure if that will not load the complete content to memory before sending it (conceptually it does not have to). Can you verify these assumptions?mziccard commentedon Sep 23, 2015
When
directUploadEnabledis set to true, whether data are read in chunks or not depends on the type ofXXXContent. In the case of all subclasses ofAbstractInputStreamContentdata reads happen in chunks of 2048 bytes.aozarov commentedon Sep 23, 2015
You mean this
AbstractInputStreamContent? As thisone seems to write all in one write... (or do they override something?)
mziccard commentedon Sep 23, 2015
I might be wrong but doesn't
AbstractInputStreamContentuseIOUtils.copywhich then callsBufferStreams.copy? That should work in chunks (4096B actually).aozarov commentedon Sep 23, 2015
Ok, if you are sure that the destination (
out) is streamed whendirectUploadEnableis true (which would make sense) rather than buffered and sent as one blob then I think your proposal of adding this method (and an extra RPC) make sense. Maybe we can use one RPC with InputStream then....aozarov commentedon Sep 30, 2015
Implemented by #186
chore: Integrate new gapic-generator-java and rules_gapic (#172)
4 remaining items
build(deps): update dependency org.apache.maven.plugins:maven-project…
deps: update dependency com.google.cloud:google-cloud-shared-dependen…
deps: update dependency com.google.cloud:google-cloud-shared-dependen…
chore(main): release 1.2.6 (#173)
chore(main): release 1.1.7 (#187)
chore(main): release 1.3.0 (#172)
chore(main): release 0.6.2 (#173)
chore(deps): update dependency com.google.cloud:google-cloud-vmmigrat…
chore(java): add a note in README for migrated split repos (googleapi…
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
chore(deps): update dependency com.google.cloud:google-cloud-datastor…
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
tests: run integration tests against emulator (googleapis#172)
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…