Autopsy  4.9.1
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 2011-2017 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.coordinationservice;
20 
21 import java.nio.BufferUnderflowException;
22 import java.nio.ByteBuffer;
23 
28 public final class CaseNodeData {
29 
30  private static final int CURRENT_VERSION = 0;
31 
32  private int version;
33  private boolean errorsOccurred;
34 
41  public static int getCurrentVersion() {
43  }
44 
55  public CaseNodeData(byte[] nodeData) throws InvalidDataException {
56  if(nodeData == null || nodeData.length == 0) {
57  this.version = CURRENT_VERSION;
58  this.errorsOccurred = false;
59  } else {
60  /*
61  * Get fields from node data.
62  */
63  ByteBuffer buffer = ByteBuffer.wrap(nodeData);
64  try {
65  if (buffer.hasRemaining()) {
66  this.version = buffer.getInt();
67 
68  /*
69  * Flags bit format: 76543210
70  * 0-6 --> reserved for future use
71  * 7 --> errorsOccurred
72  */
73  byte flags = buffer.get();
74  this.errorsOccurred = (flags < 0);
75  }
76  } catch (BufferUnderflowException ex) {
77  throw new InvalidDataException("Node data is incomplete", ex);
78  }
79  }
80  }
81 
87  public boolean getErrorsOccurred() {
88  return this.errorsOccurred;
89  }
90 
96  public void setErrorsOccurred(boolean errorsOccurred) {
97  this.errorsOccurred = errorsOccurred;
98  }
99 
105  public int getVersion() {
106  return this.version;
107  }
108 
115  public byte[] toArray() {
116  ByteBuffer buffer = ByteBuffer.allocate(5);
117 
118  buffer.putInt(this.version);
119  buffer.put((byte)(this.errorsOccurred ? 0x80 : 0));
120 
121  // Prepare the array
122  byte[] array = new byte[buffer.position()];
123  buffer.rewind();
124  buffer.get(array, 0, array.length);
125 
126  return array;
127  }
128 
129  public final static class InvalidDataException extends Exception {
130 
131  private static final long serialVersionUID = 1L;
132 
133  private InvalidDataException(String message) {
134  super(message);
135  }
136 
137  private InvalidDataException(String message, Throwable cause) {
138  super(message, cause);
139  }
140  }
141 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.