Clean and document KWS AbstractFileChunk class

This commit is contained in:
Richard Cordovano
2016-10-18 15:31:14 -04:00
parent a237d4e064
commit 6bf235ba17
4 changed files with 55 additions and 31 deletions
@@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2012 Basis Technology Corp.
* Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,47 +19,73 @@
package org.sleuthkit.autopsy.keywordsearch;
import java.nio.charset.Charset;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.keywordsearch.Ingester.IngesterException;
/**
* Represents each string chunk to be indexed, a derivative of TextExtractor
* file
* A representation of a chunk of text from a file that can be used, when
* supplied with an Ingester, to index the chunk for search.
*/
class AbstractFileChunk {
final class AbstractFileChunk {
private int chunkID;
private TextExtractor parent;
private final int chunkNumber;
private final TextExtractor textExtractor;
AbstractFileChunk(TextExtractor parent, int chunkID) {
this.parent = parent;
this.chunkID = chunkID;
}
public TextExtractor getParent() {
return parent;
}
public int getChunkId() {
return chunkID;
/**
* Constructs a representation of a chunk of text from a file that can be
* used, when supplied with an Ingester, to index the chunk for search.
*
* @param textExtractor A TextExtractor for the file.
* @param chunkNumber A sequence number for the chunk.
*/
AbstractFileChunk(TextExtractor textExtractor, int chunkNumber) {
this.textExtractor = textExtractor;
this.chunkNumber = chunkNumber;
}
/**
* return String representation of the absolute id (parent and child)
* Gets the TextExtractor for the source file of the text chunk.
*
* @return
* @return A reference to the TextExtractor.
*/
String getIdString() {
return Server.getChunkIdString(this.parent.getSourceFile().getId(), this.chunkID);
TextExtractor getTextExtractor() {
return textExtractor;
}
void index(Ingester ingester, byte[] content, long contentSize, Charset indexCharset) throws IngesterException {
ByteContentStream bcs = new ByteContentStream(content, contentSize, parent.getSourceFile(), indexCharset);
/**
* Gets the sequence number of the text chunk.
*
* @return The chunk number.
*/
int getChunkNumber() {
return chunkNumber;
}
/**
* Gets the id of the text chunk.
*
* @return An id of the form [source file object id]_[chunk number]
*/
String getChunkId() {
return Server.getChunkIdString(this.textExtractor.getSourceFile().getId(), this.chunkNumber);
}
/**
* Indexes the text chunk.
*
* @param ingester An Ingester to do the indexing.
* @param chunkBytes The raw bytes of the text chunk.
* @param chunkSize The size of the text chunk in bytes.
* @param charSet The char set to use during indexing.
*
* @throws org.sleuthkit.autopsy.keywordsearch.Ingester.IngesterException
*/
void index(Ingester ingester, byte[] chunkBytes, long chunkSize, Charset charSet) throws IngesterException {
ByteContentStream bcs = new ByteContentStream(chunkBytes, chunkSize, textExtractor.getSourceFile(), charSet);
try {
ingester.ingest(this, bcs, content.length);
} catch (Exception ingEx) {
throw new IngesterException(NbBundle.getMessage(this.getClass(), "AbstractFileChunk.index.exception.msg",
parent.getSourceFile().getId(), chunkID), ingEx);
ingester.ingest(this, bcs, chunkBytes.length);
} catch (Exception ex) {
throw new IngesterException(String.format("Error ingesting (indexing) file chunk: %s", getChunkId()), ex);
}
}
}
@@ -157,7 +157,6 @@ DropdownSearchPanel.cutMenuItem.text=Cut
DropdownSearchPanel.selectAllMenuItem.text=Select All
DropdownSearchPanel.pasteMenuItem.text=Paste
DropdownSearchPanel.copyMenuItem.text=Copy
AbstractFileChunk.index.exception.msg=Problem ingesting file string chunk\: {0}, chunk\: {1}
AbstractFileStringContentStream.getSize.exception.msg=Cannot tell how many chars in converted string, until entire string is converted
AbstractFileStringContentStream.getSrcInfo.text=File\:{0}
ByteContentStream.getSrcInfo.text=File\:{0}
@@ -133,7 +133,6 @@ OptionsCategory_Keywords_KeywordSearchOptions=\u30ad\u30fc\u30ef\u30fc\u30c9\u69
ExtractedContentPanel.pageOfLabel.text=of
ExtractedContentPanel.pageCurLabel.text=-
ExtractedContentPanel.pageTotalLabel.text=-
AbstractFileChunk.index.exception.msg=\u30d5\u30a1\u30a4\u30eb\u30b9\u30c8\u30ea\u30f3\u30b0\u30c1\u30e3\u30f3\u30af\u306e\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u4e2d\u306b\u554f\u984c\u304c\u767a\u751f\u3057\u307e\u3057\u305f\uff1a {0}, \u30c1\u30e3\u30f3\u30af\: {1}
AbstractFileStringContentStream.getSize.exception.msg=\u30b9\u30c8\u30ea\u30f3\u30b0\u5168\u4f53\u304c\u5909\u63db\u3055\u308c\u306a\u3051\u308c\u3070\u3001\u5909\u63db\u3055\u308c\u305f\u30b9\u30c8\u30ea\u30f3\u30b0\u5185\u306e\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u6570\u306f\u4e0d\u660e\u3067\u3059\u3002
AbstractFileStringContentStream.getSrcInfo.text=\u30d5\u30a1\u30a4\u30eb\uff1a{0}
ByteContentStream.getSrcInfo.text=\u30d5\u30a1\u30a4\u30eb\uff1a{0}
@@ -134,7 +134,7 @@ class Ingester {
//overwrite id with the chunk id
params.put(Server.Schema.ID.toString(),
Server.getChunkIdString(sourceContent.getId(), fec.getChunkId()));
Server.getChunkIdString(sourceContent.getId(), fec.getChunkNumber()));
ingest(bcs, params, size);
}