Interface B2ContentSource

  • All Known Implementing Classes:
    B2ByteArrayContentSource, B2CancellableContentSource, B2FileContentSource

    public interface B2ContentSource
    Implementations of B2ContentSource provide the length, SHA1, and the bytes that the B2Client should upload. There are common implementations of this class, such as B2FileContentSource and MemoryContentSource.
    • Method Detail

      • getContentLength

        long getContentLength()
                       throws java.io.IOException
        Returns:
        the number of bytes in the content. the length must be non-negative.
        Throws:
        java.io.IOException - if there's trouble
      • getSha1OrNull

        java.lang.String getSha1OrNull()
                                throws java.io.IOException
        You are encouraged to implement this. If it returns non-null, the B2Client can provide the sha1 before performing the upload. Definitely implement this if you've stored the sha1 separately from the file. That way you can ensure that B2 doesn't take the file if there's trouble reading it from your source. If you return null, B2StorageClient will compute the SHA1 from the bytes in the stream. Note that large files do not have SHA-1s for the entire file. If you provide a SHA-1 for a large file upload, the SDK follows the recommendation of putting your value into the 'large_file_sha1' fileInfo. See "SHA1 Checksums" in https://www.backblaze.com/b2/docs/large_files.html
        Returns:
        the hex-encoded sha1 for the content or null if it's not known yet.
        Throws:
        java.io.IOException - if there's trouble
      • getSrcLastModifiedMillisOrNull

        java.lang.Long getSrcLastModifiedMillisOrNull()
                                               throws java.io.IOException
        Returns:
        the time the source was last modified (in milliseconds since the epoch) or null if there isn't a reasonable value for that.
        Throws:
        java.io.IOException - if there's trouble
      • createInputStream

        java.io.InputStream createInputStream()
                                       throws java.io.IOException,
                                              B2Exception
        NOTE: this may be called multiple times as uploads are retried, etc. The content is expected to be identical each time this is called.
        Returns:
        a new inputStream containing the contents.
        Throws:
        java.io.IOException - if there's trouble
        B2Exception - if there's trouble
      • createContentSourceWithRangeOrNull

        default B2ContentSource createContentSourceWithRangeOrNull​(long start,
                                                                   long length)
                                                            throws java.io.IOException
        If possible, this returns a NEW input stream for just the specified range of the content. If it's not possible (or just not implemented), this returns null. The large file uploading mechanism uses this call to get a stream for each part that will be uploaded separately. If this returns null, the large file uploader will use createInputStream() and read and discard the initial part of the stream to get to the part it needs. This method is optional. However, if your content source will be used for large file uploads, please implement it to make your uploads more efficient. NOTE: this may be called multiple times as uploads are retried, etc. The overall content is expected to be identical each time this is called.
        Returns:
        a new inputStream containing the specified range of the overall contents.
        Throws:
        java.io.IOException - if there's trouble