Autopsy  4.1
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 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 Case autoCase;
41  private final Path propertiesPath;
42 
43  PerCaseTimelineProperties(Case c) {
44  Objects.requireNonNull(c, "Case must not be null");
45  this.autoCase = c;
46  propertiesPath = Paths.get(autoCase.getModuleDirectory(), "Timeline", "timeline.properties"); //NON-NLS
47  }
48 
57  public synchronized boolean isDBStale() throws IOException {
58 
59  String stale = getProperty(STALE_KEY);
60  return StringUtils.isBlank(stale) ? true : Boolean.valueOf(stale);
61 
62  }
63 
72  public synchronized void setDbStale(Boolean stale) throws IOException {
73  setProperty(STALE_KEY, stale.toString());
74  }
75 
83  public synchronized boolean wasIngestRunning() throws IOException {
84  String stale = getProperty(WAS_INGEST_RUNNING_KEY);
85  return StringUtils.isBlank(stale) ? true : Boolean.valueOf(stale);
86  }
87 
96  public synchronized void setIngestRunning(Boolean ingestRunning) throws IOException {
97  setProperty(WAS_INGEST_RUNNING_KEY, ingestRunning.toString());
98  }
99 
108  private synchronized Path getPropertiesPath() throws IOException {
109 
110  if (!Files.exists(propertiesPath)) {
111  Path parent = propertiesPath.getParent();
112  Files.createDirectories(parent);
113  Files.createFile(propertiesPath);
114  }
115  return propertiesPath;
116  }
117 
127  private synchronized String getProperty(String propertyKey) throws IOException {
128  return getProperties().getProperty(propertyKey);
129  }
130 
139  private synchronized void setProperty(String propertyKey, String propertyValue) throws IOException {
140  Path propertiesFile = getPropertiesPath();
141  Properties props = getProperties(propertiesFile);
142  props.setProperty(propertyKey, propertyValue);
143 
144  try (OutputStream fos = Files.newOutputStream(propertiesFile)) {
145  props.store(fos, ""); //NON-NLS
146  }
147  }
148 
156  private synchronized Properties getProperties() throws IOException {
157  return getProperties(getPropertiesPath());
158  }
159 
170  private synchronized Properties getProperties(final Path propertiesFile) throws IOException {
171  try (InputStream inputStream = Files.newInputStream(propertiesFile)) {
172  Properties props = new Properties();
173  props.load(inputStream);
174  return props;
175  }
176  }
177 }

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