X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/6c32365704be635c38e0a338b727643fa76120f5..2c2efa286d4cb06f1a89205ecefa47c69bad15b8:/src/com/owncloud/android/operations/ChunkedUploadFileOperation.java diff --git a/src/com/owncloud/android/operations/ChunkedUploadFileOperation.java b/src/com/owncloud/android/operations/ChunkedUploadFileOperation.java index d38df47f..5e4b5913 100644 --- a/src/com/owncloud/android/operations/ChunkedUploadFileOperation.java +++ b/src/com/owncloud/android/operations/ChunkedUploadFileOperation.java @@ -22,13 +22,13 @@ import java.io.File; 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.datamodel.OCFile; +import com.owncloud.android.network.ProgressiveDataTransferer; import android.accounts.Account; import android.util.Log; @@ -46,9 +46,10 @@ public class ChunkedUploadFileOperation extends UploadFileOperation { 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 @@ -56,23 +57,21 @@ public class ChunkedUploadFileOperation extends UploadFileOperation { int status = -1; FileChannel channel = null; - FileLock lock = null; RandomAccessFile raf = null; try { File file = new File(getStoragePath()); raf = new RandomAccessFile(file, "r"); channel = raf.getChannel(); - //lock = channel.tryLock(); - ChunkFromFileChannelRequestEntity entity = new ChunkFromFileChannelRequestEntity(channel, getMimeType(), CHUNK_SIZE, file); - entity.addOnDatatransferProgressListeners(getDataTransferListeners()); + mEntity = new ChunkFromFileChannelRequestEntity(channel, getMimeType(), CHUNK_SIZE, file); + ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(getDataTransferListeners()); long offset = 0; String uriPrefix = client.getBaseUri() + WebdavUtils.encodePath(getRemotePath()) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ; long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE); for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) { mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER); - entity.setOffset(offset); - mPutMethod.setRequestEntity(entity); + ((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset); + mPutMethod.setRequestEntity(mEntity); 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); @@ -81,8 +80,6 @@ public class ChunkedUploadFileOperation extends UploadFileOperation { } } finally { - if (lock != null) - lock.release(); if (channel != null) channel.close(); if (raf != null)