From 1d82336c81920ab9f9022290e8be1a480b3a19de Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 20 Jan 2017 10:49:17 -0500 Subject: [PATCH] 1903 added class for serializing filesSets other than interesting ones --- .../interestingitems/FilesSetsManager.java | 9 ++-- .../FilesSetsSerializable.java | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsSerializable.java diff --git a/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsManager.java b/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsManager.java index d26198f6bd..93e586f517 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsManager.java @@ -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 filesSetsSettings = (Map)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 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); } } - } diff --git a/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsSerializable.java b/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsSerializable.java new file mode 100644 index 0000000000..35b2a9477d --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/modules/interestingitems/FilesSetsSerializable.java @@ -0,0 +1,45 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2017 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.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 filesSets; + + FilesSetsSerializable(Map filesSets) { + this.filesSets = filesSets; + } + + /** + * @return the filesSets + */ + Map getFilesSets() { + return filesSets; + } + +} \ No newline at end of file