From 182b2d240aa97f04fee6a4e8f76ee2665076acba Mon Sep 17 00:00:00 2001 From: Oliver Spohngellert Date: Thu, 10 Mar 2016 15:34:17 -0500 Subject: [PATCH] Moved towards making serialization follow new protocol --- .../modules/hashdatabase/HashDbManager.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 5d16a6c5e4..6cd58e014b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -136,6 +136,10 @@ public class HashDbManager implements PropertyChangeListener { private HashDbManagerException(String message) { super(message); } + + private HashDbManagerException(String message, Throwable exception) { + super(message, exception); + } } /** @@ -512,18 +516,14 @@ public class HashDbManager implements PropertyChangeListener { hashDatabases.clear(); } - private boolean writeHashSetConfigurationToDisk() { + private boolean writeHashSetConfigurationToDisk() throws HashDbManagerException { try (NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(DB_SERIALIZATION_FILE_PATH))) { HashDbSerializationSettings settings = new HashDbSerializationSettings(this.knownHashSets, this.knownBadHashSets); out.writeObject(settings); - File xmlFile = new File(configFilePath); - if (xmlFile.exists()) { - xmlFile.delete(); - } return true; } catch (IOException | TskCoreException ex) { - throw new PersistenceException(String.format("Failed to write settings to %s", DB_SERIALIZATION_FILE_PATH), ex); + throw new HashDbManagerException(String.format("Failed to write settings to %s", DB_SERIALIZATION_FILE_PATH), ex); } } @@ -560,8 +560,19 @@ public class HashDbManager implements PropertyChangeListener { return f.exists() && f.canRead() && f.canWrite(); } - private boolean readHashSetsConfigurationFromDisk() { - if (hashSetsConfigurationFileExists()) { + private boolean readHashSetsConfigurationFromDisk() throws HashDbManagerException { + File fileSetFile = new File(DB_SERIALIZATION_FILE_PATH); + if (fileSetFile.exists()) { + try { + try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(DB_SERIALIZATION_FILE_PATH))) { + HashDbSerializationSettings filesSetsSettings = (HashDbSerializationSettings) in.readObject(); + this.setFields(filesSetsSettings); + return true; + } + } catch (IOException | ClassNotFoundException ex) { + throw new PersistenceException(String.format("Failed to read settings from %s", DB_SERIALIZATION_FILE_PATH), ex); + } + } else if (hashSetsConfigurationFileExists()) { boolean updatedSchema = false; // Open the XML document that implements the configuration file. @@ -702,26 +713,13 @@ public class HashDbManager implements PropertyChangeListener { return true; } else { - File fileSetFile = new File(DB_SERIALIZATION_FILE_PATH); - if (fileSetFile.exists()) { - try { - try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(DB_SERIALIZATION_FILE_PATH))) { - HashDbSerializationSettings filesSetsSettings = (HashDbSerializationSettings) in.readObject(); - this.setFields(filesSetsSettings); - return true; - } - } catch (IOException | ClassNotFoundException ex) { - throw new PersistenceException(String.format("Failed to read settings from %s", DB_SERIALIZATION_FILE_PATH), ex); - } - } else { - try { - this.setFields(new HashDbSerializationSettings(new ArrayList<>(), new ArrayList<>())); - } catch (TskCoreException ex) { - throw new PersistenceException("Failed to create hash database settings", ex); - } - - return true; + try { + this.setFields(new HashDbSerializationSettings(new ArrayList<>(), new ArrayList<>())); + } catch (TskCoreException ex) { + throw new PersistenceException("Failed to create hash database settings", ex); } + + return true; } }