1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.document.impl;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
28 import java.net.URL;
29
30 import org.apache.rat.api.Document;
31
32
33 public class MonolithicFileDocument extends AbstractMonolithicDocument {
34 private final File file;
35
36
37
38
39
40 public static Document newInstance(final URL url) {
41 if ("file".equals(url.getProtocol())) {
42 final File f = new File(url.getFile());
43 return new MonolithicFileDocument(f);
44 }
45 return new AbstractMonolithicDocument(url.toExternalForm()){
46 public Reader reader() throws IOException {
47 return new InputStreamReader(inputStream(), "UTF-8");
48 }
49
50 public InputStream inputStream() throws IOException {
51 return url.openStream();
52 }
53 };
54 }
55
56 public MonolithicFileDocument(final File file) {
57 super(DocumentImplUtils.toName(file));
58 this.file = file;
59 }
60
61 public Reader reader() throws IOException {
62 return new FileReader(file);
63 }
64
65 public InputStream inputStream() throws IOException {
66 return new FileInputStream(file);
67 }
68 }