19 package org.sleuthkit.autopsy.timeline;
 
   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;
 
   35 class PerCaseTimelineProperties {
 
   37     private static final String STALE_KEY = 
"stale"; 
 
   38     private static final String WAS_INGEST_RUNNING_KEY = 
"was_ingest_running"; 
 
   40     private final Path propertiesPath;
 
   42     PerCaseTimelineProperties(Case autopsyCase) {
 
   43         Objects.requireNonNull(autopsyCase, 
"Case must not be null");
 
   44         propertiesPath = Paths.get(autopsyCase.getModuleDirectory(), 
"Timeline", 
"timeline.properties"); 
 
   55     public synchronized boolean isDBStale() throws IOException {
 
   57         String stale = getProperty(STALE_KEY);
 
   58         return StringUtils.isBlank(stale) ? 
true : Boolean.valueOf(stale);
 
   70     public synchronized void setDbStale(Boolean stale) 
throws IOException {
 
   71         setProperty(STALE_KEY, stale.toString());
 
   81     public synchronized boolean wasIngestRunning() throws IOException {
 
   82         String stale = getProperty(WAS_INGEST_RUNNING_KEY);
 
   83         return StringUtils.isBlank(stale) ? 
true : Boolean.valueOf(stale);
 
   94     public synchronized void setIngestRunning(Boolean ingestRunning) 
throws IOException {
 
   95         setProperty(WAS_INGEST_RUNNING_KEY, ingestRunning.toString());
 
  106     private synchronized Path getPropertiesPath() throws IOException {
 
  108         if (!Files.exists(propertiesPath)) {
 
  109             Path parent = propertiesPath.getParent();
 
  110             Files.createDirectories(parent);
 
  111             Files.createFile(propertiesPath);
 
  113         return propertiesPath;
 
  125     private synchronized String getProperty(String propertyKey) 
throws IOException {
 
  126         return getProperties().getProperty(propertyKey);
 
  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);
 
  142         try (OutputStream fos = Files.newOutputStream(propertiesFile)) {
 
  143             props.store(fos, 
""); 
 
  154     private synchronized Properties getProperties() throws IOException {
 
  155         return getProperties(getPropertiesPath());
 
  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);