19package org.sleuthkit.autopsy.casemodule.multiusercases;
21import java.io.ByteArrayInputStream;
22import java.io.ByteArrayOutputStream;
23import java.io.DataInputStream;
24import java.io.DataOutputStream;
26import java.io.IOException;
27import java.nio.file.Path;
28import java.nio.file.Paths;
29import java.text.ParseException;
31import java.util.logging.Level;
32import org.sleuthkit.autopsy.casemodule.CaseMetadata;
33import org.sleuthkit.autopsy.casemodule.CaseMetadata.CaseMetadataException;
34import org.sleuthkit.autopsy.coordinationservice.CoordinationService;
35import org.sleuthkit.autopsy.coordinationservice.CoordinationService.CoordinationServiceException;
36import org.sleuthkit.autopsy.coreutils.Logger;
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()) {
203 nodeData = oldNodeData;
206 nodeData = oldNodeData;
226 final Path caseDirectoryPath = Paths.get(nodePath);
227 final File caseDirectory = caseDirectoryPath.toFile();
228 if (!caseDirectory.exists()) {
232 if (metadataFilePath ==
null) {
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();
318 return this.errorsOccurred;
337 return this.directory;
346 return new Date(this.createDate.getTime());
355 return new Date(this.lastAccessDate.getTime());
382 return this.displayName;
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;
499 super(message, cause);
CaseNodeDataException(String message)
static final long serialVersionUID
CaseNodeDataException(String message, Throwable cause)
void setDisplayName(String displayName)
void setDeletedFlag(DeletedFlags flag)
void setLastAccessDate(Date lastAccessDate)
void setErrorsOccurred(boolean errorsOccurred)
static CaseMetadata getCaseMetadata(String nodePath)
static CaseNodeData createCaseNodeData(final CaseMetadata metadata)
static final Logger logger
static final int MAJOR_VERSION
boolean isDeletedFlagSet(DeletedFlags flag)
static void writeCaseNodeData(CaseNodeData nodeData)
static CaseNodeData upgradeCaseNodeData(String nodePath, CaseNodeData oldNodeData)
CaseNodeData(CaseMetadata metadata)
static final int MINOR_VERSION
CaseNodeData(byte[] nodeData)
void setMinorVersion(int minorVersion)
static CaseNodeData readCaseNodeData(String nodePath)
boolean getErrorsOccurred()
void setNodeData(CategoryNode category, String nodePath, byte[] data)
static synchronized CoordinationService getInstance()
byte[] getNodeData(CategoryNode category, String nodePath)
synchronized static Logger getLogger(String name)