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 B2ListKeysIterable
applicationKeys(B2ListKeysRequest request)
Returns an iterable whose iterator yields the application keys that match the given request.void
cancelLargeFile(B2CancelLargeFileRequest request)
Cancels an unfinished large file.void
close()
Closes resources used by this client.B2FileVersion
copySmallFile(B2CopyFileRequest request)
Makes a copy of a file in the same bucket.B2Bucket
createBucket(B2CreateBucketRequest request)
Creates a new bucket with the given request.B2CreatedApplicationKey
createKey(B2CreateKeyRequest request)
Creates a new application key.B2Bucket
deleteBucket(B2DeleteBucketRequest request)
Deletes the specified bucket.void
deleteFileVersion(B2DeleteFileVersionRequest request)
Deletes the specified file version.B2ApplicationKey
deleteKey(B2DeleteKeyRequest request)
Deletes the specified application key.void
downloadById(B2DownloadByIdRequest request, B2ContentSink handler)
Asks to download the specified file by id.void
downloadByName(B2DownloadByNameRequest request, B2ContentSink handler)
Asks to download the specified file by bucket name and file name.B2ListFilesIterable
fileNames(B2ListFileNamesRequest request)
Returns an iterable whose iterator yields the fileNames that match the given request.B2ListFilesIterable
fileVersions(B2ListFileVersionsRequest request)
Returns an iterable whose iterator yields the fileVersions that match the given request.B2FileVersion
finishLargeFile(B2FinishLargeFileRequest request)
This method allows the caller to finish a large file.B2FileVersion
finishUploadingLargeFile(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.B2AccountAuthorization
getAccountAuthorization()
This method provides access to an account authorization structure.java.lang.String
getAccountId()
B2GetBucketNotificationRulesResponse
getBucketNotificationRules(B2GetBucketNotificationRulesRequest request)
Gets the bucket's event notification rules as described by the request.B2DownloadAuthorization
getDownloadAuthorization(B2GetDownloadAuthorizationRequest request)
java.lang.String
getDownloadByIdUrl(B2DownloadByIdRequest request)
Returns the URL for downloading the file specified by the request.java.lang.String
getDownloadByNameUrl(B2DownloadByNameRequest request)
Returns the URL for downloading the file specified by the request.B2FileVersion
getFileInfo(B2GetFileInfoRequest request)
B2FileVersion
getFileInfoByName(B2GetFileInfoByNameRequest request)
B2FilePolicy
getFilePolicy()
B2UploadPartUrlResponse
getUploadPartUrl(B2GetUploadPartUrlRequest request)
This method allows the caller to get an upload url and authorization token directly for uploading a large file part.B2UploadUrlResponse
getUploadUrl(B2GetUploadUrlRequest request)
This method allows the caller to get an upload url and authorization token directly.B2StorageClientWebifier
getWebifier()
B2FileVersion
hideFile(B2HideFileRequest request)
Hides the specified file.void
invalidateAccountAuthorization()
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.B2ListBucketsResponse
listBuckets(B2ListBucketsRequest listBucketsRequest)
B2ListPartsIterable
parts(B2ListPartsRequest request)
Returns an iterable whose iterator yields the parts of large, unfinished files that match the given request.B2SetBucketNotificationRulesResponse
setBucketNotificationRules(B2SetBucketNotificationRulesRequest request)
Sets the bucket's event notification rules as described by the request.B2FileVersion
startLargeFile(B2StartLargeFileRequest request)
This method allows the caller to start a large file.B2FileVersion
storeLargeFile(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.B2FileVersion
storeLargeFile(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().B2FileVersion
storeLargeFileFromLocalContent(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.B2FileVersion
storeLargeFileFromLocalContent(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().B2ListFilesIterable
unfinishedLargeFiles(B2ListUnfinishedLargeFilesRequest request)
Returns an iterable whose iterator yields the fileVersions of large, unfinished files that match the given request.B2Bucket
updateBucket(B2UpdateBucketRequest request)
Updates the specified bucket as described by the request.B2UpdateFileLegalHoldResponse
updateFileLegalHold(B2UpdateFileLegalHoldRequest request)
Updates the legal hold configuration of the specified file as described by the request.B2UpdateFileRetentionResponse
updateFileRetention(B2UpdateFileRetentionRequest request)
Updates the file retention configuration of the specified file as described by the request.B2FileVersion
uploadLargeFile(B2UploadFileRequest request, java.util.concurrent.ExecutorService executor)
Uploads the specified content as separate parts to form a B2 large file.B2FileVersion
uploadSmallFile(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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceB2StorageClient
- Specified by:
close
in interfacejava.io.Closeable
-
getAccountId
public java.lang.String getAccountId() throws B2Exception
- Specified by:
getAccountId
in interfaceB2StorageClient
- Returns:
- the accountId for this client.
- Throws:
B2Exception
-
getFilePolicy
public B2FilePolicy getFilePolicy() throws B2Exception
- Specified by:
getFilePolicy
in 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:
getWebifier
in interfaceB2StorageClient
-
createBucket
public B2Bucket createBucket(B2CreateBucketRequest request) throws B2Exception
Description copied from interface:B2StorageClient
Creates a new bucket with the given request.- Specified by:
createBucket
in 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:B2StorageClient
Creates a new application key.- Specified by:
createKey
in 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:B2StorageClient
Returns 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:
applicationKeys
in 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:B2StorageClient
Deletes the specified application key.- Specified by:
deleteKey
in 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:
listBuckets
in 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:B2StorageClient
Verifies 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:
finishUploadingLargeFile
in 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:B2StorageClient
Uploads the specified content as a normal B2 file. The file must be smaller than the maximum file size (5 GB).- Specified by:
uploadSmallFile
in 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:B2StorageClient
Makes a copy of a file in the same bucket. The new file must be smaller than the maximum file size (5 GB).- Specified by:
copySmallFile
in 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:B2StorageClient
Uploads the specified content as separate parts to form a B2 large file.- Specified by:
uploadLargeFile
in 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:B2StorageClient
Uploads 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:
storeLargeFileFromLocalContent
in 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:B2StorageClient
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(). 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:
storeLargeFileFromLocalContent
in 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:B2StorageClient
Initiates 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:
storeLargeFileFromLocalContentAsync
in 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:B2StorageClient
Initiates 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:
storeLargeFileFromLocalContentAsync
in 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:B2StorageClient
Stores 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:
storeLargeFile
in 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:B2StorageClient
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().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:
storeLargeFile
in 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:B2StorageClient
Stores 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:
storePartsForLargeFile
in 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:B2StorageClient
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().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:
storePartsForLargeFile
in 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:B2StorageClient
Returns 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:
fileVersions
in 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:B2StorageClient
Returns 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:
fileNames
in 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:B2StorageClient
Returns 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:
unfinishedLargeFiles
in 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:B2StorageClient
Returns 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:
parts
in 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:B2StorageClient
Cancels an unfinished large file.- Specified by:
cancelLargeFile
in 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:B2StorageClient
Asks to download the specified file by id.- Specified by:
downloadById
in 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:B2StorageClient
Returns 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:
getDownloadByIdUrl
in 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:B2StorageClient
Returns 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:
getDownloadByNameUrl
in 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:B2StorageClient
Asks to download the specified file by bucket name and file name.- Specified by:
downloadByName
in 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:B2StorageClient
Deletes the specified file version.- Specified by:
deleteFileVersion
in 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:
getDownloadAuthorization
in 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:
getFileInfo
in 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:
getFileInfoByName
in 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:B2StorageClient
Hides the specified file.- Specified by:
hideFile
in 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:B2StorageClient
Updates the specified bucket as described by the request.- Specified by:
updateBucket
in 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:B2StorageClient
Deletes the specified bucket. Note that it must be empty.- Specified by:
deleteBucket
in 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:B2StorageClient
This 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:
getAccountAuthorization
in 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:B2StorageClient
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. (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:
invalidateAccountAuthorization
in interfaceB2StorageClient
-
getUploadUrl
public B2UploadUrlResponse getUploadUrl(B2GetUploadUrlRequest request) throws B2Exception
Description copied from interface:B2StorageClient
This 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:
getUploadUrl
in 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:B2StorageClient
This 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:
getUploadPartUrl
in 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:B2StorageClient
This 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:
startLargeFile
in 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:B2StorageClient
This 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:
finishLargeFile
in 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:B2StorageClient
Updates the legal hold configuration of the specified file as described by the request.- Specified by:
updateFileLegalHold
in 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:B2StorageClient
Updates the file retention configuration of the specified file as described by the request.- Specified by:
updateFileRetention
in 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:B2StorageClient
Sets the bucket's event notification rules as described by the request.- Specified by:
setBucketNotificationRules
in 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:B2StorageClient
Gets the bucket's event notification rules as described by the request.- Specified by:
getBucketNotificationRules
in 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
-
-