]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaOutputStream.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / java / FastLZJavaOutputStream.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.fastlz.java;
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.fastlz.FastLZ;
24 import org.simantics.fastlz.FastLZJava;
25
26
27 /**
28  * @author Tuukka Lehtonen
29  */
30 public class FastLZJavaOutputStream extends CompressingOutputStream {
31
32     public FastLZJavaOutputStream(File file) throws FileNotFoundException {
33         super(file);
34     }
35
36     public FastLZJavaOutputStream(FileOutputStream stream) {
37         super(stream);
38     }
39
40     public FastLZJavaOutputStream(OutputStream stream) {
41         super(stream);
42     }
43
44     public FastLZJavaOutputStream(OutputStream stream, WritableByteChannel channel) {
45         super(stream, channel);
46     }
47
48     @Override
49     protected int compressBound(int inputSize) {
50         return FastLZ.compressBound(inputSize);
51     }
52
53     @Override
54     protected int compress(ByteBuffer uncompressed, int uncompressedOffset, int uncompressedSize,
55             ByteBuffer compressed, int compressedOffset) throws IOException {
56         return FastLZJava.compress(uncompressed.array(), 0, uncompressedSize, compressed.array(), 8);
57     }
58
59     protected ByteBuffer allocateBuffer(int capacity) {
60         return ByteBuffer.allocate(capacity);
61     }
62
63 }