X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/8638936ce70e28f64f4ffd2fddff8595d4814bf1..c75e5aa71cf93e677e5abb95cb3d9c1f45a64ea7:/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java diff --git a/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java b/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java index 8d3912d9..103cd04a 100644 --- a/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java +++ b/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java @@ -2,9 +2,8 @@ * 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 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -30,12 +29,11 @@ import java.util.Set; import org.apache.commons.httpclient.methods.RequestEntity; +import com.owncloud.android.Log_OC; import com.owncloud.android.network.ProgressiveDataTransferer; import eu.alefzero.webdav.OnDatatransferProgressListener; -import android.util.Log; - /** * A RequestEntity that represents a PIECE of a file. @@ -122,11 +120,14 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres mChannel.position(mOffset); long size = mFile.length(); if (size == 0) size = -1; - while (mChannel.position() < mOffset + mChunkSize && mChannel.position() < mChannel.size()) { + long maxCount = Math.min(mOffset + mChunkSize, mChannel.size()); + while (mChannel.position() < maxCount) { readCount = mChannel.read(mBuffer); out.write(mBuffer.array(), 0, readCount); mBuffer.clear(); - mTransferred += readCount; + if (mTransferred < maxCount) { // condition to avoid accumulate progress for repeated chunks + mTransferred += readCount; + } synchronized (mDataTransferListeners) { it = mDataTransferListeners.iterator(); while (it.hasNext()) { @@ -136,7 +137,7 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres } } catch (IOException io) { - Log.e(TAG, io.getMessage()); + Log_OC.e(TAG, io.getMessage()); throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io); }