Add simple android client.
[odfkit:webodf.git] / android / src / org / webodf / FileReader.java
1 package org.webodf;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6
7 public class FileReader {
8         private final WebODFView view;
9         private final String path;
10         private final long size;
11
12         public FileReader(WebODFView view, String path) {
13                 this.view = view;
14                 this.path = path;
15                 File f = new File(path);
16                 size = f.length();
17         }
18
19         public String getit() {
20                 return "oh my";
21         }
22
23         public long length() {
24                 return size;
25         }
26
27         public String read(int offset, int length) {
28                 StringBuilder sb = new StringBuilder();
29                 FileInputStream fi;
30                 try {
31                         fi = new FileInputStream(path);
32                         fi.skip(offset);
33                         offset = 0;
34                         int c;
35                         while (offset < length && (c = fi.read()) != -1) {
36                                 sb.append((char) c);
37                                 offset++;
38                         }
39                         fi.close();
40                 } catch (IOException e) {
41                 }
42                 if (offset != length) {
43                         view.log("there is a problem: " + Integer.toString(offset) + " vs "
44                                         + Integer.toString(length));
45                 }
46                 if (sb.length() != length) {
47                         view.log("there is ze problem: " + Integer.toString(sb.length())
48                                         + " vs " + Integer.toString(length));
49                 }
50                 return sb.toString();
51         }
52 }