Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify upload pausing #42

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/main/java/io/tus/java/client/TusUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,40 @@ public URL getUploadURL() {
* Finish the request by closing the HTTP connection and the InputStream.
* You can call this method even before the entire file has been uploaded. Use this behavior to
* enable pausing uploads.
* This method is equivalent to calling {@code finish(false)}.
*
* @throws ProtocolException Thrown if the server sends an unexpected status
* code
* @throws IOException Thrown if an exception occurs while cleaning up.
*/
public void finish() throws ProtocolException, IOException {
finish(true);
}

/**
* Finish the request by closing the HTTP connection. You can choose whether to close the InputStream or not.
* You can call this method even before the entire file has been uploaded. Use this behavior to
* enable pausing uploads.
*
* Be aware that it doesn't automatically release local resources if {@code closeStream == false} and you do
* not close the InputStream on your own. To be safe use {@link TusUploader#finish()}.
*
* @param closeInputStream Determines whether the InputStream is closed with the HTTP connection. Not closing the
* Input Stream may be useful for future upload a future continuation of the upload.
* @throws ProtocolException Thrown if the server sends an unexpected status code
* @throws IOException Thrown if an exception occurs while cleaning up.
*/
public void finish(boolean closeInputStream) throws ProtocolException, IOException {
finishConnection();
if (upload.getSize() == offset) {
client.uploadFinished(upload);
}

// Close the TusInputStream after checking the response and closing the connection to ensure
// that we will not need to read from it again in the future.
input.close();
if (closeInputStream) {
input.close();
}
}

private void finishConnection() throws ProtocolException, IOException {
Expand Down