1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.fastlz.java;
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;
22 import org.simantics.compressions.impl.CompressingOutputStream;
23 import org.simantics.fastlz.FastLZ;
24 import org.simantics.fastlz.FastLZJava;
28 * @author Tuukka Lehtonen
30 public class FastLZJavaOutputStream extends CompressingOutputStream {
32 public FastLZJavaOutputStream(File file) throws FileNotFoundException {
36 public FastLZJavaOutputStream(FileOutputStream stream) {
40 public FastLZJavaOutputStream(OutputStream stream) {
44 public FastLZJavaOutputStream(OutputStream stream, WritableByteChannel channel) {
45 super(stream, channel);
49 protected int compressBound(int inputSize) {
50 return FastLZ.compressBound(inputSize);
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);
59 protected ByteBuffer allocateBuffer(int capacity) {
60 return ByteBuffer.allocate(capacity);