X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.fastlz%2Fsrc%2Forg%2Fsimantics%2Ffastlz%2Fjava%2FFastLZJavaOutputStream.java;fp=bundles%2Forg.simantics.fastlz%2Fsrc%2Forg%2Fsimantics%2Ffastlz%2Fjava%2FFastLZJavaOutputStream.java;h=c5307da50885a094b9600b19f0c4389eed6ca304;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaOutputStream.java b/bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaOutputStream.java new file mode 100644 index 000000000..c5307da50 --- /dev/null +++ b/bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaOutputStream.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.fastlz.java; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.channels.WritableByteChannel; + +import org.simantics.compressions.impl.CompressingOutputStream; +import org.simantics.fastlz.FastLZ; +import org.simantics.fastlz.FastLZJava; + + +/** + * @author Tuukka Lehtonen + */ +public class FastLZJavaOutputStream extends CompressingOutputStream { + + public FastLZJavaOutputStream(File file) throws FileNotFoundException { + super(file); + } + + public FastLZJavaOutputStream(FileOutputStream stream) { + super(stream); + } + + public FastLZJavaOutputStream(OutputStream stream) { + super(stream); + } + + public FastLZJavaOutputStream(OutputStream stream, WritableByteChannel channel) { + super(stream, channel); + } + + @Override + protected int compressBound(int inputSize) { + return FastLZ.compressBound(inputSize); + } + + @Override + protected int compress(ByteBuffer uncompressed, int uncompressedOffset, int uncompressedSize, + ByteBuffer compressed, int compressedOffset) throws IOException { + return FastLZJava.compress(uncompressed.array(), 0, uncompressedSize, compressed.array(), 8); + } + + protected ByteBuffer allocateBuffer(int capacity) { + return ByteBuffer.allocate(capacity); + } + +}