Autopsy 4.22.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 */
19package org.sleuthkit.autopsy.modules.interestingitems;
20
21import java.io.File;
22import java.io.FileInputStream;
23import java.io.FileOutputStream;
24import java.io.IOException;
25import java.io.Serializable;
26import java.nio.file.Path;
27import java.nio.file.Paths;
28import java.util.HashMap;
29import java.util.Map;
30import org.openide.util.io.NbObjectInputStream;
31import org.openide.util.io.NbObjectOutputStream;
32import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager.FilesSetsManagerException;
33
37class FileSetsDefinitions implements Serializable {
38
39 private static final long serialVersionUID = 1L;
40 //By wrapping the map in this class we avoid warnings for unchecked casting when serializing
41 private final Map<String, FilesSet> filesSets;
42
43 FileSetsDefinitions(Map<String, FilesSet> filesSets) {
44 this.filesSets = filesSets;
45 }
46
50 Map<String, FilesSet> getFilesSets() {
51 return filesSets;
52 }
53
62 static boolean writeDefinitionsFile(String basePath, String fileName, Map<String, FilesSet> interestingFilesSets) throws FilesSetsManager.FilesSetsManagerException {
63 File outputPath = Paths.get(basePath, fileName).toFile();
64 outputPath.getParentFile().mkdirs();
65 try (final NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(outputPath))) {
66 out.writeObject(new FileSetsDefinitions(interestingFilesSets));
67 } catch (IOException ex) {
68 throw new FilesSetsManager.FilesSetsManagerException(String.format("Failed to write settings to %s", fileName), ex);
69 }
70 return true;
71 }
72
84 static Map<String, FilesSet> readSerializedDefinitions(String basePath, String serialFileName) throws FilesSetsManager.FilesSetsManagerException {
85 Path filePath = Paths.get(basePath, serialFileName);
86 File fileSetFile = filePath.toFile();
87 String filePathStr = filePath.toString();
88 if (fileSetFile.exists()) {
89 try {
90 try (final NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(filePathStr))) {
91 FileSetsDefinitions filesSetsSettings = (FileSetsDefinitions) in.readObject();
92 return filesSetsSettings.getFilesSets();
93 }
94 } catch (IOException | ClassNotFoundException ex) {
95 throw new FilesSetsManager.FilesSetsManagerException(String.format("Failed to read settings from %s", filePathStr), ex);
96 }
97 } else {
98 return new HashMap<>();
99 }
100 }
101
102}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.