Interface B2StorageClient

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Implementing Classes:
    B2StorageClientImpl

    public interface B2StorageClient
    extends java.io.Closeable
    B2StorageClient is the interface for performing B2 operations. Be sure to close() any instance you create when you are done with it. Try-with-resources can be very useful for that. Here are some design principles: Be type-safe. Use different types for requests & responses. Keep things final. Use builder classes to instantiate objects so it's easier to add new attributes. In addition, we provide convenience methods so the user doesn't have to use the builder, when the object only has one or two simple, obvious arguments. Throw B2Exception, a checked exception, for most problems. THREAD-SAFETY: You may call any methods from any thread at any time. Calls may be blocked waiting for resources, but calling from multiple threads is safe. (This assumes the Webifier is thread-safe, and the default implementation is.) XXX: how much checking of requests should we do? for the moment, i'm inclined to let the server do the bulk of the checking so (1) i don't have to repeat it here and (2) i don't have to rev. the client to let people take advantage of a wider range of inputs, such as more fileInfos.) we may very well revisit this.
    • Method Detail

      • getAccountId

        java.lang.String getAccountId()
                               throws B2Exception
        Returns:
        the accountId for this client.
        Throws:
        B2Exception
      • getFilePolicy

        B2FilePolicy getFilePolicy()
                            throws B2Exception
        Returns:
        an object for answering policy questions, such as whether to upload a file as a small or large file.
        Throws:
        B2Exception
      • createBucket

        B2Bucket createBucket​(B2CreateBucketRequest request)
                       throws B2Exception
        Creates a new bucket with the given request.
        Parameters:
        request - the request to create the bucket.
        Returns:
        the newly created bucket.
        Throws:
        B2Exception - if there's any trouble.
      • createBucket

        default B2Bucket createBucket​(java.lang.String bucketName,
                                      java.lang.String bucketType)
                               throws B2Exception
        Creates a new bucket with the specified bucketName and bucketType and default settings for all of the other bucket attributes.
        Parameters:
        bucketName - the requested name for the bucket
        bucketType - the requested type of the bucket
        Returns:
        the newly created bucket
        Throws:
        B2Exception - if there's any trouble
      • applicationKeys

        B2ListKeysIterable applicationKeys​(B2ListKeysRequest request)
                                    throws B2Exception
        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.
        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
      • applicationKeys

        default B2ListKeysIterable applicationKeys()
                                            throws B2Exception
        Just like applicationKeys(request), except that it makes a request for all application keys for the account.
        Returns:
        a new iterable to iterate over all of the keys in the specified account
        Throws:
        B2Exception - if there's any trouble
      • buckets

        default java.util.List<B2Bucket> buckets()
                                          throws B2Exception
        Returns:
        a new list with all of the account's buckets for the b2 default buckets.
        Throws:
        B2Exception - if there's any trouble.
      • getBucketOrNullByName

        default B2Bucket getBucketOrNullByName​(java.lang.String name)
                                        throws B2Exception
        Returns:
        this account's bucket with the given name, or null if this account doesn't have a bucket with the given name.
        Throws:
        B2Exception - if there's any trouble.
      • uploadSmallFile

        B2FileVersion uploadSmallFile​(B2UploadFileRequest request)
                               throws B2Exception
        Uploads the specified content as a normal B2 file. The file must be smaller than the maximum file size (5 GB).
        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

        B2FileVersion copySmallFile​(B2CopyFileRequest request)
                             throws B2Exception
        Makes a copy of a file in the same bucket. The new file must be smaller than the maximum file size (5 GB).
        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

        B2FileVersion uploadLargeFile​(B2UploadFileRequest request,
                                      java.util.concurrent.ExecutorService executor)
                               throws B2Exception
        Uploads the specified content as separate parts to form a B2 large file.
        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

        B2FileVersion storeLargeFileFromLocalContent​(B2FileVersion fileVersion,
                                                     B2ContentSource contentSource,
                                                     B2UploadListener uploadListenerOrNull,
                                                     java.util.concurrent.ExecutorService executor)
                                              throws B2Exception
        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.
        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:
        The fileVersion of the large file after it has been finished.
        Throws:
        B2Exception - If there's trouble.
      • storeLargeFileFromLocalContent

        B2FileVersion storeLargeFileFromLocalContent​(B2StoreLargeFileRequest storeLargeFileRequest,
                                                     B2ContentSource contentSource,
                                                     B2UploadListener uploadListenerOrNull,
                                                     java.util.concurrent.ExecutorService executor)
                                              throws B2Exception
        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.
        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:
        The fileVersion of the large file after it has been finished.
        Throws:
        B2Exception - If there's trouble.
      • storeLargeFileFromLocalContentAsync

        java.util.concurrent.CompletableFuture<B2FileVersion> storeLargeFileFromLocalContentAsync​(B2FileVersion fileVersion,
                                                                                                  B2ContentSource contentSource,
                                                                                                  B2UploadListener uploadListenerOrNull,
                                                                                                  java.util.concurrent.ExecutorService executor)
                                                                                           throws B2Exception
        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.
        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

        java.util.concurrent.CompletableFuture<B2FileVersion> storeLargeFileFromLocalContentAsync​(B2StoreLargeFileRequest storeLargeFileRequest,
                                                                                                  B2ContentSource contentSource,
                                                                                                  B2UploadListener uploadListenerOrNull,
                                                                                                  java.util.concurrent.ExecutorService executor)
                                                                                           throws B2Exception
        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.
        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

        B2FileVersion storeLargeFile​(B2FileVersion fileVersion,
                                     java.util.List<B2PartStorer> partStorers,
                                     B2UploadListener uploadListenerOrNull,
                                     java.util.concurrent.ExecutorService executor)
                              throws B2Exception
        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.

        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

        B2FileVersion storeLargeFile​(B2StoreLargeFileRequest storeLargeFileRequest,
                                     java.util.List<B2PartStorer> partStorers,
                                     B2UploadListener uploadListenerOrNull,
                                     java.util.concurrent.ExecutorService executor)
                              throws B2Exception
        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.

        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

        java.util.List<B2Part> storePartsForLargeFile​(B2FileVersion fileVersion,
                                                      java.util.List<B2PartStorer> partStorers,
                                                      B2UploadListener uploadListenerOrNull,
                                                      java.util.concurrent.ExecutorService executor)
                                               throws B2Exception
        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.

        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

        java.util.List<B2Part> storePartsForLargeFile​(B2StoreLargeFileRequest storeLargeFileRequest,
                                                      java.util.List<B2PartStorer> partStorers,
                                                      B2UploadListener uploadListenerOrNull,
                                                      java.util.concurrent.ExecutorService executor)
                                               throws B2Exception
        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.

        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.
      • finishUploadingLargeFile

        B2FileVersion finishUploadingLargeFile​(B2FileVersion fileVersion,
                                               B2UploadFileRequest request,
                                               java.util.concurrent.ExecutorService executor)
                                        throws B2Exception
        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!)
        Parameters:
        fileVersion - describes the unfinished large file we want to finish.
        request - describes the content we want to use to finish the large file
        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 the finished large file.
        Throws:
        B2Exception - if there's any trouble.
      • fileVersions

        B2ListFilesIterable fileVersions​(B2ListFileVersionsRequest request)
                                  throws B2Exception
        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.
        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
      • fileVersions

        default B2ListFilesIterable fileVersions​(java.lang.String bucketId)
                                          throws B2Exception
        Just like fileVersions(request), except that it makes a request for all fileVersions in the specified bucket.
        Parameters:
        bucketId - the bucket whose fileVersions you want an Iterable for.
        Returns:
        a new iterable to iterate over all of the fileVersions in the specified bucket.
        Throws:
        B2Exception - if there's any trouble
      • fileNames

        B2ListFilesIterable fileNames​(B2ListFileNamesRequest request)
                               throws B2Exception
        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.
        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

        default B2ListFilesIterable fileNames​(java.lang.String bucketId)
                                       throws B2Exception
        Just like fileNames(request), except that it makes a request for all fileNames in the specified bucket.
        Parameters:
        bucketId - the bucket whose fileNames you want an Iterable for.
        Returns:
        a new iterable to iterate over all of the fileNames in the specified bucket.
        Throws:
        B2Exception - if there's any trouble
      • unfinishedLargeFiles

        B2ListFilesIterable unfinishedLargeFiles​(B2ListUnfinishedLargeFilesRequest request)
                                          throws B2Exception
        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.
        Parameters:
        request - specifies which unfinished large files to list
        Returns:
        a new iterable to iterate over fileVersions that match the given request.
        Throws:
        B2Exception - if there's any trouble
      • unfinishedLargeFiles

        default B2ListFilesIterable unfinishedLargeFiles​(java.lang.String bucketId)
                                                  throws B2Exception
        Just like unfinishedLargeFiles(request), except that it makes a request for all unfinished large files in the specified bucket.
        Parameters:
        bucketId - the bucket whose fileNames you want an Iterable for.
        Returns:
        a new iterable to iterate over all of the unfinished large files in the specified bucket.
        Throws:
        B2Exception - if there's any trouble
      • parts

        B2ListPartsIterable parts​(B2ListPartsRequest request)
                           throws B2Exception
        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.
        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
      • parts

        default B2ListPartsIterable parts​(java.lang.String largeFileId)
                                   throws B2Exception
        Just like parts(request), except that it makes a request for the parts of the specified largeFileId.
        Parameters:
        largeFileId - the large file whose parts you want an Iterable for.
        Returns:
        a new iterable to iterate over all of the parts of the specified file.
        Throws:
        B2Exception - if there's any trouble
      • cancelLargeFile

        void cancelLargeFile​(B2CancelLargeFileRequest cancelRequest)
                      throws B2Exception
        Cancels an unfinished large file.
        Parameters:
        cancelRequest - specifies which unfinsihed large file to cancel.
        Throws:
        B2Exception - if there's any trouble.
      • cancelLargeFile

        default void cancelLargeFile​(java.lang.String largeFileId)
                              throws B2Exception
        Just like cancelLargeFile(request), except that you only need to specify the largeFileId for the unfinished large file you're trying to cancel.
        Parameters:
        largeFileId - specifies the unfinished, large file to cancel.
        Throws:
        B2Exception - if there's any trouble.
      • downloadById

        void downloadById​(B2DownloadByIdRequest request,
                          B2ContentSink handler)
                   throws B2Exception
        Asks to download the specified file by id.
        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.
      • downloadById

        default void downloadById​(java.lang.String fileId,
                                  B2ContentSink handler)
                           throws B2Exception
        Just like downloadById(request), but you only have to specify the fileId instead of a request object.
        Parameters:
        fileId - the id of the file you want to download.
        handler - the handler to process the data as its downloaded.
        Throws:
        B2Exception - if there's any trouble.
      • downloadByName

        void downloadByName​(B2DownloadByNameRequest request,
                            B2ContentSink handler)
                     throws B2Exception
        Asks to download the specified file by bucket name and file name.
        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.
      • downloadByName

        default void downloadByName​(java.lang.String bucketName,
                                    java.lang.String fileName,
                                    B2ContentSink handler)
                             throws B2Exception
        Just like downloadByName(request), but you only have to specify the bucketName and the fileName instead of a request object.
        Parameters:
        bucketName - the name of the bucket you want to download from.
        fileName - the name of the file you want to download.
        handler - the handler to process the data as its downloaded.
        Throws:
        B2Exception - if there's any trouble.
      • deleteFileVersion

        void deleteFileVersion​(B2DeleteFileVersionRequest request)
                        throws B2Exception
        Deletes the specified file version.
        Parameters:
        request - specifies which fileVersion to delete.
        Throws:
        B2Exception - if there's any trouble.
      • deleteFileVersion

        default void deleteFileVersion​(B2FileVersion version)
                                throws B2Exception
        Just like deleteFileVersion(request), except that the request is created from the specified fileVersion.
        Parameters:
        version - specifies the fileVersion to delete.
        Throws:
        B2Exception - if there's any trouble.
      • deleteFileVersion

        default void deleteFileVersion​(java.lang.String fileName,
                                       java.lang.String fileId)
                                throws B2Exception
        Just like deleteFileVersion(request), except that the request is created from the specified fileName and fileId.
        Parameters:
        fileName - the name of the file to delete.
        fileId - the id of the file to delete.
        Throws:
        B2Exception - if there's any trouble.
      • deleteAllFilesInBucket

        default void deleteAllFilesInBucket​(java.lang.String bucketId)
                                     throws B2Exception
        Delete all files in bucket.
        Parameters:
        bucketId - the bucket whose file versions should be deleted
        Throws:
        B2Exception - if there's any trouble. if there's trouble, it's undefined which file versions have been deleted (if any) and which haven't (if any).
      • getFileInfo

        default B2FileVersion getFileInfo​(java.lang.String fileId)
                                   throws B2Exception
        Just like getFileInfo(request) except that the request is created from the given fileId.
        Parameters:
        fileId - specifies the file whose info to fetch.
        Returns:
        a B2FileVersion object
        Throws:
        B2Exception - if there's any trouble.
      • getFileInfoByName

        default B2FileVersion getFileInfoByName​(java.lang.String bucketName,
                                                java.lang.String fileName)
                                         throws B2Exception
        Just like getFileInfoByName(request), but for the most recent version of file with the specified fileName in the specified bucket.
        Parameters:
        bucketName - bucketName the name of the bucket containing the file you want info about.
        fileName - fileName the name of the file whose info you're interested in.
        Throws:
        B2Exception - if there's any trouble.
      • hideFile

        B2FileVersion hideFile​(B2HideFileRequest request)
                        throws B2Exception
        Hides the specified file.
        Parameters:
        request - specifies the file to hide
        Returns:
        the fileVersion that's hiding the specified path
        Throws:
        B2Exception - if there's any trouble.
      • hideFile

        default B2FileVersion hideFile​(java.lang.String bucketId,
                                       java.lang.String fileName)
                                throws B2Exception
        Just like hideFile(request) except the request is created from the given bucketId and fileName.
        Parameters:
        bucketId - the id of the bucket containing the file we want to hide
        fileName - the name of the file we want to hide
        Returns:
        the fileVersion that's hiding the specified path
        Throws:
        B2Exception - if there's any trouble.
      • updateBucket

        B2Bucket updateBucket​(B2UpdateBucketRequest request)
                       throws B2Exception
        Updates the specified bucket as described by the request.
        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

        B2Bucket deleteBucket​(B2DeleteBucketRequest request)
                       throws B2Exception
        Deletes the specified bucket. Note that it must be empty.
        Parameters:
        request - specifies the bucket to delete.
        Returns:
        the deleted bucket
        Throws:
        B2Exception - if there's any trouble.
      • deleteBucket

        default B2Bucket deleteBucket​(java.lang.String bucketId)
                               throws B2Exception
        Just like deleteBucket(request) except that the request is created from the specified bucketId.
        Parameters:
        bucketId - the bucket to delete.
        Returns:
        the deleted bucket
        Throws:
        B2Exception - if there's any trouble.
      • getDownloadByIdUrl

        java.lang.String getDownloadByIdUrl​(B2DownloadByIdRequest request)
                                     throws B2Exception
        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.

        Parameters:
        request - specifies what to download.
        Returns:
        a URL for fetching the file.
        Throws:
        B2Exception - if there's any trouble.
      • getDownloadByIdUrl

        default java.lang.String getDownloadByIdUrl​(java.lang.String fileId)
                                             throws B2Exception
        Just like getDownloadByIdUrl(request) except that the request is created from the given fileId.
        Parameters:
        fileId - the file whose download url we're interested in.
        Returns:
        the URL
        Throws:
        B2Exception - if there's any trouble.
      • getDownloadByNameUrl

        java.lang.String getDownloadByNameUrl​(B2DownloadByNameRequest request)
                                       throws B2Exception
        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.

        Parameters:
        request - specifies what to download.
        Returns:
        a URL for fetching the file.
        Throws:
        B2Exception - if there's any trouble.
      • getDownloadByNameUrl

        default java.lang.String getDownloadByNameUrl​(java.lang.String bucketName,
                                                      java.lang.String fileName)
                                               throws B2Exception
        Just like getDownloadByIdUrl(request) except that the request is created from the given bucketName and fileName.
        Parameters:
        bucketName - the name of the bucket that contains the desired file.
        fileName - the name of the file whose download URL we want.
        Returns:
        the URL
        Throws:
        B2Exception - if there's any trouble.
      • getAccountAuthorization

        B2AccountAuthorization getAccountAuthorization()
                                                throws B2Exception
        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.
        Returns:
        the account authorization, possibly from a cache.
        Throws:
        B2Exception - if there's trouble getting the authorization.
      • invalidateAccountAuthorization

        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. (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!
      • getUploadUrl

        B2UploadUrlResponse getUploadUrl​(B2GetUploadUrlRequest request)
                                  throws B2Exception
        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.
        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

        B2UploadPartUrlResponse getUploadPartUrl​(B2GetUploadPartUrlRequest request)
                                          throws B2Exception
        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.
        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

        B2FileVersion startLargeFile​(B2StartLargeFileRequest request)
                              throws B2Exception
        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.
        Parameters:
        request - specifies details about the file to start.
        Returns:
        the response from the server.
        Throws:
        B2Exception - if there's any trouble.
      • finishLargeFile

        B2FileVersion finishLargeFile​(B2FinishLargeFileRequest request)
                               throws B2Exception
        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.
        Parameters:
        request - specifies details about the file to finish.
        Returns:
        the response from the server.
        Throws:
        B2Exception - if there's any trouble.
      • setBucketNotificationRules

        default B2SetBucketNotificationRulesResponse setBucketNotificationRules​(java.lang.String bucketId,
                                                                                java.util.List<B2EventNotificationRule> eventNotificationRules)
                                                                         throws B2Exception
        Just like setBucketNotificationRules(request), except that the request is created from the specified bucketId and eventNotificationRules.
        Parameters:
        bucketId - the bucket whose eventNotificationRules you want to set.
        eventNotificationRules - the eventNotificationRules to set on the bucket.
        Throws:
        B2Exception - if there's any trouble.
      • getBucketNotificationRules

        default B2GetBucketNotificationRulesResponse getBucketNotificationRules​(java.lang.String bucketId)
                                                                         throws B2Exception
        Just like getBucketNotificationRules(request), except that the request is created from the specified bucketId.
        Parameters:
        bucketId - the bucket whose eventNotificationRules you want to get.
        Throws:
        B2Exception - if there's any trouble.
      • close

        void close()
        Closes this instance, releasing resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable