Sleuth Kit Java Bindings (JNI)  4.6
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 {
32 
33  private TskData.EncodingType type;
34 
43  public EncodedFileOutputStream(OutputStream out, TskData.EncodingType type) throws IOException {
44  super(out);
45  this.type = type;
46  writeHeader();
47  }
48 
59  public EncodedFileOutputStream(OutputStream out, int size, TskData.EncodingType type) throws IOException {
60  super(out, size);
61  this.type = type;
62  writeHeader();
63  }
64 
65  private void writeHeader() throws IOException {
66  // We get the encoded header here so it will be in plaintext after encoding
67  write(EncodedFileUtil.getEncodedHeader(type), 0, EncodedFileUtil.getHeaderLength());
68  }
69 
70  @Override
71  public void write(int b) throws IOException {
72  super.write((int) EncodedFileUtil.encodeByte((byte) b, type));
73  }
74 
75  @Override
76  public void write(byte[] b,
77  int off,
78  int len)
79  throws IOException {
80  byte[] encodedData = new byte[b.length];
81  for (int i = 0; i < b.length; i++) {
82  encodedData[i] = EncodedFileUtil.encodeByte(b[i], type);
83  }
84 
85  super.write(encodedData, off, len);
86  }
87 }
EncodedFileOutputStream(OutputStream out, int size, TskData.EncodingType type)
EncodedFileOutputStream(OutputStream out, TskData.EncodingType type)

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