X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/8e36e7cc3e6218ccb80ee2af3eb0a19df24e339f..52bd01bcedf1b8f13c49b67ee40a848bae1a9d40:/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java?ds=inline diff --git a/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java b/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java index 13c11042..3f453968 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 @@ -31,18 +30,17 @@ 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. * * @author David A. Velasco */ -public class ChunkFromFileChannelRequestEntity implements RequestEntity { +public class ChunkFromFileChannelRequestEntity implements RequestEntity, ProgressiveDataTransferer { private static final String TAG = ChunkFromFileChannelRequestEntity.class.getSimpleName(); @@ -92,16 +90,25 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity { return true; } - public void addOnDatatransferProgressListener(OnDatatransferProgressListener listener) { - mDataTransferListeners.add(listener); + @Override + public void addDatatransferProgressListener(OnDatatransferProgressListener listener) { + synchronized (mDataTransferListeners) { + mDataTransferListeners.add(listener); + } } - public void addOnDatatransferProgressListeners(Collection listeners) { - mDataTransferListeners.addAll(listeners); + @Override + public void addDatatransferProgressListeners(Collection listeners) { + synchronized (mDataTransferListeners) { + mDataTransferListeners.addAll(listeners); + } } - public void removeOnDatatransferProgressListener(OnDatatransferProgressListener listener) { - mDataTransferListeners.remove(listener); + @Override + public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { + synchronized (mDataTransferListeners) { + mDataTransferListeners.remove(listener); + } } @@ -118,9 +125,11 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity { out.write(mBuffer.array(), 0, readCount); mBuffer.clear(); mTransferred += readCount; - it = mDataTransferListeners.iterator(); - while (it.hasNext()) { - it.next().onTransferProgress(readCount, mTransferred, size, mFile.getName()); + synchronized (mDataTransferListeners) { + it = mDataTransferListeners.iterator(); + while (it.hasNext()) { + it.next().onTransferProgress(readCount, mTransferred, size, mFile.getName()); + } } }