19 package org.sleuthkit.datamodel;
 
   21 import java.io.IOException;
 
   22 import java.io.RandomAccessFile;
 
   23 import java.util.Arrays;
 
   28 class EncodedFileUtil {
 
   30         final static private int HEADER_LENGTH = 32;  
 
   31         final static private String XOR1_HEADER =  
"TSK_CONTAINER_XOR1_xxxxxxxxxxxxx";
 
   39         static String getHeader(TskData.EncodingType type) throws IOException{
 
   44                                 throw new IOException(
"Can not get header for " + type.toString());
 
   57         static byte [] getEncodedHeader(TskData.EncodingType type) throws IOException{
 
   58                 if(type.equals(TskData.EncodingType.NONE)){
 
   59                         throw new IOException(
"Can not get encoded header for " + type.toString());
 
   61                 byte [] encHeader = 
new byte[HEADER_LENGTH];
 
   62                 byte [] plainHeader = getHeader(type).getBytes();
 
   64                 for(
int i = 0;i < HEADER_LENGTH;i++){
 
   65                         encHeader[i] = encodeByte(plainHeader[i], type);
 
   75         static int getHeaderLength(){
 
   86         static byte encodeByte(byte b, TskData.EncodingType type) throws IOException{
 
   89                                 return ((byte)(b ^ 0xca)); 
 
   91                                 throw new IOException(
"Can not encode byte with encoding type " + type.toString());
 
  102         static byte decodeByte(byte b, TskData.EncodingType type) throws IOException{
 
  105                                 return ((byte)(b ^ 0xca)); 
 
  107                                 throw new IOException(
"Can not decode byte with encoding type " + type.toString());
 
  117         static TskData.EncodingType getEncoding(RandomAccessFile fileHandle){
 
  119                         long curOffset = fileHandle.getFilePointer();
 
  120                         if (curOffset != 0) {
 
  123                         byte[] header = 
new byte[HEADER_LENGTH];
 
  124                         int bytesRead = fileHandle.read(header, 0, HEADER_LENGTH);
 
  125                         if(bytesRead != HEADER_LENGTH){
 
  126                                 return TskData.EncodingType.NONE;
 
  129                         return(getTypeFromHeader(header));
 
  130                 } 
catch (IOException ex){
 
  131                         return TskData.EncodingType.NONE;
 
  140         static private TskData.EncodingType getTypeFromHeader(byte[] header){
 
  141                 if(header.length != HEADER_LENGTH){
 
  142                         return TskData.EncodingType.NONE;
 
  145                 if(Arrays.equals(header, XOR1_HEADER.getBytes())){
 
  146                         return TskData.EncodingType.XOR1;
 
  148                         return TskData.EncodingType.NONE;