projects
/
pub
/
Android
/
ownCloud.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
remove all warning from project
[pub/Android/ownCloud.git]
/
src
/
eu
/
alefzero
/
webdav
/
FileRequestEntity.java
diff --git
a/src/eu/alefzero/webdav/FileRequestEntity.java
b/src/eu/alefzero/webdav/FileRequestEntity.java
index
8ebdcbe
..
df6bdff
100644
(file)
--- a/
src/eu/alefzero/webdav/FileRequestEntity.java
+++ b/
src/eu/alefzero/webdav/FileRequestEntity.java
@@
-21,41
+21,48
@@
import android.util.Log;
*/
public class FileRequestEntity implements RequestEntity {
*/
public class FileRequestEntity implements RequestEntity {
- final File
f
ile;
- final String
c
ontentType;
- OnDatatransferProgressListener
l
istener;
+ final File
mF
ile;
+ final String
mC
ontentType;
+ OnDatatransferProgressListener
mL
istener;
public FileRequestEntity(final File file, final String contentType) {
super();
public FileRequestEntity(final File file, final String contentType) {
super();
+ this.mFile = file;
+ this.mContentType = contentType;
if (file == null) {
throw new IllegalArgumentException("File may not be null");
}
if (file == null) {
throw new IllegalArgumentException("File may not be null");
}
- this.file = file;
- this.contentType = contentType;
}
}
+ @Override
public long getContentLength() {
public long getContentLength() {
- return
this.f
ile.length();
+ return
mF
ile.length();
}
}
+ @Override
public String getContentType() {
public String getContentType() {
- return
this.c
ontentType;
+ return
mC
ontentType;
}
}
+ @Override
public boolean isRepeatable() {
return true;
}
public void setOnDatatransferProgressListener(OnDatatransferProgressListener listener) {
public boolean isRepeatable() {
return true;
}
public void setOnDatatransferProgressListener(OnDatatransferProgressListener listener) {
-
this.l
istener = listener;
+
mL
istener = 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();
FileLock lock = channel.tryLock();
//InputStream instream = new FileInputStream(this.file);
FileLock lock = channel.tryLock();
//InputStream instream = new FileInputStream(this.file);
@@
-64,8
+71,8
@@
public class FileRequestEntity implements RequestEntity {
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();
- if (
l
istener != null)
-
l
istener.transferProgress(i);
+ if (
mL
istener != null)
+
mL
istener.transferProgress(i);
}
} catch (IOException io) {
Log.e("FileRequestException", io.getMessage());
}
} catch (IOException io) {
Log.e("FileRequestException", io.getMessage());
@@
-75,6
+82,7
@@
public class FileRequestEntity implements RequestEntity {
//instream.close();
lock.release();
channel.close();
//instream.close();
lock.release();
channel.close();
+ raf.close();
}
}
}
}