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 eu
.alefzero
.webdav
.OnDatatransferProgressListener
;
13 import android
.util
.Log
;
17 * A RequestEntity that represents a File.
20 public class FileRequestEntity
implements RequestEntity
{
23 final String contentType
;
24 OnDatatransferProgressListener listener
;
26 public FileRequestEntity(final File file
, final String contentType
) {
29 throw new IllegalArgumentException("File may not be null");
32 this.contentType
= contentType
;
35 public long getContentLength() {
36 return this.file
.length();
39 public String
getContentType() {
40 return this.contentType
;
43 public boolean isRepeatable() {
47 public void setOnDatatransferProgressListener(OnDatatransferProgressListener listener
) {
48 this.listener
= listener
;
51 public void writeRequest(final OutputStream out
) throws IOException
{
52 byte[] tmp
= new byte[4096];
54 InputStream instream
= new FileInputStream(this.file
);
56 while ((i
= instream
.read(tmp
)) >= 0) {
59 listener
.transferProgress(i
);
61 } catch (IOException io
) {
62 Log
.e("FileRequestException", io
.getMessage());
63 throw new RuntimeException("Ugly solution to workaround the default policy of retries when the server falls while uploading ; temporal fix; really", io
);