logger.debug("Reading data from {}...", dataFile);
// Initialize persistent store from file
if (!dataFile.canRead()) {
logger.error("Data file is not readable: {}", dataFile);
throw new SailException("Can't read data file: " + dataFile);
}
// Don't try to read empty files: this will result in an
// IOException, and the file doesn't contain any data anyway.
if (dataFile.length() == 0L) {
logger.warn("Ignoring empty data file: {}", dataFile);
}
else {
try {
FileIO.read(this, dataFile);
logger.debug("Data file read successfully");
}
catch (IOException e) {
logger.error("Failed to read data file", e);
throw new SailException(e);
}
}
}
else {
// file specified that does not exist yet, create it
try {
File dir = dataFile.getParentFile();
if (dir != null && !dir.exists()) {
logger.debug("Creating directory for data file...");
if (!dir.mkdirs()) {
logger.debug("Failed to create directory for data file: {}", dir);
throw new SailException("Failed to create directory for data file: " + dir);
}
}
logger.debug("Initializing data file...");
FileIO.write(this, dataFile);
logger.debug("Data file initialized");
}
catch (IOException e) {
logger.debug("Failed to initialize data file", e);
throw new SailException("Failed to initialize data file " + dataFile, e);
}
catch (SailException e) {
logger.debug("Failed to initialize data file", e);
throw new SailException("Failed to initialize data file " + dataFile, e);
}
}
}
contentsChanged = false;