1 package eu
.alefzero
.webdav
;
4 import java
.io
.FileInputStream
;
5 import java
.io
.IOException
;
6 import java
.io
.InputStream
;
7 import java
.io
.OutputStream
;
9 import org
.apache
.commons
.httpclient
.methods
.RequestEntity
;
11 import android
.util
.Log
;
13 import eu
.alefzero
.owncloud
.files
.interfaces
.OnDatatransferProgressListener
;
16 * A RequestEntity that represents a File.
19 public class FileRequestEntity
implements RequestEntity
{
22 final String contentType
;
23 OnDatatransferProgressListener listener
;
25 public FileRequestEntity(final File file
, final String contentType
) {
28 throw new IllegalArgumentException("File may not be null");
31 this.contentType
= contentType
;
34 public long getContentLength() {
35 return this.file
.length();
38 public String
getContentType() {
39 return this.contentType
;
42 public boolean isRepeatable() {
46 public void setOnDatatransferProgressListener(OnDatatransferProgressListener listener
) {
47 this.listener
= listener
;
50 public void writeRequest(final OutputStream out
) throws IOException
{
51 byte[] tmp
= new byte[4096];
53 InputStream instream
= new FileInputStream(this.file
);
55 while ((i
= instream
.read(tmp
)) >= 0) {
58 listener
.transferProgress(i
);
60 } catch (IOException io
) {
61 Log
.e("FileRequestException", io
.getMessage());
62 throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io
);