Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileSetsDefinitions.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.interestingitems;
20 
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.Serializable;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.HashMap;
29 import java.util.Map;
30 import org.openide.util.io.NbObjectInputStream;
31 import org.openide.util.io.NbObjectOutputStream;
33 
37 class FileSetsDefinitions implements Serializable {
38 
39 
40  private static final long serialVersionUID = 1L;
41  //By wrapping the map in this class we avoid warnings for unchecked casting when serializing
42  private final Map<String, FilesSet> filesSets;
43 
44  FileSetsDefinitions(Map<String, FilesSet> filesSets) {
45  this.filesSets = filesSets;
46  }
47 
51  Map<String, FilesSet> getFilesSets() {
52  return filesSets;
53  }
54 
62  static boolean writeDefinitionsFile(String fileName, Map<String, FilesSet> interestingFilesSets) throws FilesSetsManager.FilesSetsManagerException {
63  try (final NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(Paths.get(PlatformUtil.getUserConfigDirectory(), fileName).toString()))) {
64  out.writeObject(new FileSetsDefinitions(interestingFilesSets));
65  } catch (IOException ex) {
66  throw new FilesSetsManager.FilesSetsManagerException(String.format("Failed to write settings to %s", fileName), ex);
67  }
68  return true;
69  }
70 
79  static Map<String, FilesSet> readSerializedDefinitions(String serialFileName) throws FilesSetsManager.FilesSetsManagerException {
80  Path filePath = Paths.get(PlatformUtil.getUserConfigDirectory(), serialFileName);
81  File fileSetFile = filePath.toFile();
82  String filePathStr = filePath.toString();
83  if (fileSetFile.exists()) {
84  try {
85  try (final NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(filePathStr))) {
86  FileSetsDefinitions filesSetsSettings = (FileSetsDefinitions) in.readObject();
87  return filesSetsSettings.getFilesSets();
88  }
89  } catch (IOException | ClassNotFoundException ex) {
90  throw new FilesSetsManager.FilesSetsManagerException(String.format("Failed to read settings from %s", filePathStr), ex);
91  }
92  } else {
93  return new HashMap<>();
94  }
95  }
96 
97 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.