adjusting design to holo, stability for account setup
[pub/Android/ownCloud.git] / src / eu / alefzero / webdav / FileRequestEntity.java
1 package eu.alefzero.webdav;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8
9 import org.apache.commons.httpclient.methods.RequestEntity;
10
11 /**
12 * A RequestEntity that represents a File.
13 *
14 */
15 public class FileRequestEntity implements RequestEntity {
16
17 final File file;
18 final String contentType;
19
20 public FileRequestEntity(final File file, final String contentType) {
21 super();
22 if (file == null) {
23 throw new IllegalArgumentException("File may not be null");
24 }
25 this.file = file;
26 this.contentType = contentType;
27 }
28 public long getContentLength() {
29 return this.file.length();
30 }
31
32 public String getContentType() {
33 return this.contentType;
34 }
35
36 public boolean isRepeatable() {
37 return true;
38 }
39
40 public void writeRequest(final OutputStream out) throws IOException {
41 byte[] tmp = new byte[4096];
42 int i = 0;
43 InputStream instream = new FileInputStream(this.file);
44 try {
45 while ((i = instream.read(tmp)) >= 0) {
46 out.write(tmp, 0, i);
47 }
48 } finally {
49 instream.close();
50 }
51 }
52
53 }