mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 18:37:17 +00:00 
			
		
		
		
	Implement move method and finish basic chunked uploads
This commit is contained in:
		
							parent
							
								
									1d80067f85
								
							
						
					
					
						commit
						c8a0451e06
					
				| @ -1,5 +1,7 @@ | ||||
| package com.owncloud.android.lib.common.http.methods.webdav; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.http.HttpConstants; | ||||
| 
 | ||||
| import at.bitfire.dav4android.exception.UnauthorizedException; | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| @ -16,7 +18,12 @@ public class MoveMethod extends DavMethod { | ||||
|     @Override | ||||
|     public int execute() throws Exception { | ||||
|         try { | ||||
|             mDavResource.move(destinationUrl, forceOverride); | ||||
|             mDavResource.move( | ||||
|                     destinationUrl, | ||||
|                     forceOverride, | ||||
|                     super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), | ||||
|                     super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) | ||||
|             ); | ||||
| 
 | ||||
|             mRequest = mDavResource.getRequest(); | ||||
|             mResponse = mDavResource.getResponse(); | ||||
|  | ||||
| @ -29,6 +29,7 @@ import android.util.Log; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.nio.channels.FileChannel; | ||||
| import java.util.Iterator; | ||||
| @ -68,7 +69,11 @@ public class ChunkFromFileRequestBody extends FileRequestBody { | ||||
| 
 | ||||
|     @Override | ||||
|     public long contentLength() { | ||||
|         return mChunkSize; | ||||
|         try { | ||||
|             return Math.min(mChunkSize, mChannel.size() - mChannel.position()); | ||||
|         } catch (IOException e) { | ||||
|             return mChunkSize; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
| @ -83,6 +88,7 @@ public class ChunkFromFileRequestBody extends FileRequestBody { | ||||
|             long maxCount = Math.min(mOffset + mChunkSize, mChannel.size()); | ||||
|             while (mChannel.position() < maxCount) { | ||||
| 
 | ||||
| 
 | ||||
|                 Log_OC.d(TAG, "Sink buffer size: " + sink.buffer().size()); | ||||
| 
 | ||||
|                 readCount = mChannel.read(mBuffer); | ||||
| @ -122,4 +128,8 @@ public class ChunkFromFileRequestBody extends FileRequestBody { | ||||
| //            } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void setOffset(long offset) { | ||||
|         this.mOffset = offset; | ||||
|     } | ||||
| } | ||||
| @ -52,7 +52,6 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R | ||||
| public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation { | ||||
| 
 | ||||
|     private static final int LAST_CHUNK_TIMEOUT = 900000; //15 mins. | ||||
| 
 | ||||
|     public static final long CHUNK_SIZE = 1024000; | ||||
|     private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -66,9 +65,8 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { | ||||
|         int status = -1; | ||||
|         int status; | ||||
|         RemoteOperationResult result = null; | ||||
| 
 | ||||
|         FileChannel channel = null; | ||||
|         RandomAccessFile raf = null; | ||||
| 
 | ||||
| @ -89,7 +87,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|             String uriPrefix = client.getNewUploadsWebDavUri() + FileUtils.PATH_SEPARATOR + String.valueOf(mTransferId); | ||||
|             long totalLength = fileToUpload.length(); | ||||
|             long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE); | ||||
|             String totalLengthStr = String.valueOf(fileToUpload.length()); | ||||
| 
 | ||||
|             for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) { | ||||
|                 mPutMethod = new PutMethod( | ||||
| @ -100,8 +97,8 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|                     mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); | ||||
|                 } | ||||
| 
 | ||||
| //                ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset); | ||||
| //                mPutMethod.setRequestEntity(mEntity); | ||||
|                 ((ChunkFromFileRequestBody) mFileRequestBody).setOffset(offset); | ||||
| 
 | ||||
| //                if (mCancellationRequested.get()) { | ||||
| //                    mPutMethod.abort(); | ||||
| //                    // next method will throw an exception | ||||
| @ -137,8 +134,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|                 channel.close(); | ||||
|             if (raf != null) | ||||
|                 raf.close(); | ||||
| //            if (mPutMethod != null) | ||||
| //                mPutMethod.releaseConnection();    // let the connection available for other methods | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
| @ -115,14 +115,14 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { | ||||
|                     ? new RemoteOperationResult(OK) | ||||
|                     : new RemoteOperationResult(propfindMethod); | ||||
| 
 | ||||
|             Log_OC.d(TAG, "Existence check for " + client.getOldFilesWebdavUri() + | ||||
|             Log_OC.d(TAG, "Existence check for " + client.getNewFilesWebDavUri() + | ||||
|                     WebdavUtils.encodePath(mPath) + " targeting for " + | ||||
|                     (mSuccessIfAbsent ? " absence " : " existence ") + | ||||
|                     "finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : "")); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Existence check for " + client.getOldFilesWebdavUri() + | ||||
|             Log_OC.e(TAG, "Existence check for " + client.getNewFilesWebDavUri() + | ||||
|                     WebdavUtils.encodePath(mPath) + " targeting for " + | ||||
|                     (mSuccessIfAbsent ? " absence " : " existence ") + ": " + | ||||
|                     result.getLogMessage(), result.getException()); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user