View Javadoc

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.impl;
21  
22  import java.io.ByteArrayInputStream;
23  import java.io.File;
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.io.InputStreamReader;
27  import java.io.Reader;
28  
29  import org.apache.rat.api.Document;
30  import org.apache.rat.api.MetaData;
31  import org.apache.rat.api.RatException;
32  
33  public class ArchiveEntryDocument implements Document {
34  	
35  	private byte[] contents;
36      private final String name;
37  
38      private final MetaData metaData = new MetaData();
39  
40  	public ArchiveEntryDocument(File file, byte[] contents) throws RatException {
41  		super();
42  		name = DocumentImplUtils.toName(file);
43  		this.contents = contents;
44  	}
45  	
46  	public MetaData getMetaData() {
47  		return metaData;
48  	}
49  
50  	public String getName() {
51  		return name;
52  	}
53  
54  	public InputStream inputStream() throws IOException {
55  		return new ByteArrayInputStream(contents);
56  	}
57  
58  	public boolean isComposite() {
59  		return DocumentImplUtils.isZipStream(new ByteArrayInputStream(contents));
60  	}
61  
62  	public Reader reader() throws IOException {
63  		return new InputStreamReader(new ByteArrayInputStream(contents));
64  	}
65  
66  
67      /**
68       * Representations suitable for logging.
69       * @return a <code>String</code> representation 
70       * of this object.
71       */
72      public String toString()
73      {
74          return "TarEntryDocument ( "
75              + "name = " + this.name + " "
76              + "metaData = " + this.metaData + " "
77              + " )";
78      }
79  }