Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseNodeData.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2019 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.casemodule.multiusercases;
20 
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23 import java.io.DataInputStream;
24 import java.io.DataOutputStream;
25 import java.io.IOException;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.text.ParseException;
29 import java.util.Date;
31 
36 public final class CaseNodeData {
37 
38  private static final int CURRENT_VERSION = 1;
39 
40  /*
41  * Version 0 fields.
42  */
43  private final int version;
44  private boolean errorsOccurred;
45 
46  /*
47  * Version 1 fields.
48  */
49  private Path directory;
50  private Date createDate;
51  private Date lastAccessDate;
52  private String name;
53  private String displayName;
54  private short deletedItemFlags;
55 
62  public static int getCurrentVersion() {
64  }
65 
76  public CaseNodeData(CaseMetadata metadata) throws ParseException {
77  this.version = CURRENT_VERSION;
78  this.errorsOccurred = false;
79  this.directory = Paths.get(metadata.getCaseDirectory());
80  this.createDate = CaseMetadata.getDateFormat().parse(metadata.getCreatedDate());
81  this.lastAccessDate = new Date();
82  this.name = metadata.getCaseName();
83  this.displayName = metadata.getCaseDisplayName();
84  this.deletedItemFlags = 0;
85  }
86 
96  public CaseNodeData(byte[] nodeData) throws IOException {
97  if (nodeData == null || nodeData.length == 0) {
98  throw new IOException(null == nodeData ? "Null node data byte array" : "Zero-length node data byte array");
99  }
100  DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(nodeData));
101  this.version = inputStream.readInt();
102  if (this.version > 0) {
103  this.errorsOccurred = inputStream.readBoolean();
104  } else {
105  short legacyErrorsOccurred = inputStream.readByte();
106  this.errorsOccurred = (legacyErrorsOccurred < 0);
107  }
108  if (this.version > 0) {
109  this.directory = Paths.get(inputStream.readUTF());
110  this.createDate = new Date(inputStream.readLong());
111  this.lastAccessDate = new Date(inputStream.readLong());
112  this.name = inputStream.readUTF();
113  this.displayName = inputStream.readUTF();
114  this.deletedItemFlags = inputStream.readShort();
115  }
116  }
117 
123  public int getVersion() {
124  return this.version;
125  }
126 
133  public boolean getErrorsOccurred() {
134  return this.errorsOccurred;
135  }
136 
143  public void setErrorsOccurred(boolean errorsOccurred) {
144  this.errorsOccurred = errorsOccurred;
145  }
146 
153  public Path getDirectory() {
154  return this.directory;
155  }
156 
163  public void setDirectory(Path caseDirectory) {
164  this.directory = caseDirectory;
165  }
166 
172  public Date getCreateDate() {
173  return new Date(this.createDate.getTime());
174  }
175 
181  public void setCreateDate(Date createDate) {
182  this.createDate = new Date(createDate.getTime());
183  }
184 
190  public Date getLastAccessDate() {
191  return new Date(this.lastAccessDate.getTime());
192  }
193 
199  public void setLastAccessDate(Date lastAccessDate) {
200  this.lastAccessDate = new Date(lastAccessDate.getTime());
201  }
202 
209  public String getName() {
210  return this.name;
211  }
212 
219  public void setName(String name) {
220  this.name = name;
221  }
222 
228  public String getDisplayName() {
229  return this.displayName;
230  }
231 
237  public void setDisplayName(String displayName) {
238  this.displayName = displayName;
239  }
240 
249  public byte[] toArray() throws IOException {
250  ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
251  DataOutputStream outputStream = new DataOutputStream(byteStream);
252  outputStream.writeInt(this.version);
253  outputStream.writeBoolean(this.errorsOccurred);
254  outputStream.writeUTF(this.directory.toString());
255  outputStream.writeLong(this.createDate.getTime());
256  outputStream.writeLong(this.lastAccessDate.getTime());
257  outputStream.writeUTF(this.name);
258  outputStream.writeUTF(this.displayName);
259  outputStream.writeShort(this.deletedItemFlags);
260  outputStream.flush();
261  byteStream.flush();
262  return byteStream.toByteArray();
263  }
264 
265  public final static class InvalidDataException extends Exception {
266 
267  private static final long serialVersionUID = 1L;
268 
269  private InvalidDataException(String message) {
270  super(message);
271  }
272 
273  private InvalidDataException(String message, Throwable cause) {
274  super(message, cause);
275  }
276  }
277 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.