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

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