39
39
import com .google .common .collect .Iterables ;
40
40
import com .google .common .collect .Lists ;
41
41
import com .google .common .io .BaseEncoding ;
42
+ import java .io .IOException ;
42
43
import java .io .InputStream ;
43
44
import java .io .Serializable ;
44
45
import java .net .URL ;
46
+ import java .nio .file .Path ;
45
47
import java .security .Key ;
46
48
import java .util .Arrays ;
47
49
import java .util .Collections ;
@@ -1821,7 +1823,7 @@ public static Builder newBuilder() {
1821
1823
* Blob blob = storage.create(blobInfo);
1822
1824
* }</pre>
1823
1825
*
1824
- * @return a [ @code Blob} with complete information
1826
+ * @return a { @code Blob} with complete information
1825
1827
* @throws StorageException upon failure
1826
1828
*/
1827
1829
Blob create (BlobInfo blobInfo , BlobTargetOption ... options );
@@ -1842,7 +1844,7 @@ public static Builder newBuilder() {
1842
1844
* Blob blob = storage.create(blobInfo, "Hello, World!".getBytes(UTF_8));
1843
1845
* }</pre>
1844
1846
*
1845
- * @return a [ @code Blob} with complete information
1847
+ * @return a { @code Blob} with complete information
1846
1848
* @throws StorageException upon failure
1847
1849
* @see <a href="https://cloud.google.com/storage/docs/hashes-etags">Hashes and ETags</a>
1848
1850
*/
@@ -1865,7 +1867,7 @@ public static Builder newBuilder() {
1865
1867
* Blob blob = storage.create(blobInfo, "Hello, World!".getBytes(UTF_8), 7, 5);
1866
1868
* }</pre>
1867
1869
*
1868
- * @return a [ @code Blob} with complete information
1870
+ * @return a { @code Blob} with complete information
1869
1871
* @throws StorageException upon failure
1870
1872
* @see <a href="https://cloud.google.com/storage/docs/hashes-etags">Hashes and ETags</a>
1871
1873
*/
@@ -1908,12 +1910,124 @@ Blob create(
1908
1910
* Blob blob = storage.create(blobInfo, content, BlobWriteOption.encryptionKey(encryptionKey));
1909
1911
* }</pre>
1910
1912
*
1911
- * @return a [ @code Blob} with complete information
1913
+ * @return a { @code Blob} with complete information
1912
1914
* @throws StorageException upon failure
1913
1915
*/
1914
1916
@ Deprecated
1915
1917
Blob create (BlobInfo blobInfo , InputStream content , BlobWriteOption ... options );
1916
1918
1919
+ /**
1920
+ * Uploads {@code path} to the blob using {@link #writer}. By default any MD5 and CRC32C values in
1921
+ * the given {@code blobInfo} are ignored unless requested via the {@link
1922
+ * BlobWriteOption#md5Match()} and {@link BlobWriteOption#crc32cMatch()} options. Folder upload is
1923
+ * not supported.
1924
+ *
1925
+ * <p>Example of uploading a file:
1926
+ *
1927
+ * <pre>{@code
1928
+ * String bucketName = "my-unique-bucket";
1929
+ * String fileName = "readme.txt";
1930
+ * BlobId blobId = BlobId.of(bucketName, fileName);
1931
+ * BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
1932
+ * storage.createFrom(blobInfo, Paths.get(fileName));
1933
+ * }</pre>
1934
+ *
1935
+ * @param blobInfo blob to create
1936
+ * @param path file to upload
1937
+ * @param options blob write options
1938
+ * @return a {@code Blob} with complete information
1939
+ * @throws IOException on I/O error
1940
+ * @throws StorageException on server side error
1941
+ * @see #createFrom(BlobInfo, Path, int, BlobWriteOption...)
1942
+ */
1943
+ Blob createFrom (BlobInfo blobInfo , Path path , BlobWriteOption ... options ) throws IOException ;
1944
+
1945
+ /**
1946
+ * Uploads {@code path} to the blob using {@link #writer} and {@code bufferSize}. By default any
1947
+ * MD5 and CRC32C values in the given {@code blobInfo} are ignored unless requested via the {@link
1948
+ * BlobWriteOption#md5Match()} and {@link BlobWriteOption#crc32cMatch()} options. Folder upload is
1949
+ * not supported.
1950
+ *
1951
+ * <p>{@link #createFrom(BlobInfo, Path, BlobWriteOption...)} invokes this method with a buffer
1952
+ * size of 15 MiB. Users can pass alternative values. Larger buffer sizes might improve the upload
1953
+ * performance but require more memory. This can cause an OutOfMemoryError or add significant
1954
+ * garbage collection overhead. Smaller buffer sizes reduce memory consumption, that is noticeable
1955
+ * when uploading many objects in parallel. Buffer sizes less than 256 KiB are treated as 256 KiB.
1956
+ *
1957
+ * <p>Example of uploading a humongous file:
1958
+ *
1959
+ * <pre>{@code
1960
+ * BlobId blobId = BlobId.of(bucketName, blobName);
1961
+ * BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("video/webm").build();
1962
+ *
1963
+ * int largeBufferSize = 150 * 1024 * 1024;
1964
+ * Path file = Paths.get("humongous.file");
1965
+ * storage.createFrom(blobInfo, file, largeBufferSize);
1966
+ * }</pre>
1967
+ *
1968
+ * @param blobInfo blob to create
1969
+ * @param path file to upload
1970
+ * @param bufferSize size of the buffer I/O operations
1971
+ * @param options blob write options
1972
+ * @return a {@code Blob} with complete information
1973
+ * @throws IOException on I/O error
1974
+ * @throws StorageException on server side error
1975
+ */
1976
+ Blob createFrom (BlobInfo blobInfo , Path path , int bufferSize , BlobWriteOption ... options )
1977
+ throws IOException ;
1978
+
1979
+ /**
1980
+ * Reads bytes from an input stream and uploads those bytes to the blob using {@link #writer}. By
1981
+ * default any MD5 and CRC32C values in the given {@code blobInfo} are ignored unless requested
1982
+ * via the {@link BlobWriteOption#md5Match()} and {@link BlobWriteOption#crc32cMatch()} options.
1983
+ *
1984
+ * <p>Example of uploading data with CRC32C checksum:
1985
+ *
1986
+ * <pre>{@code
1987
+ * BlobId blobId = BlobId.of(bucketName, blobName);
1988
+ * byte[] content = "Hello, world".getBytes(StandardCharsets.UTF_8);
1989
+ * Hasher hasher = Hashing.crc32c().newHasher().putBytes(content);
1990
+ * String crc32c = BaseEncoding.base64().encode(Ints.toByteArray(hasher.hash().asInt()));
1991
+ * BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setCrc32c(crc32c).build();
1992
+ * storage.createFrom(blobInfo, new ByteArrayInputStream(content), Storage.BlobWriteOption.crc32cMatch());
1993
+ * }</pre>
1994
+ *
1995
+ * @param blobInfo blob to create
1996
+ * @param content input stream to read from
1997
+ * @param options blob write options
1998
+ * @return a {@code Blob} with complete information
1999
+ * @throws IOException on I/O error
2000
+ * @throws StorageException on server side error
2001
+ * @see #createFrom(BlobInfo, InputStream, int, BlobWriteOption...)
2002
+ */
2003
+ Blob createFrom (BlobInfo blobInfo , InputStream content , BlobWriteOption ... options )
2004
+ throws IOException ;
2005
+
2006
+ /**
2007
+ * Reads bytes from an input stream and uploads those bytes to the blob using {@link #writer} and
2008
+ * {@code bufferSize}. By default any MD5 and CRC32C values in the given {@code blobInfo} are
2009
+ * ignored unless requested via the {@link BlobWriteOption#md5Match()} and {@link
2010
+ * BlobWriteOption#crc32cMatch()} options.
2011
+ *
2012
+ * <p>{@link #createFrom(BlobInfo, InputStream, BlobWriteOption...)} )} invokes this method with a
2013
+ * buffer size of 15 MiB. Users can pass alternative values. Larger buffer sizes might improve the
2014
+ * upload performance but require more memory. This can cause an OutOfMemoryError or add
2015
+ * significant garbage collection overhead. Smaller buffer sizes reduce memory consumption, that
2016
+ * is noticeable when uploading many objects in parallel. Buffer sizes less than 256 KiB are
2017
+ * treated as 256 KiB.
2018
+ *
2019
+ * @param blobInfo blob to create
2020
+ * @param content input stream to read from
2021
+ * @param bufferSize size of the buffer I/O operations
2022
+ * @param options blob write options
2023
+ * @return a {@code Blob} with complete information
2024
+ * @throws IOException on I/O error
2025
+ * @throws StorageException on server side error
2026
+ */
2027
+ Blob createFrom (
2028
+ BlobInfo blobInfo , InputStream content , int bufferSize , BlobWriteOption ... options )
2029
+ throws IOException ;
2030
+
1917
2031
/**
1918
2032
* Returns the requested bucket or {@code null} if not found.
1919
2033
*
0 commit comments