19 package org.sleuthkit.autopsy.casemodule.multiusercases;
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23 import java.io.DataInputStream;
24 import java.io.DataOutputStream;
26 import java.io.IOException;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.text.ParseException;
30 import java.util.Date;
31 import java.util.logging.Level;
91 throw new CaseNodeDataException(String.format(
"Error creating case node data for coordination service node with path %s", metadata.getCaseDirectory().toUpperCase()), ex);
113 if (nodeBytes != null && nodeBytes.length > 0) {
116 }
catch (IOException ex) {
120 logger.log(Level.WARNING, String.format(
"Error reading node data for coordination service node with path %s, will attempt to replace it", nodePath.toUpperCase()), ex);
123 logger.log(Level.INFO, String.format(
"Replaced corrupt node data for coordination service node with path %s", nodePath.toUpperCase()));
131 logger.log(Level.INFO, String.format(
"Missing node data for coordination service node with path %s, will attempt to create it", nodePath.toUpperCase()));
134 logger.log(Level.INFO, String.format(
"Created node data for coordination service node with path %s", nodePath.toUpperCase()));
142 throw new CaseNodeDataException(String.format(
"Error reading/writing node data coordination service node with path %s", nodePath.toUpperCase()), ex);
163 throw new CaseNodeDataException(String.format(
"Error writing node data coordination service node with path %s", nodeData.getDirectory().toString().toUpperCase()), ex);
182 switch (oldNodeData.getVersion()) {
202 oldNodeData.setMinorVersion(MINOR_VERSION);
203 nodeData = oldNodeData;
206 nodeData = oldNodeData;
226 final Path caseDirectoryPath = Paths.get(nodePath);
227 final File caseDirectory = caseDirectoryPath.toFile();
228 if (!caseDirectory.exists()) {
229 throw new CaseNodeDataException(
"Case directory does not exist");
232 if (metadataFilePath == null) {
233 throw new CaseNodeDataException(
"Case meta data file does not exist");
249 this.errorsOccurred =
false;
250 this.directory = Paths.get(metadata.getCaseDirectory());
252 this.lastAccessDate =
new Date();
253 this.name = metadata.getCaseName();
254 this.displayName = metadata.getCaseDisplayName();
255 this.deletedItemFlags = 0;
268 if (nodeData == null || nodeData.length == 0) {
269 throw new IOException(null == nodeData ?
"Null node data byte array" :
"Zero-length node data byte array");
271 try (ByteArrayInputStream byteStream =
new ByteArrayInputStream(nodeData); DataInputStream inputStream =
new DataInputStream(byteStream)) {
272 this.version = inputStream.readInt();
273 if (this.version == 1) {
274 this.errorsOccurred = inputStream.readBoolean();
276 byte errorsOccurredByte = inputStream.readByte();
277 this.errorsOccurred = (errorsOccurredByte < 0);
279 if (this.version > 0) {
280 this.directory = Paths.get(inputStream.readUTF());
281 this.createDate =
new Date(inputStream.readLong());
282 this.lastAccessDate =
new Date(inputStream.readLong());
283 this.name = inputStream.readUTF();
284 this.displayName = inputStream.readUTF();
285 this.deletedItemFlags = inputStream.readShort();
287 if (this.version > 1) {
288 this.minorVersion = inputStream.readInt();
346 return new Date(this.createDate.getTime());
355 return new Date(this.lastAccessDate.getTime());
364 this.lastAccessDate =
new Date(lastAccessDate.getTime());
411 this.deletedItemFlags |= flag.
getValue();
424 try (ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(); DataOutputStream outputStream =
new DataOutputStream(byteStream)) {
425 outputStream.writeInt(this.version);
426 outputStream.writeByte((byte) (this.errorsOccurred ? 0x80 : 0));
427 outputStream.writeUTF(this.directory.toString());
428 outputStream.writeLong(this.createDate.getTime());
429 outputStream.writeLong(this.lastAccessDate.getTime());
430 outputStream.writeUTF(this.name);
431 outputStream.writeUTF(this.displayName);
432 outputStream.writeShort(this.deletedItemFlags);
433 outputStream.writeInt(this.minorVersion);
434 outputStream.flush();
436 return byteStream.toByteArray();
459 this.value = (short) value;
477 public static final class CaseNodeDataException
extends Exception {
499 super(message, cause);
static CaseNodeData createCaseNodeData(final CaseMetadata metadata)
void setMinorVersion(int minorVersion)
static final int MAJOR_VERSION
void setDeletedFlag(DeletedFlags flag)
boolean isDeletedFlagSet(DeletedFlags flag)
boolean getErrorsOccurred()
void setDisplayName(String displayName)
CaseNodeDataException(String message)
static CaseNodeData readCaseNodeData(String nodePath)
static CaseMetadata getCaseMetadata(String nodePath)
static final Logger logger
byte[] getNodeData(CategoryNode category, String nodePath)
static void writeCaseNodeData(CaseNodeData nodeData)
static CaseNodeData upgradeCaseNodeData(String nodePath, CaseNodeData oldNodeData)
CaseNodeData(byte[] nodeData)
static final int MINOR_VERSION
static final long serialVersionUID
CaseNodeDataException(String message, Throwable cause)
void setLastAccessDate(Date lastAccessDate)
void setNodeData(CategoryNode category, String nodePath, byte[] data)
void setErrorsOccurred(boolean errorsOccurred)
CaseNodeData(CaseMetadata metadata)
synchronized static Logger getLogger(String name)
static synchronized CoordinationService getInstance()