Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PerCaseTimelineProperties.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2016-2018 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.timeline;
20 
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.Objects;
28 import java.util.Properties;
29 import org.apache.commons.lang3.StringUtils;
31 
35 class PerCaseTimelineProperties {
36 
37  private static final String STALE_KEY = "stale"; //NON-NLS
38  private static final String WAS_INGEST_RUNNING_KEY = "was_ingest_running"; // NON-NLS
39 
40  private final Path propertiesPath;
41 
42  PerCaseTimelineProperties(Case autopsyCase) {
43  Objects.requireNonNull(autopsyCase, "Case must not be null");
44  propertiesPath = Paths.get(autopsyCase.getModuleDirectory(), "Timeline", "timeline.properties"); //NON-NLS
45  }
46 
55  public synchronized boolean isDBStale() throws IOException {
56 
57  String stale = getProperty(STALE_KEY);
58  return StringUtils.isBlank(stale) ? true : Boolean.valueOf(stale);
59 
60  }
61 
70  public synchronized void setDbStale(Boolean stale) throws IOException {
71  setProperty(STALE_KEY, stale.toString());
72  }
73 
81  public synchronized boolean wasIngestRunning() throws IOException {
82  String stale = getProperty(WAS_INGEST_RUNNING_KEY);
83  return StringUtils.isBlank(stale) ? true : Boolean.valueOf(stale);
84  }
85 
94  public synchronized void setIngestRunning(Boolean ingestRunning) throws IOException {
95  setProperty(WAS_INGEST_RUNNING_KEY, ingestRunning.toString());
96  }
97 
106  private synchronized Path getPropertiesPath() throws IOException {
107 
108  if (!Files.exists(propertiesPath)) {
109  Path parent = propertiesPath.getParent();
110  Files.createDirectories(parent);
111  Files.createFile(propertiesPath);
112  }
113  return propertiesPath;
114  }
115 
125  private synchronized String getProperty(String propertyKey) throws IOException {
126  return getProperties().getProperty(propertyKey);
127  }
128 
137  private synchronized void setProperty(String propertyKey, String propertyValue) throws IOException {
138  Path propertiesFile = getPropertiesPath();
139  Properties props = getProperties(propertiesFile);
140  props.setProperty(propertyKey, propertyValue);
141 
142  try (OutputStream fos = Files.newOutputStream(propertiesFile)) {
143  props.store(fos, ""); //NON-NLS
144  }
145  }
146 
154  private synchronized Properties getProperties() throws IOException {
155  return getProperties(getPropertiesPath());
156  }
157 
168  private synchronized Properties getProperties(final Path propertiesFile) throws IOException {
169  try (InputStream inputStream = Files.newInputStream(propertiesFile)) {
170  Properties props = new Properties();
171  props.load(inputStream);
172  return props;
173  }
174  }
175 }

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