]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.lz4/src/org/simantics/lz4/impl/LZ4OutputStream.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.lz4 / src / org / simantics / lz4 / impl / LZ4OutputStream.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.lz4.impl;
13
14 import java.io.File;
15 import java.io.FileNotFoundException;
16 import java.io.FileOutputStream;
17 import java.io.IOException;
18 import java.io.OutputStream;
19 import java.nio.ByteBuffer;
20 import java.nio.channels.WritableByteChannel;
21
22 import org.simantics.compressions.impl.CompressingOutputStream;
23 import org.simantics.lz4.LZ4;
24
25 /**
26  * @author Tuukka Lehtonen
27  */
28 public class LZ4OutputStream extends CompressingOutputStream {
29
30     public LZ4OutputStream(File file) throws FileNotFoundException {
31         super(file);
32     }
33
34     public LZ4OutputStream(FileOutputStream stream) {
35         super(stream);
36     }
37     
38     public LZ4OutputStream(OutputStream output) {
39         super(output);
40     }
41
42     
43     public LZ4OutputStream(OutputStream stream, WritableByteChannel channel) {
44         super(stream, channel);
45     }
46
47     @Override
48     protected int compressBound(int inputSize) {
49         return LZ4.compressBound(inputSize);
50     }
51
52     @Override
53     protected int compress(ByteBuffer uncompressed, int uncompressedOffset, int uncompressedSize,
54             ByteBuffer compressed, int compressedOffset) throws IOException {
55         return LZ4.compressBuffer(uncompressed, uncompressedOffset, uncompressedSize, compressed, compressedOffset);
56     }
57
58     protected ByteBuffer allocateBuffer(int capacity) {
59         return ByteBuffer.allocateDirect(capacity);
60     }
61
62 }