Package com.backblaze.b2.client
Class B2CancellableContentSource
- java.lang.Object
-
- com.backblaze.b2.client.B2CancellableContentSource
-
- All Implemented Interfaces:
B2ContentSource
public class B2CancellableContentSource extends java.lang.Object implements B2ContentSource
A ContentSource wrapper that returns an InputStream that will check whether the cancellation token says to stop.
-
-
Constructor Summary
Constructors Constructor Description B2CancellableContentSource(B2ContentSource source, B2CancellationToken cancellationToken)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStream
createInputStream()
NOTE: this may be called multiple times as uploads are retried, etc.long
getContentLength()
java.lang.String
getSha1OrNull()
You are encouraged to implement this.java.lang.Long
getSrcLastModifiedMillisOrNull()
-
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.contentSources.B2ContentSource
createContentSourceWithRangeOrNull
-
-
-
-
Constructor Detail
-
B2CancellableContentSource
public B2CancellableContentSource(B2ContentSource source, B2CancellationToken cancellationToken)
-
-
Method Detail
-
getContentLength
public long getContentLength() throws java.io.IOException
- Specified by:
getContentLength
in interfaceB2ContentSource
- Returns:
- the number of bytes in the content. the length must be non-negative.
- Throws:
java.io.IOException
- if there's trouble
-
getSha1OrNull
public java.lang.String getSha1OrNull() throws java.io.IOException
Description copied from interface:B2ContentSource
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- Specified by:
getSha1OrNull
in interfaceB2ContentSource
- 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
public java.lang.Long getSrcLastModifiedMillisOrNull() throws java.io.IOException
- Specified by:
getSrcLastModifiedMillisOrNull
in interfaceB2ContentSource
- 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
public java.io.InputStream createInputStream() throws java.io.IOException, B2Exception
Description copied from interface:B2ContentSource
NOTE: this may be called multiple times as uploads are retried, etc. The content is expected to be identical each time this is called.- Specified by:
createInputStream
in interfaceB2ContentSource
- Returns:
- a new inputStream containing the contents.
- Throws:
java.io.IOException
- if there's troubleB2Exception
- if there's trouble
-
-