Autopsy  4.0
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;
31 import org.sleuthkit.datamodel.AbstractContent;
32 
37 class ByteContentStream implements ContentStream {
38 
39  //input
40  private byte[] content; //extracted subcontent
41  private long contentSize;
42  private AbstractContent aContent; //origin
43  private Charset charset; //output byte stream charset of encoded strings
44 
45  private InputStream stream;
46 
47  private static Logger logger = Logger.getLogger(ByteContentStream.class.getName());
48 
49  public ByteContentStream(byte[] content, long contentSize, AbstractContent aContent, Charset charset) {
50  this.content = content;
51  this.aContent = aContent;
52  this.charset = charset;
53  stream = new ByteArrayInputStream(content, 0, (int) contentSize);
54  }
55 
56  public byte[] getByteContent() {
57  return content;
58  }
59 
60  public AbstractContent getSourceContent() {
61  return aContent;
62  }
63 
64  @Override
65  public String getContentType() {
66  return "text/plain;charset=" + charset.name(); //NON-NLS
67  }
68 
69  @Override
70  public String getName() {
71  return aContent.getName();
72  }
73 
74  @Override
75  public Reader getReader() throws IOException {
76  return new InputStreamReader(stream);
77 
78  }
79 
80  @Override
81  public Long getSize() {
82  return contentSize;
83  }
84 
85  @Override
86  public String getSourceInfo() {
87  return NbBundle.getMessage(this.getClass(), "ByteContentStream.getSrcInfo.text", aContent.getId());
88  }
89 
90  @Override
91  public InputStream getStream() throws IOException {
92  return stream;
93  }
94 
95  @Override
96  protected void finalize() throws Throwable {
97  super.finalize();
98 
99  stream.close();
100  }
101 
102 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.