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.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.nio.ByteBuffer;
20 import java.nio.channels.ReadableByteChannel;
22 import org.simantics.compressions.impl.DecompressingInputStream;
23 import org.simantics.fastlz.FastLZJava;
26 * @author Tuukka Lehtonen
28 public class FastLZJavaInputStream extends DecompressingInputStream {
30 public FastLZJavaInputStream(File file) throws FileNotFoundException {
34 public FastLZJavaInputStream(FileInputStream stream) {
38 public FastLZJavaInputStream(InputStream stream) {
42 public FastLZJavaInputStream(InputStream stream, ReadableByteChannel channel) {
43 super(stream, channel);
47 protected ByteBuffer allocateBuffer(int capacity) {
48 return ByteBuffer.allocate(capacity);
52 public void decompress(ByteBuffer compressed, int compressedOffset, int compressedSize, ByteBuffer uncompressed,
53 int uncompressedOffset, int uncompressedSize) throws IOException {
54 int decompressed = FastLZJava.decompress(compressed.array(), 0,
55 compressedSize, uncompressed.array(), 0, uncompressedSize);
56 if (decompressed != uncompressedSize)
57 throw new IOException("decompressed " + decompressed + " bytes when " + uncompressedSize + " bytes were expected.");