1903 added class for serializing filesSets other than interesting ones

This commit is contained in:
William Schaefer 2017-01-20 10:49:17 -05:00
parent d745830415
commit 1d82336c81
2 changed files with 48 additions and 6 deletions

View File

@ -22,7 +22,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@ -151,9 +150,8 @@ public final class FilesSetsManager extends Observable {
if (fileSetFile.exists()) {
try {
try (final NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(filePathStr))) {
@SuppressWarnings("unchecked")
Map<String, FilesSet> filesSetsSettings = (Map<String, FilesSet>)in.readObject();
return filesSetsSettings;
FilesSetsSerializable filesSetsSettings = (FilesSetsSerializable)in.readObject();
return filesSetsSettings.getFilesSets();
}
} catch (IOException | ClassNotFoundException ex) {
throw new FilesSetsManagerException(String.format("Failed to read settings from %s", filePathStr), ex);
@ -189,7 +187,7 @@ public final class FilesSetsManager extends Observable {
void setCustomFileIngestFilters(Map<String, FilesSet> filesSets) throws FilesSetsManagerException {
synchronized (FILE_INGEST_FILTER_LOCK) {
try (final NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(Paths.get(PlatformUtil.getUserConfigDirectory(), FILE_INGEST_FILTER_DEFS_NAME).toString()))) {
out.writeObject(filesSets);
out.writeObject(new FilesSetsSerializable(filesSets));
} catch (IOException ex) {
throw new FilesSetsManagerException(String.format("Failed to write settings to %s", FILE_INGEST_FILTER_DEFS_NAME), ex);
}
@ -214,5 +212,4 @@ public final class FilesSetsManager extends Observable {
super(cause);
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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.modules.interestingitems;
import java.io.Serializable;
import java.util.Map;
/**
* Class for wrapping a map which stores FilesSets as values with a String key.
*/
class FilesSetsSerializable implements Serializable {
private static final long serialVersionUID = 1L;
//By wrapping the map in this class we avoid warnings for unchecked casting when serializing
private final Map<String, FilesSet> filesSets;
FilesSetsSerializable(Map<String, FilesSet> filesSets) {
this.filesSets = filesSets;
}
/**
* @return the filesSets
*/
Map<String, FilesSet> getFilesSets() {
return filesSets;
}
}