Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTSettingsPersistence.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 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 com.basistech.df.cybertriage.autopsy.incidentoptions;
20 
21 import com.fasterxml.jackson.databind.ObjectMapper;
22 import java.io.File;
23 import java.io.IOException;
24 import java.nio.file.Paths;
25 import java.util.logging.Level;
28 
33 public class CTSettingsPersistence {
34 
35  private static final String CT_SETTINGS_DIR = "CyberTriage";
36  private static final String CT_SETTINGS_FILENAME = "CyberTriageSettings.json";
37 
38  private static final Logger logger = Logger.getLogger(CTSettingsPersistence.class.getName());
39 
41 
42  private final ObjectMapper objectMapper = new ObjectMapper();
43 
45  return instance;
46  }
47 
48  public synchronized boolean saveCTSettings(CTSettings ctSettings) {
49  if (ctSettings != null) {
50 
51  File settingsFile = getCTSettingsFile();
52  settingsFile.getParentFile().mkdirs();
53  try {
54  objectMapper.writeValue(settingsFile, ctSettings);
55  return true;
56  } catch (IOException ex) {
57  logger.log(Level.WARNING, "There was an error writing CyberTriage settings to file: " + settingsFile.getAbsolutePath(), ex);
58  }
59  }
60 
61  return false;
62  }
63 
64  public synchronized CTSettings loadCTSettings() {
65 
66  CTSettings settings = null;
67  File settingsFile = getCTSettingsFile();
68  if (settingsFile.isFile()) {
69  try {
70  settings = objectMapper.readValue(settingsFile, CTSettings.class);
71  } catch (IOException ex) {
72  logger.log(Level.WARNING, "There was an error reading CyberTriage settings to file: " + settingsFile.getAbsolutePath(), ex);
73  }
74  }
75 
76  return settings == null
77  ? CTSettings.getDefaultSettings()
78  : settings;
79 
80  }
81 
82  private File getCTSettingsFile() {
84  }
85 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.