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
;
12 * A RequestEntity that represents a File.
15 public class FileRequestEntity
implements RequestEntity
{
18 final String contentType
;
19 OnUploadProgressListener listener
;
21 public FileRequestEntity(final File file
, final String contentType
) {
24 throw new IllegalArgumentException("File may not be null");
27 this.contentType
= contentType
;
30 public long getContentLength() {
31 return this.file
.length();
34 public String
getContentType() {
35 return this.contentType
;
38 public boolean isRepeatable() {
42 public void setOnUploadProgressListener(OnUploadProgressListener listener
) {
43 this.listener
= listener
;
46 public void writeRequest(final OutputStream out
) throws IOException
{
47 byte[] tmp
= new byte[4096];
49 InputStream instream
= new FileInputStream(this.file
);
51 while ((i
= instream
.read(tmp
)) >= 0) {
54 listener
.OnUploadProgress(i
);