mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Simplified flow of interruption of uploads in cancellations
This commit is contained in:
		
							parent
							
								
									8bf276377c
								
							
						
					
					
						commit
						522ea30da0
					
				| @ -32,7 +32,6 @@ import java.io.RandomAccessFile; | ||||
| import java.nio.channels.FileChannel; | ||||
| import java.util.Random; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.HttpException; | ||||
| import org.apache.commons.httpclient.methods.PutMethod; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| @ -85,6 +84,10 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|                 mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(file.length())); | ||||
|                 ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset); | ||||
|                 mPutMethod.setRequestEntity(mEntity); | ||||
|                 if (mCancellationRequested.get()) { | ||||
|                     mPutMethod.abort(); | ||||
|                     // next method will throw an exception | ||||
|                 } | ||||
|                 status = client.executeMethod(mPutMethod); | ||||
| 
 | ||||
|                 if (status == 400) { | ||||
|  | ||||
| @ -67,7 +67,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
| 	protected PutMethod mPutMethod = null; | ||||
| 	protected boolean mForbiddenCharsInServer = false; | ||||
| 	 | ||||
| 	private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); | ||||
| 	protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); | ||||
| 	protected Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>(); | ||||
| 
 | ||||
| 	protected RequestEntity mEntity = null; | ||||
| @ -83,27 +83,28 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
| 		RemoteOperationResult result = null; | ||||
| 
 | ||||
| 		try { | ||||
| 			// / perform the upload | ||||
| 			synchronized (mCancellationRequested) { | ||||
| 				if (mCancellationRequested.get()) { | ||||
| 					throw new OperationCancelledException(); | ||||
| 			mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
| 
 | ||||
| 			if (mCancellationRequested.get()) { | ||||
| 				// the operation was cancelled before getting it's turn to be executed in the queue of uploads | ||||
| 				result = new RemoteOperationResult(new OperationCancelledException()); | ||||
| 
 | ||||
| 			} else { | ||||
| 				// perform the upload | ||||
| 				int status = uploadFile(client); | ||||
| 				if (mForbiddenCharsInServer){ | ||||
| 					result = new RemoteOperationResult( | ||||
| 							RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER); | ||||
| 				} else { | ||||
| 					mPutMethod = new PutMethod(client.getWebdavUri() + | ||||
|                             WebdavUtils.encodePath(mRemotePath)); | ||||
| 					result = new RemoteOperationResult(isSuccess(status), status, | ||||
| 							(mPutMethod != null ? mPutMethod.getResponseHeaders() : null)); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			int status = uploadFile(client); | ||||
| 			if (mForbiddenCharsInServer){ | ||||
| 				result = new RemoteOperationResult( | ||||
| 						RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER); | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(isSuccess(status), status, | ||||
| 						(mPutMethod != null ? mPutMethod.getResponseHeaders() : null)); | ||||
| 			} | ||||
| 		} catch (Exception e) { | ||||
| 			if (mCancellationRequested.get() && !(e instanceof OperationCancelledException)) { | ||||
| 			if (mPutMethod != null && mPutMethod.isAborted()) { | ||||
| 				result = new RemoteOperationResult(new OperationCancelledException()); | ||||
| 
 | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(e); | ||||
| 			} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user