1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.rat.document.impl;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.InputStreamReader;
26 import java.io.Reader;
27 import java.nio.charset.StandardCharsets;
28 import java.nio.file.Path;
29 import java.util.Collections;
30 import java.util.SortedSet;
31
32 import org.apache.rat.api.Document;
33
34
35
36
37 public class ArchiveEntryDocument extends Document {
38
39
40 private final byte[] contents;
41
42
43 private final Path path;
44
45
46
47
48
49
50 public ArchiveEntryDocument(Path path, byte[] contents) {
51 super(FileDocument.normalizeFileName(path.toFile()));
52 this.path = path;
53 this.contents = contents;
54 }
55
56 @Override
57 public InputStream inputStream() throws IOException {
58 return new ByteArrayInputStream(contents);
59 }
60
61 @Override
62 public boolean isDirectory() {
63 return false;
64 }
65
66 @Override
67 public SortedSet<Document> listChildren() {
68 return Collections.emptySortedSet();
69 }
70
71 @Override
72 public Reader reader() throws IOException {
73 return new InputStreamReader(new ByteArrayInputStream(contents), StandardCharsets.UTF_8);
74 }
75 }