Class B2StorageClientImpl
- java.lang.Object
-
- com.backblaze.b2.client.B2StorageClientImpl
-
- All Implemented Interfaces:
B2StorageClient,java.io.Closeable,java.lang.AutoCloseable
public class B2StorageClientImpl extends java.lang.Object implements B2StorageClient
B2StorageClientImpl implements B2StorageClient and it acquires credentials as needed and implements our retry policies. It's also smart about using other threads to help with the uploads. THREAD-SAFETY: As long at the subobjects it's given are thread-safe, this object may be used from multiple threads simultaneously.
-
-
Constructor Summary
Constructors Constructor Description B2StorageClientImpl(B2StorageClientWebifier webifier, B2ClientConfig config, java.util.function.Supplier<B2RetryPolicy> retryPolicySupplier)Creates a client with the given webifier and config and a default B2Sleeper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description B2ListKeysIterableapplicationKeys(B2ListKeysRequest request)Returns an iterable whose iterator yields the application keys that match the given request.voidcancelLargeFile(B2CancelLargeFileRequest request)Cancels an unfinished large file.voidclose()Closes resources used by this client.B2FileVersioncopySmallFile(B2CopyFileRequest request)Makes a copy of a file in the same bucket.B2BucketcreateBucket(B2CreateBucketRequest request)Creates a new bucket with the given request.B2CreatedApplicationKeycreateKey(B2CreateKeyRequest request)Creates a new application key.B2BucketdeleteBucket(B2DeleteBucketRequest request)Deletes the specified bucket.voiddeleteFileVersion(B2DeleteFileVersionRequest request)Deletes the specified file version.B2ApplicationKeydeleteKey(B2DeleteKeyRequest request)Deletes the specified application key.voiddownloadById(B2DownloadByIdRequest request, B2ContentSink handler)Asks to download the specified file by id.voiddownloadByName(B2DownloadByNameRequest request, B2ContentSink handler)Asks to download the specified file by bucket name and file name.B2ListFilesIterablefileNames(B2ListFileNamesRequest request)Returns an iterable whose iterator yields the fileNames that match the given request.B2ListFilesIterablefileVersions(B2ListFileVersionsRequest request)Returns an iterable whose iterator yields the fileVersions that match the given request.B2FileVersionfinishLargeFile(B2FinishLargeFileRequest request)This method allows the caller to finish a large file.B2FileVersionfinishUploadingLargeFile(B2FileVersion fileVersion, B2UploadFileRequest request, java.util.concurrent.ExecutorService executor)Verifies that the given fileVersion represents an unfinished large file and that the specified content is compatible-enough with the information in that B2FileVersion.B2AccountAuthorizationgetAccountAuthorization()This method provides access to an account authorization structure.java.lang.StringgetAccountId()B2GetBucketNotificationRulesResponsegetBucketNotificationRules(B2GetBucketNotificationRulesRequest request)Gets the bucket's event notification rules as described by the request.B2DownloadAuthorizationgetDownloadAuthorization(B2GetDownloadAuthorizationRequest request)java.lang.StringgetDownloadByIdUrl(B2DownloadByIdRequest request)Returns the URL for downloading the file specified by the request.java.lang.StringgetDownloadByNameUrl(B2DownloadByNameRequest request)Returns the URL for downloading the file specified by the request.B2FileVersiongetFileInfo(B2GetFileInfoRequest request)B2FileVersiongetFileInfoByName(B2GetFileInfoByNameRequest request)B2FilePolicygetFilePolicy()B2UploadPartUrlResponsegetUploadPartUrl(B2GetUploadPartUrlRequest request)This method allows the caller to get an upload url and authorization token directly for uploading a large file part.B2UploadUrlResponsegetUploadUrl(B2GetUploadUrlRequest request)This method allows the caller to get an upload url and authorization token directly.B2StorageClientWebifiergetWebifier()B2FileVersionhideFile(B2HideFileRequest request)Hides the specified file.voidinvalidateAccountAuthorization()If there's a cached account authorization, this will flush the cache so that the authorization will need to be reacquired the next time it is needed.B2ListBucketsResponselistBuckets(B2ListBucketsRequest listBucketsRequest)B2ListPartsIterableparts(B2ListPartsRequest request)Returns an iterable whose iterator yields the parts of large, unfinished files that match the given request.B2SetBucketNotificationRulesResponsesetBucketNotificationRules(B2SetBucketNotificationRulesRequest request)Sets the bucket's event notification rules as described by the request.B2FileVersionstartLargeFile(B2StartLargeFileRequest request)This method allows the caller to start a large file.B2FileVersionstoreLargeFile(B2FileVersion fileVersion, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor)Stores a large file, where storing each part may involve different behavior or byte sources.B2FileVersionstoreLargeFile(B2StoreLargeFileRequest storeLargeFileRequest, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor)Stores a large file, where storing each part may involve different behavior or byte sources, optionally allowing caller to pass SSE-C parameters to match those given to startLargeFile().B2FileVersionstoreLargeFileFromLocalContent(B2FileVersion fileVersion, B2ContentSource contentSource, B2UploadListener uploadListener, java.util.concurrent.ExecutorService executor)Uploads the specified content source as separate parts to form a B2 large file.B2FileVersionstoreLargeFileFromLocalContent(B2StoreLargeFileRequest storeLargeFileRequest, B2ContentSource contentSource, B2UploadListener uploadListener, java.util.concurrent.ExecutorService executor)Uploads the specified content source as separate parts to form a B2 large file, optionally allowing caller to pass SSE-C parameters to match those given to startLargeFile().java.util.concurrent.CompletableFuture<B2FileVersion>storeLargeFileFromLocalContentAsync(B2FileVersion fileVersion, B2ContentSource contentSource, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor)Initiates uploading the specified content source as separate parts to form a B2 large file.java.util.concurrent.CompletableFuture<B2FileVersion>storeLargeFileFromLocalContentAsync(B2StoreLargeFileRequest storeLargeFileRequest, B2ContentSource contentSource, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor)Initiates uploading the specified content source as separate parts to form a B2 large file.java.util.List<B2Part>storePartsForLargeFile(B2FileVersion fileVersion, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor)Stores large file parts, where storing each part may involve different behavior or byte sources.java.util.List<B2Part>storePartsForLargeFile(B2StoreLargeFileRequest storeLargeFileRequest, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor)Stores large file parts, where storing each part may involve different behavior or byte sources, optionally allowing caller to pass SSE-C parameters to match those given to startLargeFile().B2ListFilesIterableunfinishedLargeFiles(B2ListUnfinishedLargeFilesRequest request)Returns an iterable whose iterator yields the fileVersions of large, unfinished files that match the given request.B2BucketupdateBucket(B2UpdateBucketRequest request)Updates the specified bucket as described by the request.B2UpdateFileLegalHoldResponseupdateFileLegalHold(B2UpdateFileLegalHoldRequest request)Updates the legal hold configuration of the specified file as described by the request.B2UpdateFileRetentionResponseupdateFileRetention(B2UpdateFileRetentionRequest request)Updates the file retention configuration of the specified file as described by the request.B2FileVersionuploadLargeFile(B2UploadFileRequest request, java.util.concurrent.ExecutorService executor)Uploads the specified content as separate parts to form a B2 large file.B2FileVersionuploadSmallFile(B2UploadFileRequest request)Uploads the specified content as a normal B2 file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.backblaze.b2.client.B2StorageClient
applicationKeys, buckets, cancelLargeFile, createBucket, deleteAllFilesInBucket, deleteBucket, deleteFileVersion, deleteFileVersion, downloadById, downloadByName, fileNames, fileVersions, getBucketNotificationRules, getBucketOrNullByName, getDownloadByIdUrl, getDownloadByNameUrl, getFileInfo, getFileInfoByName, hideFile, listBuckets, parts, setBucketNotificationRules, unfinishedLargeFiles
-
-
-
-
Constructor Detail
-
B2StorageClientImpl
public B2StorageClientImpl(B2StorageClientWebifier webifier, B2ClientConfig config, java.util.function.Supplier<B2RetryPolicy> retryPolicySupplier)
Creates a client with the given webifier and config and a default B2Sleeper. This is the normal constructor.- Parameters:
webifier- the object to convert API calls into web calls.config- the object used to configure this.
-
-
Method Detail
-
close
public void close()
Closes resources used by this client. It's safe to call when it's already been called. It won't return until we've tried to close the resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceB2StorageClient- Specified by:
closein interfacejava.io.Closeable
-
getAccountId
public java.lang.String getAccountId() throws B2Exception- Specified by:
getAccountIdin interfaceB2StorageClient- Returns:
- the accountId for this client.
- Throws:
B2Exception
-
getFilePolicy
public B2FilePolicy getFilePolicy() throws B2Exception
- Specified by:
getFilePolicyin interfaceB2StorageClient- Returns:
- an object for answering policy questions, such as whether to upload a file as a small or large file.
- Throws:
B2Exception
-
getWebifier
public B2StorageClientWebifier getWebifier()
- Specified by:
getWebifierin interfaceB2StorageClient
-
createBucket
public B2Bucket createBucket(B2CreateBucketRequest request) throws B2Exception
Description copied from interface:B2StorageClientCreates a new bucket with the given request.- Specified by:
createBucketin interfaceB2StorageClient- Parameters:
request- the request to create the bucket.- Returns:
- the newly created bucket.
- Throws:
B2Exception- if there's any trouble.
-
createKey
public B2CreatedApplicationKey createKey(B2CreateKeyRequest request) throws B2Exception
Description copied from interface:B2StorageClientCreates a new application key.- Specified by:
createKeyin interfaceB2StorageClient- Parameters:
request- the request to create the key.- Returns:
- the newly created key
- Throws:
B2Exception- if there's any trouble.
-
applicationKeys
public B2ListKeysIterable applicationKeys(B2ListKeysRequest request) throws B2Exception
Description copied from interface:B2StorageClientReturns an iterable whose iterator yields the application keys that match the given request. It will automatically call B2 to get batches of answers as needed. If there's any trouble during hasNext() or next(), it will throw a B2RuntimeException since Iterable<> doesn't allow checked exceptions to be thrown.- Specified by:
applicationKeysin interfaceB2StorageClient- Parameters:
request- specifies which application keys to list.- Returns:
- a new iterable to iterate over fileVersions that match the given request.
- Throws:
B2Exception- if there's any trouble
-
deleteKey
public B2ApplicationKey deleteKey(B2DeleteKeyRequest request) throws B2Exception
Description copied from interface:B2StorageClientDeletes the specified application key.- Specified by:
deleteKeyin interfaceB2StorageClient- Parameters:
request- specifies the key to delete.- Returns:
- the deleted key
- Throws:
B2Exception- if there's any trouble.
-
listBuckets
public B2ListBucketsResponse listBuckets(B2ListBucketsRequest listBucketsRequest) throws B2Exception
- Specified by:
listBucketsin interfaceB2StorageClient- Returns:
- the response from B2 with the listed buckets using a listBucketsRequest object.
- Throws:
B2Exception- if there's any trouble.
-
finishUploadingLargeFile
public B2FileVersion finishUploadingLargeFile(B2FileVersion fileVersion, B2UploadFileRequest request, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientVerifies that the given fileVersion represents an unfinished large file and that the specified content is compatible-enough with the information in that B2FileVersion. If it is, this will find the parts that haven't yet been uploaded and upload them to finish the large file. XXX: describe "compatible-enough". basically it's some sanity checks such as the size of the content and the large-file-sha1 if it's available. just enough to believe the request probably does go with the presented fileVersion. (Note that if you make up a bogus fileVersion, you're on your own!)- Specified by:
finishUploadingLargeFilein interfaceB2StorageClient- Parameters:
fileVersion- describes the unfinished large file we want to finish.request- describes the content we want to use to finish the large fileexecutor- the executor to use for uploading parts in parallel. the caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- the B2FileVersion that represents the finished large file.
- Throws:
B2Exception- if there's any trouble.
-
uploadSmallFile
public B2FileVersion uploadSmallFile(B2UploadFileRequest request) throws B2Exception
Description copied from interface:B2StorageClientUploads the specified content as a normal B2 file. The file must be smaller than the maximum file size (5 GB).- Specified by:
uploadSmallFilein interfaceB2StorageClient- Parameters:
request- describes the content to upload and extra metadata about it.- Returns:
- the B2FileVersion that represents it.
- Throws:
B2Exception- if there's any trouble.
-
copySmallFile
public B2FileVersion copySmallFile(B2CopyFileRequest request) throws B2Exception
Description copied from interface:B2StorageClientMakes a copy of a file in the same bucket. The new file must be smaller than the maximum file size (5 GB).- Specified by:
copySmallFilein interfaceB2StorageClient- Parameters:
request- describes what file to copy, the range of bytes to copy, and how to handle file metadata.- Returns:
- The B2FileVersion of the new file.
- Throws:
B2Exception- if there's any trouble.
-
uploadLargeFile
public B2FileVersion uploadLargeFile(B2UploadFileRequest request, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientUploads the specified content as separate parts to form a B2 large file.- Specified by:
uploadLargeFilein interfaceB2StorageClient- Parameters:
request- describes the content to upload and extra metadata about it.executor- the executor to use for uploading parts in parallel. the caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- the B2FileVersion that represents it.
- Throws:
B2Exception- if there's any trouble.
-
storeLargeFileFromLocalContent
public B2FileVersion storeLargeFileFromLocalContent(B2FileVersion fileVersion, B2ContentSource contentSource, B2UploadListener uploadListener, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientUploads the specified content source as separate parts to form a B2 large file. This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method. However, this method will call finish file. XXX: add storePartsForLargeFileFromLocalContent that stores parts but doesn't finish the file.- Specified by:
storeLargeFileFromLocalContentin interfaceB2StorageClient- Parameters:
fileVersion- The B2FileVersion for the large file getting stored. This is the return value of startLargeFile().contentSource- The contentSource to upload.uploadListener- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- The fileVersion of the large file after it has been finished.
- Throws:
B2Exception- If there's trouble.
-
storeLargeFileFromLocalContent
public B2FileVersion storeLargeFileFromLocalContent(B2StoreLargeFileRequest storeLargeFileRequest, B2ContentSource contentSource, B2UploadListener uploadListener, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientUploads the specified content source as separate parts to form a B2 large file, optionally allowing caller to pass SSE-C parameters to match those given to startLargeFile(). This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method as part of a B2StoreLargeFileRequest. However, this method will call finish file. XXX: add storePartsForLargeFileFromLocalContent that stores parts but doesn't finish the file.- Specified by:
storeLargeFileFromLocalContentin interfaceB2StorageClient- Parameters:
storeLargeFileRequest- The B2StoreLargeFileRequest for the large file getting stored. This is built from the return value of startLargeFile() and any other relevant parameters.contentSource- The contentSource to upload.uploadListener- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- The fileVersion of the large file after it has been finished.
- Throws:
B2Exception- If there's trouble.
-
storeLargeFileFromLocalContentAsync
public java.util.concurrent.CompletableFuture<B2FileVersion> storeLargeFileFromLocalContentAsync(B2FileVersion fileVersion, B2ContentSource contentSource, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientInitiates uploading the specified content source as separate parts to form a B2 large file. This allows the upload to be cancelled partway through. This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method. The returned future can be cancelled and this will also attempt to stop any part uploads in progress. Cancelling after the b2_finish_large_file API call has been started will result in the future being cancelled, but the API call can still succeed. There is no way to tell from the future whether this is the case. The caller is responsible for checking and calling B2StorageClient.cancelLargeFile.- Specified by:
storeLargeFileFromLocalContentAsyncin interfaceB2StorageClient- Parameters:
fileVersion- The B2FileVersion for the large file getting stored. This is the return value of startLargeFile().contentSource- The contentSource to upload.uploadListenerOrNull- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- CompletableFuture with the resulting B2FileVersion of the completed file
- Throws:
B2Exception- on error
-
storeLargeFileFromLocalContentAsync
public java.util.concurrent.CompletableFuture<B2FileVersion> storeLargeFileFromLocalContentAsync(B2StoreLargeFileRequest storeLargeFileRequest, B2ContentSource contentSource, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientInitiates uploading the specified content source as separate parts to form a B2 large file. This allows the upload to be cancelled partway through. This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method. The returned future can be cancelled and this will also attempt to stop any part uploads in progress. Cancelling after the b2_finish_large_file API call has been started will result in the future being cancelled, but the API call can still succeed. There is no way to tell from the future whether this is the case. The caller is responsible for checking and calling B2StorageClient.cancelLargeFile.- Specified by:
storeLargeFileFromLocalContentAsyncin interfaceB2StorageClient- Parameters:
storeLargeFileRequest- The B2StoreLargeFileRequest for the large file getting stored. This is built from the return value of startLargeFile() and any other relevant parameters.contentSource- The contentSource to upload.uploadListenerOrNull- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- CompletableFuture with the resulting B2FileVersion of the completed file
- Throws:
B2Exception- on error
-
storeLargeFile
public B2FileVersion storeLargeFile(B2FileVersion fileVersion, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientStores a large file, where storing each part may involve different behavior or byte sources.For example, this method supports the use case of making a copy of a file that mostly has not changed, and the user only wishes to upload the parts that have changed. In this case partStorers would be a mix of B2CopyingPartStorers and one or more B2UploadingPartStorers.
Another use case would be reattempting an upload of a large file where some parts have completed, and some haven't. In this case, partStorers would be a mix of B2AlreadyStoredPartStorer and B2UploadingPartStorers.
This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method. However, this method will call finish file. Note that each part, whether copied or uploaded, is still subject to the minimum part size.
- Specified by:
storeLargeFilein interfaceB2StorageClient- Parameters:
fileVersion- The B2FileVersion for the large file getting stored. This is the return value of startLargeFile().partStorers- The list of objects that know how to store the part they are responsible for.uploadListenerOrNull- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- The fileVersion of the large file after it has been finished.
- Throws:
B2Exception- If there's trouble.
-
storeLargeFile
public B2FileVersion storeLargeFile(B2StoreLargeFileRequest storeLargeFileRequest, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientStores a large file, where storing each part may involve different behavior or byte sources, optionally allowing caller to pass SSE-C parameters to match those given to startLargeFile().For example, this method supports the use case of making a copy of a file that mostly has not changed, and the user only wishes to upload the parts that have changed. In this case partStorers would be a mix of B2CopyingPartStorers and one or more B2UploadingPartStorers.
Another use case would be reattempting an upload of a large file where some parts have completed, and some haven't. In this case, partStorers would be a mix of B2AlreadyStoredPartStorer and B2UploadingPartStorers.
This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method as part of a B2StoreLargeFileRequest. However, this method will call finish file. Note that each part, whether copied or uploaded, is still subject to the minimum part size.
- Specified by:
storeLargeFilein interfaceB2StorageClient- Parameters:
storeLargeFileRequest- The B2StoreLargeFileRequest for the large file getting stored. This is built from the return value of startLargeFile() and any other relevant parameters.partStorers- The list of objects that know how to store the part they are responsible for.uploadListenerOrNull- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- The fileVersion of the large file after it has been finished.
- Throws:
B2Exception- If there's trouble.
-
storePartsForLargeFile
public java.util.List<B2Part> storePartsForLargeFile(B2FileVersion fileVersion, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientStores large file parts, where storing each part may involve different behavior or byte sources.For example, this method supports the use case of preparing to make a copy of a file that mostly has not changed, and the user only wishes to upload the parts that have changed. In this case partStorers would be a mix of B2CopyingPartStorers and one or more B2UploadingPartStorers.
Another use case would be reattempting some part uploads for an unfinished large file for which some parts have completed, and some haven't. In this case, partStorers would be a mix of B2AlreadyStoredPartStorer and B2UploadingPartStorers.
This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method. Note that each part, whether copied or uploaded, is still subject to the minimum part size. Note also that this method does not finish the large file.
- Specified by:
storePartsForLargeFilein interfaceB2StorageClient- Parameters:
fileVersion- The B2FileVersion for the large file for which these parts are being uploaded. This is the return value of startLargeFile().partStorers- The list of objects that know how to store the part they are responsible for.uploadListenerOrNull- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- The list of parts after all have been stored.
- Throws:
B2Exception- If there's trouble.
-
storePartsForLargeFile
public java.util.List<B2Part> storePartsForLargeFile(B2StoreLargeFileRequest storeLargeFileRequest, java.util.List<B2PartStorer> partStorers, B2UploadListener uploadListenerOrNull, java.util.concurrent.ExecutorService executor) throws B2Exception
Description copied from interface:B2StorageClientStores large file parts, where storing each part may involve different behavior or byte sources, optionally allowing caller to pass SSE-C parameters to match those given to startLargeFile().For example, this method supports the use case of making a copy of a file that mostly has not changed, and the user only wishes to upload the parts that have changed. In this case partStorers would be a mix of B2CopyingPartStorers and one or more B2UploadingPartStorers.
Another use case would be reattempting some part uploads for an unfinished large file for which some parts have completed, and some haven't. In this case, partStorers would be a mix of B2AlreadyStoredPartStorer and B2UploadingPartStorers.
This method assumes you have already called startLargeFile(). The return value of that call needs to be passed into this method as part of a B2StoreLargeFileRequest. Note that each part, whether copied or uploaded, is still subject to the minimum part size. Note also that this method does not finish the large file.
- Specified by:
storePartsForLargeFilein interfaceB2StorageClient- Parameters:
storeLargeFileRequest- The B2StoreLargeFileRequest for the large file for which these parts are being stored. This is built from the return value of startLargeFile() and any other relevant parameters.partStorers- The list of objects that know how to store the part they are responsible for.uploadListenerOrNull- The object that handles upload progress events. This may be null if you do not need to be notified of progress events.executor- The executor for uploading parts in parallel. The caller retains ownership of the executor and is responsible for shutting it down.- Returns:
- The list of parts after all have been stored.
- Throws:
B2Exception- If there's trouble.
-
fileVersions
public B2ListFilesIterable fileVersions(B2ListFileVersionsRequest request) throws B2Exception
Description copied from interface:B2StorageClientReturns an iterable whose iterator yields the fileVersions that match the given request. It will automatically call B2 to get batches of answers as needed. If there's any trouble during hasNext() or next(), it will throw a B2RuntimeException since Iterable<> doesn't allow checked exceptions to be thrown.- Specified by:
fileVersionsin interfaceB2StorageClient- Parameters:
request- specifies which fileVersions to list.- Returns:
- a new iterable to iterate over fileVersions that match the given request.
- Throws:
B2Exception- if there's any trouble
-
fileNames
public B2ListFilesIterable fileNames(B2ListFileNamesRequest request) throws B2Exception
Description copied from interface:B2StorageClientReturns an iterable whose iterator yields the fileNames that match the given request. It will automatically call B2 to get batches of answers as needed. If there's any trouble during hasNext() or next(), it will throw a B2RuntimeException since Iterable<> doesn't allow checked exceptions to be thrown.- Specified by:
fileNamesin interfaceB2StorageClient- Parameters:
request- specifies which fileVersions to list.- Returns:
- a new iterable to iterate over fileVersions that match the given request.
- Throws:
B2Exception- if there's any trouble
-
unfinishedLargeFiles
public B2ListFilesIterable unfinishedLargeFiles(B2ListUnfinishedLargeFilesRequest request)
Description copied from interface:B2StorageClientReturns an iterable whose iterator yields the fileVersions of large, unfinished files that match the given request. It will automatically call B2 to get batches of answers as needed. If there's any trouble during hasNext() or next(), it will throw a B2RuntimeException since Iterable<> doesn't allow checked exceptions to be thrown.- Specified by:
unfinishedLargeFilesin interfaceB2StorageClient- Parameters:
request- specifies which unfinished large files to list- Returns:
- a new iterable to iterate over fileVersions that match the given request.
-
parts
public B2ListPartsIterable parts(B2ListPartsRequest request) throws B2Exception
Description copied from interface:B2StorageClientReturns an iterable whose iterator yields the parts of large, unfinished files that match the given request. It will automatically call B2 to get batches of answers as needed. If there's any trouble during hasNext() or next(), it will throw a B2RuntimeException since Iterable<> doesn't allow checked exceptions to be thrown.- Specified by:
partsin interfaceB2StorageClient- Parameters:
request- specifies which parts to list- Returns:
- a new iterable to iterate over parts that match the given request.
- Throws:
B2Exception- if there's any trouble
-
cancelLargeFile
public void cancelLargeFile(B2CancelLargeFileRequest request) throws B2Exception
Description copied from interface:B2StorageClientCancels an unfinished large file.- Specified by:
cancelLargeFilein interfaceB2StorageClient- Parameters:
request- specifies which unfinsihed large file to cancel.- Throws:
B2Exception- if there's any trouble.
-
downloadById
public void downloadById(B2DownloadByIdRequest request, B2ContentSink handler) throws B2Exception
Description copied from interface:B2StorageClientAsks to download the specified file by id.- Specified by:
downloadByIdin interfaceB2StorageClient- Parameters:
request- specifies the file and which part of the file to request.handler- if the server starts sending us the file, the headers and input stream are passed to the handler. NOTE: if you get an exception while processing the stream, be sure to clean up anything you've created. the handler may or may not be called again based on the exception.- Throws:
B2Exception- if there's trouble with the request or if the handler throws an exception.
-
getDownloadByIdUrl
public java.lang.String getDownloadByIdUrl(B2DownloadByIdRequest request) throws B2Exception
Description copied from interface:B2StorageClientReturns the URL for downloading the file specified by the request. Note that note all of the request will be represented in the URL. For instance, the url will not contain authorization or range information since we normally send those in the request headers.This is useful for generating public URLs and as part of generating signed download URLs.
- Specified by:
getDownloadByIdUrlin interfaceB2StorageClient- Parameters:
request- specifies what to download.- Returns:
- a URL for fetching the file.
- Throws:
B2Exception- if there's any trouble.
-
getDownloadByNameUrl
public java.lang.String getDownloadByNameUrl(B2DownloadByNameRequest request) throws B2Exception
Description copied from interface:B2StorageClientReturns the URL for downloading the file specified by the request. Note that note all of the request will be represented in the URL. For instance, the url will not contain authorization or range information since we normally send those in the request headers.This is useful for generating public URLs and as part of generating signed download URLs.
- Specified by:
getDownloadByNameUrlin interfaceB2StorageClient- Parameters:
request- specifies what to download.- Returns:
- a URL for fetching the file.
- Throws:
B2Exception- if there's any trouble.
-
downloadByName
public void downloadByName(B2DownloadByNameRequest request, B2ContentSink handler) throws B2Exception
Description copied from interface:B2StorageClientAsks to download the specified file by bucket name and file name.- Specified by:
downloadByNamein interfaceB2StorageClient- Parameters:
request- specifies the file and which part of the file to request.handler- if the server starts sending us the file, the headers and input stream are passed to the handler. NOTE: if you get an exception while processing the stream, be sure to clean up anything you've created. the handler may or may not be called again based on the exception.- Throws:
B2Exception- if there's trouble with the request or if the handler throws an exception.
-
deleteFileVersion
public void deleteFileVersion(B2DeleteFileVersionRequest request) throws B2Exception
Description copied from interface:B2StorageClientDeletes the specified file version.- Specified by:
deleteFileVersionin interfaceB2StorageClient- Parameters:
request- specifies which fileVersion to delete.- Throws:
B2Exception- if there's any trouble.
-
getDownloadAuthorization
public B2DownloadAuthorization getDownloadAuthorization(B2GetDownloadAuthorizationRequest request) throws B2Exception
- Specified by:
getDownloadAuthorizationin interfaceB2StorageClient- Parameters:
request- specifies what the download authorization should allow.- Returns:
- a download authorization
- Throws:
B2Exception- if there's any trouble.
-
getFileInfo
public B2FileVersion getFileInfo(B2GetFileInfoRequest request) throws B2Exception
- Specified by:
getFileInfoin interfaceB2StorageClient- Parameters:
request- specifies the file whose info to fetch.- Returns:
- a B2FileVersion object
- Throws:
B2Exception- if there's any trouble.
-
getFileInfoByName
public B2FileVersion getFileInfoByName(B2GetFileInfoByNameRequest request) throws B2Exception
- Specified by:
getFileInfoByNamein interfaceB2StorageClient- Parameters:
request- specifies the file whose info to fetch.- Returns:
- a B2FileVersion object
- Throws:
B2Exception- if there's any trouble.
-
hideFile
public B2FileVersion hideFile(B2HideFileRequest request) throws B2Exception
Description copied from interface:B2StorageClientHides the specified file.- Specified by:
hideFilein interfaceB2StorageClient- Parameters:
request- specifies the file to hide- Returns:
- the fileVersion that's hiding the specified path
- Throws:
B2Exception- if there's any trouble.
-
updateBucket
public B2Bucket updateBucket(B2UpdateBucketRequest request) throws B2Exception
Description copied from interface:B2StorageClientUpdates the specified bucket as described by the request.- Specified by:
updateBucketin interfaceB2StorageClient- Parameters:
request- specifies which bucket to update and how to update it.- Returns:
- the new state of the bucket
- Throws:
B2Exception- if there's any trouble.- See Also:
- b2_update_bucket
-
deleteBucket
public B2Bucket deleteBucket(B2DeleteBucketRequest request) throws B2Exception
Description copied from interface:B2StorageClientDeletes the specified bucket. Note that it must be empty.- Specified by:
deleteBucketin interfaceB2StorageClient- Parameters:
request- specifies the bucket to delete.- Returns:
- the deleted bucket
- Throws:
B2Exception- if there's any trouble.
-
getAccountAuthorization
public B2AccountAuthorization getAccountAuthorization() throws B2Exception
Description copied from interface:B2StorageClientThis method provides access to an account authorization structure. The returned structure may have been cached. When possible, you should use other objects and helpers instead of using the account authorization directly, so that the B2StorageClient can properly invalidate the cached authorization, if any, in response to interactions with the server. For instance, for downloading: * to download files, use downloadByName() or downloadById(). * if you don't want to download directly, but need to give a download url to some other code, use getDownloadByIdUrl() or getDownloadByNameUrl(). * if neither of those will work for you because you need some other code to be able to form the download urls itself, you may need to getAccountAuthorization() and get the downloadUrl from it. For instance, when deciding whether to use uploadSmallFile() or uploadLargeFile(), call getFilePolicy() and use the helper methods on the result.- Specified by:
getAccountAuthorizationin interfaceB2StorageClient- Returns:
- the account authorization, possibly from a cache.
- Throws:
B2Exception- if there's trouble getting the authorization.
-
invalidateAccountAuthorization
public void invalidateAccountAuthorization()
Description copied from interface:B2StorageClientIf there's a cached account authorization, this will flush the cache so that the authorization will need to be reacquired the next time it is needed. (Keep in mind that another thread may need it and reacquire it before this method even returns.) You should never need to call this unless you have called getAccountAuthorization() and have gotten some kind of authorization exception when using the contents of that authorization. It's really a lot simpler for you if you never do that and instead always do your work through B2StorageClient's APIs!- Specified by:
invalidateAccountAuthorizationin interfaceB2StorageClient
-
getUploadUrl
public B2UploadUrlResponse getUploadUrl(B2GetUploadUrlRequest request) throws B2Exception
Description copied from interface:B2StorageClientThis method allows the caller to get an upload url and authorization token directly. Note that the SDK has lots of logic to upload files and getting upload URLs and using them outside the SDK means that you need to handle lots of details of uploading by yourself including: * retrying based on the types of errors you get, with proper backoff. * refreshing your account authorization when it expires. * reusing upload urls when possible * etc. When possible you should seriously consider using uploadSmallFile() and uploadLargeFile() instead of reimplementing that logic. If there's a reason you can't use those methods, let us know. Perhaps we can improve things together to meet your needs.- Specified by:
getUploadUrlin interfaceB2StorageClient- Parameters:
request- specifies details about the desired upload url and credentials.- Returns:
- the response from the server.
- Throws:
B2Exception- if there's any trouble.
-
getUploadPartUrl
public B2UploadPartUrlResponse getUploadPartUrl(B2GetUploadPartUrlRequest request) throws B2Exception
Description copied from interface:B2StorageClientThis method allows the caller to get an upload url and authorization token directly for uploading a large file part. Note that the SDK has lots of logic to upload files and getting upload URLs and using them outside the SDK means that you need to handle lots of details of uploading by yourself including: * retrying based on the types of errors you get, with proper backoff. * refreshing your account authorization when it expires. * reusing upload urls when possible * etc. When possible you should seriously consider using uploadSmallFile() and uploadLargeFile() instead of reimplementing that logic. If there's a reason you can't use those methods, let us know. Perhaps we can improve things together to meet your needs.- Specified by:
getUploadPartUrlin interfaceB2StorageClient- Parameters:
request- specifies details about the desired upload url and credentials.- Returns:
- the response from the server.
- Throws:
B2Exception- if there's any trouble.
-
startLargeFile
public B2FileVersion startLargeFile(B2StartLargeFileRequest request) throws B2Exception
Description copied from interface:B2StorageClientThis method allows the caller to start a large file. Note that the SDK has lots of logic to upload large files and doing your own uploading outside the SDK means that you need to handle lots of details of uploading by yourself including: * retrying based on the types of errors you get, with proper backoff. * refreshing your account authorization when it expires. * reusing upload urls when possible * etc. When possible you should seriously consider using uploadLargeFile() instead of reimplementing that logic. If there's a reason you can't use those methods, let us know. Perhaps we can improve things together to meet your needs.- Specified by:
startLargeFilein interfaceB2StorageClient- Parameters:
request- specifies details about the file to start.- Returns:
- the response from the server.
- Throws:
B2Exception- if there's any trouble.
-
finishLargeFile
public B2FileVersion finishLargeFile(B2FinishLargeFileRequest request) throws B2Exception
Description copied from interface:B2StorageClientThis method allows the caller to finish a large file. Note that the SDK has lots of logic to upload large files and doing your own uploading outside the SDK means that you need to handle lots of details of uploading by yourself including: * retrying based on the types of errors you get, with proper backoff. * refreshing your account authorization when it expires. * reusing upload urls when possible * etc. When possible you should seriously consider using uploadLargeFile() or finishUploadingLargeFile() instead of reimplementing that logic. If there's a reason you can't use those methods, let us know. Perhaps we can improve things together to meet your needs.- Specified by:
finishLargeFilein interfaceB2StorageClient- Parameters:
request- specifies details about the file to finish.- Returns:
- the response from the server.
- Throws:
B2Exception- if there's any trouble.
-
updateFileLegalHold
public B2UpdateFileLegalHoldResponse updateFileLegalHold(B2UpdateFileLegalHoldRequest request) throws B2Exception
Description copied from interface:B2StorageClientUpdates the legal hold configuration of the specified file as described by the request.- Specified by:
updateFileLegalHoldin interfaceB2StorageClient- Parameters:
request- specifies which file to update and how to update it.- Returns:
- the new state of the file
- Throws:
B2Exception- if there's any trouble.- See Also:
- b2_update_file_legal_hold
-
updateFileRetention
public B2UpdateFileRetentionResponse updateFileRetention(B2UpdateFileRetentionRequest request) throws B2Exception
Description copied from interface:B2StorageClientUpdates the file retention configuration of the specified file as described by the request.- Specified by:
updateFileRetentionin interfaceB2StorageClient- Parameters:
request- specifies which file to update and how to update it.- Returns:
- the new state of the file
- Throws:
B2Exception- if there's any trouble.- See Also:
- b2_update_file_retention
-
setBucketNotificationRules
public B2SetBucketNotificationRulesResponse setBucketNotificationRules(B2SetBucketNotificationRulesRequest request) throws B2Exception
Description copied from interface:B2StorageClientSets the bucket's event notification rules as described by the request.- Specified by:
setBucketNotificationRulesin interfaceB2StorageClient- Parameters:
request- specifies which bucket to update and how to update the event notification rules.- Returns:
- the new state of the bucket's event notification rules
- Throws:
B2Exception- if there's any trouble.- See Also:
- b2_set_bucket_notification_rules
-
getBucketNotificationRules
public B2GetBucketNotificationRulesResponse getBucketNotificationRules(B2GetBucketNotificationRulesRequest request) throws B2Exception
Description copied from interface:B2StorageClientGets the bucket's event notification rules as described by the request.- Specified by:
getBucketNotificationRulesin interfaceB2StorageClient- Parameters:
request- specifies which bucket to get the event notification rules from.- Returns:
- the current state of the bucket's event notification rules
- Throws:
B2Exception- if there's any trouble.- See Also:
- b2_get_bucket_notification_rules
-
-