import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
- public void setOnDatatransferProgressListener(OnDatatransferProgressListener listener) {
- this.listener = listener;
+ public void addOnDatatransferProgressListener(OnDatatransferProgressListener listener) {
+ mListeners.add(listener);
+
+ public void addOnDatatransferProgressListeners(Collection<OnDatatransferProgressListener> listeners) {
+ mListeners.addAll(listeners);
+ }
+
+ public void removeOnDatatransferProgressListener(OnDatatransferProgressListener listener) {
+ mListeners.remove(listener);
+ }
+
+
+ @Override
public void writeRequest(final OutputStream out) throws IOException {
//byte[] tmp = new byte[4096];
ByteBuffer tmp = ByteBuffer.allocate(4096);
int i = 0;
public void writeRequest(final OutputStream out) throws IOException {
//byte[] tmp = new byte[4096];
ByteBuffer tmp = ByteBuffer.allocate(4096);
int i = 0;
- FileChannel channel = new RandomAccessFile(this.file, "rw").getChannel();
+ // TODO(bprzybylski): each mem allocation can throw OutOfMemoryError we need to handle it
+ // globally in some fashionable manner
+ RandomAccessFile raf = new RandomAccessFile(mFile, "rw");
+ FileChannel channel = raf.getChannel();
while ((i = channel.read(tmp)) >= 0) {
out.write(tmp.array(), 0, i);
tmp.clear();
while ((i = channel.read(tmp)) >= 0) {
out.write(tmp.array(), 0, i);
tmp.clear();
} catch (IOException io) {
Log.e("FileRequestException", io.getMessage());
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
} finally {
} catch (IOException io) {
Log.e("FileRequestException", io.getMessage());
throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io);
} finally {