/* ownCloud Android client application
* Copyright (C) 2012 Bartek Przybylski
+ * Copyright (C) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
+ * the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
import java.util.Random;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PutMethod;
+import com.owncloud.android.Log_OC;
import com.owncloud.android.datamodel.OCFile;
import android.accounts.Account;
public class ChunkedUploadFileOperation extends UploadFileOperation {
- private static final long CHUNK_SIZE = 102400;
+ private static final long CHUNK_SIZE = 1024000;
private static final String OC_CHUNKED_HEADER = "OC-Chunked";
private static final String TAG = ChunkedUploadFileOperation.class.getSimpleName();
public ChunkedUploadFileOperation( Account account,
OCFile file,
boolean isInstant,
- boolean forceOverwrite) {
+ boolean forceOverwrite,
+ int localBehaviour) {
- super(account, file, isInstant, forceOverwrite);
+ super(account, file, isInstant, forceOverwrite, localBehaviour);
}
@Override
int status = -1;
FileChannel channel = null;
- FileLock lock = null;
RandomAccessFile raf = null;
try {
File file = new File(getStoragePath());
- raf = new RandomAccessFile(file, "rw");
+ raf = new RandomAccessFile(file, "r");
channel = raf.getChannel();
- lock = channel.tryLock();
ChunkFromFileChannelRequestEntity entity = new ChunkFromFileChannelRequestEntity(channel, getMimeType(), CHUNK_SIZE, file);
entity.addOnDatatransferProgressListeners(getDataTransferListeners());
long offset = 0;
mPutMethod.setRequestEntity(entity);
status = client.executeMethod(mPutMethod);
client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
- Log.d(TAG, "Upload of " + getStoragePath() + " to " + getRemotePath() + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
+ Log_OC.d(TAG, "Upload of " + getStoragePath() + " to " + getRemotePath() + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
if (!isSuccess(status))
break;
}
} finally {
- if (lock != null)
- lock.release();
if (channel != null)
channel.close();
if (raf != null)