From b38171dbd72ced8204f505dba859c410b9a1eaaa Mon Sep 17 00:00:00 2001 From: millmanorama Date: Tue, 13 Dec 2016 00:04:53 +0100 Subject: [PATCH] make the ByteXXXStream classes inner classes of the TextExtractors that use them. --- .../keywordsearch/ArtifactExtractor.java | 69 ++++++++++++ .../keywordsearch/ByteArtifactStream.java | 100 ------------------ .../keywordsearch/ByteContentStream.java | 98 ----------------- .../keywordsearch/FileTextExtractor.java | 74 +++++++++++++ 4 files changed, 143 insertions(+), 198 deletions(-) delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteArtifactStream.java delete mode 100644 KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteContentStream.java diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ArtifactExtractor.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ArtifactExtractor.java index 629c71936f..72b259e1a8 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ArtifactExtractor.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ArtifactExtractor.java @@ -5,6 +5,8 @@ */ package org.sleuthkit.autopsy.keywordsearch; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; @@ -12,8 +14,11 @@ import java.util.HashMap; import org.apache.commons.io.IOUtils; import org.apache.solr.common.util.ContentStream; import org.openide.util.Exceptions; +import org.openide.util.NbBundle; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.ContentUtils; +import static org.sleuthkit.autopsy.keywordsearch.Bundle.ByteArtifactStream_getSrcInfo_text; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -163,4 +168,68 @@ public class ArtifactExtractor extends TextExtractor { return source.getDisplayName(); } + static private class ByteArtifactStream implements ContentStream { + + //input + private final byte[] content; //extracted subcontent + private long contentSize; + private final BlackboardArtifact aContent; //origin + + private final InputStream stream; + + private static final Logger logger = Logger.getLogger(ByteArtifactStream.class.getName()); + + public ByteArtifactStream(byte[] content, long contentSize, BlackboardArtifact aContent) { + this.content = content; + this.aContent = aContent; + stream = new ByteArrayInputStream(content, 0, (int) contentSize); + } + + public byte[] getByteContent() { + return content; + } + + public BlackboardArtifact getSourceContent() { + return aContent; + } + + @Override + public String getContentType() { + return "text/plain;charset=" + Server.DEFAULT_INDEXED_TEXT_CHARSET.name(); //NON-NLS + } + + @Override + public String getName() { + return aContent.getDisplayName(); + } + + @Override + public Reader getReader() throws IOException { + return new InputStreamReader(stream); + + } + + @Override + public Long getSize() { + return contentSize; + } + + @Override + @NbBundle.Messages("ByteArtifactStream.getSrcInfo.text=Artifact:{0}") + public String getSourceInfo() { + return ByteArtifactStream_getSrcInfo_text(aContent.getArtifactID()); + } + + @Override + public InputStream getStream() throws IOException { + return stream; + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + + stream.close(); + } + } } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteArtifactStream.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteArtifactStream.java deleted file mode 100644 index 7e4898d185..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteArtifactStream.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import org.apache.solr.common.util.ContentStream; -import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.coreutils.Logger; -import static org.sleuthkit.autopsy.keywordsearch.Bundle.*; -import org.sleuthkit.datamodel.BlackboardArtifact; - -/** - * Stream of bytes representing string with specified encoding to feed into Solr - * as ContentStream - */ -class ByteArtifactStream implements ContentStream { - - //input - private final byte[] content; //extracted subcontent - private long contentSize; - private final BlackboardArtifact aContent; //origin - - private final InputStream stream; - - private static final Logger logger = Logger.getLogger(ByteContentStream.class.getName()); - - public ByteArtifactStream(byte[] content, long contentSize, BlackboardArtifact aContent) { - this.content = content; - this.aContent = aContent; - stream = new ByteArrayInputStream(content, 0, (int) contentSize); - } - - public byte[] getByteContent() { - return content; - } - - public BlackboardArtifact getSourceContent() { - return aContent; - } - - @Override - public String getContentType() { - return "text/plain;charset=" + Server.DEFAULT_INDEXED_TEXT_CHARSET.name(); //NON-NLS - } - - @Override - public String getName() { - return aContent.getDisplayName(); - } - - @Override - public Reader getReader() throws IOException { - return new InputStreamReader(stream); - - } - - @Override - public Long getSize() { - return contentSize; - } - - @Override - @NbBundle.Messages("ByteArtifactStream.getSrcInfo.text=Artifact:{0}") - public String getSourceInfo() { - return ByteArtifactStream_getSrcInfo_text(aContent.getArtifactID()); - } - - @Override - public InputStream getStream() throws IOException { - return stream; - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - - stream.close(); - } - -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteContentStream.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteContentStream.java deleted file mode 100644 index c39e9b7bb5..0000000000 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/ByteContentStream.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import org.apache.solr.common.util.ContentStream; -import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.datamodel.AbstractContent; - -/** - * Stream of bytes representing string with specified encoding to feed into Solr - * as ContentStream - */ -class ByteContentStream implements ContentStream { - - //input - private final byte[] content; //extracted subcontent - private long contentSize; - private final AbstractContent aContent; //origin - - private final InputStream stream; - - private static final Logger logger = Logger.getLogger(ByteContentStream.class.getName()); - - public ByteContentStream(byte[] content, long contentSize, AbstractContent aContent) { - this.content = content; - this.aContent = aContent; - stream = new ByteArrayInputStream(content, 0, (int) contentSize); - } - - public byte[] getByteContent() { - return content; - } - - public AbstractContent getSourceContent() { - return aContent; - } - - @Override - public String getContentType() { - return "text/plain;charset=" + Server.DEFAULT_INDEXED_TEXT_CHARSET.name(); //NON-NLS - } - - @Override - public String getName() { - return aContent.getName(); - } - - @Override - public Reader getReader() throws IOException { - return new InputStreamReader(stream); - - } - - @Override - public Long getSize() { - return contentSize; - } - - @Override - public String getSourceInfo() { - return NbBundle.getMessage(this.getClass(), "ByteContentStream.getSrcInfo.text", aContent.getId()); - } - - @Override - public InputStream getStream() throws IOException { - return stream; - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - - stream.close(); - } - -} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/FileTextExtractor.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/FileTextExtractor.java index e30ea764ea..eeee49ff74 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/FileTextExtractor.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/FileTextExtractor.java @@ -18,9 +18,17 @@ */ package org.sleuthkit.autopsy.keywordsearch; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.Arrays; import java.util.List; import org.apache.solr.common.util.ContentStream; +import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.AbstractContent; import org.sleuthkit.datamodel.AbstractFile; /** @@ -121,4 +129,70 @@ abstract class FileTextExtractor extends TextExtractor