3939import com .google .common .collect .Iterables ;
4040import com .google .common .collect .Lists ;
4141import com .google .common .io .BaseEncoding ;
42+ import java .io .IOException ;
4243import java .io .InputStream ;
4344import java .io .Serializable ;
4445import java .net .URL ;
46+ import java .nio .file .Path ;
4547import java .security .Key ;
4648import java .util .Arrays ;
4749import java .util .Collections ;
@@ -1821,7 +1823,7 @@ public static Builder newBuilder() {
18211823 * Blob blob = storage.create(blobInfo);
18221824 * }</pre>
18231825 *
1824- * @return a [ @code Blob} with complete information
1826+ * @return a { @code Blob} with complete information
18251827 * @throws StorageException upon failure
18261828 */
18271829 Blob create (BlobInfo blobInfo , BlobTargetOption ... options );
@@ -1842,7 +1844,7 @@ public static Builder newBuilder() {
18421844 * Blob blob = storage.create(blobInfo, "Hello, World!".getBytes(UTF_8));
18431845 * }</pre>
18441846 *
1845- * @return a [ @code Blob} with complete information
1847+ * @return a { @code Blob} with complete information
18461848 * @throws StorageException upon failure
18471849 * @see <a href="https://cloud.google.com/storage/docs/hashes-etags">Hashes and ETags</a>
18481850 */
@@ -1865,7 +1867,7 @@ public static Builder newBuilder() {
18651867 * Blob blob = storage.create(blobInfo, "Hello, World!".getBytes(UTF_8), 7, 5);
18661868 * }</pre>
18671869 *
1868- * @return a [ @code Blob} with complete information
1870+ * @return a { @code Blob} with complete information
18691871 * @throws StorageException upon failure
18701872 * @see <a href="https://cloud.google.com/storage/docs/hashes-etags">Hashes and ETags</a>
18711873 */
@@ -1908,12 +1910,124 @@ Blob create(
19081910 * Blob blob = storage.create(blobInfo, content, BlobWriteOption.encryptionKey(encryptionKey));
19091911 * }</pre>
19101912 *
1911- * @return a [ @code Blob} with complete information
1913+ * @return a { @code Blob} with complete information
19121914 * @throws StorageException upon failure
19131915 */
19141916 @ Deprecated
19151917 Blob create (BlobInfo blobInfo , InputStream content , BlobWriteOption ... options );
19161918
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+
19172031 /**
19182032 * Returns the requested bucket or {@code null} if not found.
19192033 *
0 commit comments