1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.compressions;
\r
14 import java.io.File;
\r
15 import java.io.FileNotFoundException;
\r
16 import java.io.FileOutputStream;
\r
17 import java.io.InputStream;
\r
18 import java.io.OutputStream;
\r
19 import java.nio.ByteBuffer;
\r
22 * @author Tuukka Lehtonen
\r
24 public interface CompressionCodec {
\r
27 * @param inputSize size of uncompressed input data in bytes
\r
28 * @return maximum amount of bytes needed for the compressed data
\r
30 int compressBound(int inputSize);
\r
32 int compress(byte[] uncompressedData, int i, int length,
\r
33 byte[] compressedData, int j);
\r
36 * Compress a block of data in the input buffer and returns the size of
\r
37 * compressed block. The size of input buffer is specified by length. The
\r
38 * minimum input buffer size is 16.
\r
41 * The output buffer size must be at least what is reported y
\r
42 * {@link #compressBound(int)} for the input data size.
\r
45 * If the input is not compressible, the return value might be larger than
\r
46 * length (input buffer size).
\r
49 * The input buffer and the output buffer can not overlap.
\r
52 * It is recommended to have both input buffers as direct or heap buffers,
\r
53 * not mixed. Mixing different types of buffers will hurt performance a lot.
\r
54 * If both buffers are direct byte buffers and native decompression is
\r
55 * available, it will be employed.
\r
57 int compressBuffer(ByteBuffer input, int inputOffset, int length,
\r
58 ByteBuffer output, int outputOffset);
\r
60 byte[] decompress(byte[] compressedData, int i, int uncompressedLength);
\r
63 * Decompress a block of compressed data and returns the size of the
\r
64 * decompressed block. If error occurs, e.g. the compressed data is
\r
65 * corrupted or the output buffer is not large enough, then 0 (zero) will be
\r
69 * The input buffer and the output buffer can not overlap.
\r
72 * Decompression is memory safe and guaranteed not to write the output
\r
73 * buffer more than what is specified in maxout.
\r
76 * It is recommended to have both input buffers as direct or heap buffers,
\r
77 * not mixed. Mixing different types of buffers will hurt performance a lot.
\r
78 * If both buffers are direct byte buffers and native decompression is
\r
79 * available, it will be employed.
\r
81 int decompressBuffer(ByteBuffer input, int inputOffset, int length,
\r
82 ByteBuffer output, int outputOffset, int maxout);
\r
86 * the compressed file to read
\r
87 * @return input stream that decompresses its output using the codec's
\r
89 * @throws FileNotFoundException
\r
90 * see {@link FileOutputStream#FileOutputStream(File)} for when
\r
93 InputStream read(File file) throws FileNotFoundException;
\r
97 * the compressed file to write
\r
98 * @return output stream that compresses its input using the codec's
\r
100 * @throws FileNotFoundException
\r
101 * see {@link FileOutputStream#FileOutputStream(File)} for when
\r
104 OutputStream write(File file) throws FileNotFoundException;
\r