Sleuth Kit Java Bindings (JNI)  4.3
Java bindings for using The Sleuth Kit
EncodedFileOutputStream.java
Go to the documentation of this file.
1 /*
2  * SleuthKit Java Bindings
3  *
4  * Copyright 2011-2016 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.datamodel;
20 
21 import java.io.BufferedOutputStream;
22 import java.io.IOException;
23 import java.io.OutputStream;
24 
31 public class EncodedFileOutputStream extends BufferedOutputStream{
33 
40  public EncodedFileOutputStream(OutputStream out, TskData.EncodingType type) throws IOException{
41  super(out);
42  this.type = type;
43  writeHeader();
44  }
45 
53  public EncodedFileOutputStream(OutputStream out, int size, TskData.EncodingType type) throws IOException{
54  super(out, size);
55  this.type = type;
56  writeHeader();
57  }
58 
59  private void writeHeader() throws IOException{
60  // We get the encoded header here so it will be in plaintext after encoding
61  write(EncodedFileUtil.getEncodedHeader(type), 0, EncodedFileUtil.getHeaderLength());
62  }
63 
64  @Override
65  public void write(int b) throws IOException{
66  super.write((int)EncodedFileUtil.encodeByte((byte)b, type));
67  }
68 
69  @Override
70  public void write(byte[] b,
71  int off,
72  int len)
73  throws IOException{
74  byte[] encodedData = new byte[b.length];
75  for(int i = 0;i < b.length;i++){
76  encodedData[i] = EncodedFileUtil.encodeByte(b[i], type);
77  }
78 
79  super.write(encodedData, off, len);
80  }
81 }
EncodedFileOutputStream(OutputStream out, int size, TskData.EncodingType type)
EncodedFileOutputStream(OutputStream out, TskData.EncodingType type)

Copyright © 2011-2015 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.