Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ByteContentStream.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.io.ByteArrayInputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.InputStreamReader;
25 import java.io.Reader;
26 import java.nio.charset.Charset;
27 
28 import org.openide.util.NbBundle;
30 import org.apache.solr.common.util.ContentStream;
32 
37 class ByteContentStream implements ContentStream {
38 
39 
40  //input
41  private byte[] content; //extracted subcontent
42  private long contentSize;
43  private AbstractContent aContent; //origin
44  private Charset charset; //output byte stream charset of encoded strings
45 
46  private InputStream stream;
47 
48  private static Logger logger = Logger.getLogger(ByteContentStream.class.getName());
49 
50  public ByteContentStream(byte [] content, long contentSize, AbstractContent aContent, Charset charset) {
51  this.content = content;
52  this.aContent = aContent;
53  this.charset = charset;
54  stream = new ByteArrayInputStream(content, 0, (int)contentSize);
55  }
56 
57  public byte[] getByteContent() {
58  return content;
59  }
60 
61  public AbstractContent getSourceContent() {
62  return aContent;
63  }
64 
65 
66  @Override
67  public String getContentType() {
68  return "text/plain;charset=" + charset.name(); //NON-NLS
69  }
70 
71  @Override
72  public String getName() {
73  return aContent.getName();
74  }
75 
76  @Override
77  public Reader getReader() throws IOException {
78  return new InputStreamReader(stream);
79 
80  }
81 
82  @Override
83  public Long getSize() {
84  return contentSize;
85  }
86 
87  @Override
88  public String getSourceInfo() {
89  return NbBundle.getMessage(this.getClass(), "ByteContentStream.getSrcInfo.text", aContent.getId());
90  }
91 
92  @Override
93  public InputStream getStream() throws IOException {
94  return stream;
95  }
96 
97  @Override
98  protected void finalize() throws Throwable {
99  super.finalize();
100 
101  stream.close();
102  }
103 
104 
105 
106 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.