1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 */
19
20 package org.apache.rat.document;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.InputStream;
24 import java.util.Collections;
25 import java.util.SortedSet;
26
27 import org.apache.rat.api.Document;
28
29 /**
30 * A Document that wraps an Archive entry.
31 */
32 public class ArchiveEntryDocument extends Document {
33
34 /** The contents of the entry */
35 private final byte[] contents;
36
37 /**
38 * Creates an Archive entry.
39 * @param entryName the name of this entry from outside the archive.
40 * @param contents the contents of the entry.
41 * @param nameMatcher the name matcher to filter contents with.
42 */
43 public ArchiveEntryDocument(final ArchiveEntryName entryName, final byte[] contents, final DocumentNameMatcher nameMatcher) {
44 super(entryName, nameMatcher);
45 this.contents = contents;
46 }
47
48 @Override
49 public InputStream inputStream() {
50 return new ByteArrayInputStream(contents);
51 }
52
53 @Override
54 public boolean isDirectory() {
55 return false;
56 }
57
58 @Override
59 public SortedSet<Document> listChildren() {
60 return Collections.emptySortedSet();
61 }
62 }