Saved isplaying state to avoid autoplay when a video is paused and the device orienta...
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / ChunkedUploadFileOperation.java
index 1f78aa1..5e4b591 100644 (file)
@@ -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, "rw");
+            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)