1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.testhelpers;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.InputStreamReader;
24 import java.io.Reader;
25 import java.util.Collections;
26 import java.util.SortedSet;
27
28 import org.apache.commons.io.function.IOSupplier;
29 import org.apache.rat.api.Document;
30 import org.apache.rat.document.DocumentNameMatcher;
31 import org.apache.rat.document.DocumentName;
32 import org.apache.rat.document.FSInfoTest;
33
34 public class TestingDocument extends Document {
35
36 private final Reader reader;
37 private final IOSupplier<InputStream> input;
38
39 public TestingDocument() {
40 this("name");
41 }
42
43 public TestingDocument(String name) {
44 this(name, null);
45 }
46
47 public TestingDocument(DocumentName documentName) {
48 super(documentName, DocumentNameMatcher.MATCHES_ALL);
49 this.reader = null;
50 this.input = null;
51 }
52
53 public TestingDocument(String name, DocumentNameMatcher matcher) {
54 super(DocumentName.builder().setName(name).setBaseName("").build(), matcher);
55 this.reader = null;
56 this.input = null;
57 }
58
59 public TestingDocument(Reader reader, String name) {
60 super(DocumentName.builder().setName(name).setBaseName("").build(), DocumentNameMatcher.MATCHES_ALL);
61 this.reader = reader;
62 this.input = null;
63 }
64
65 public TestingDocument(IOSupplier<InputStream> inputStream, String name) {
66 super(DocumentName.builder(FSInfoTest.UNIX).setName(name).setBaseName("").build(), DocumentNameMatcher.MATCHES_ALL);
67 this.input = inputStream;
68 this.reader = null;
69 }
70
71 @Override
72 public Reader reader() throws IOException {
73 return reader == null ? new InputStreamReader(input.get()) : reader;
74 }
75
76 @Override
77 public boolean isDirectory() {
78 return false;
79 }
80
81 @Override
82 public SortedSet<Document> listChildren() {
83 return Collections.emptySortedSet();
84 }
85
86 @Override
87 public InputStream inputStream() throws IOException {
88 if (input != null) {
89 return input.get();
90 }
91 throw new UnsupportedOperationException();
92 }
93 }