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