]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fastlz/src/org/simantics/fastlz/java/FastLZJavaInputStream.java
Merge commit '876ede6'
[simantics/platform.git] / bundles / org.simantics.fastlz / src / org / simantics / fastlz / java / FastLZJavaInputStream.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.fastlz.java;\r
13 \r
14 import java.io.File;\r
15 import java.io.FileInputStream;\r
16 import java.io.FileNotFoundException;\r
17 import java.io.IOException;\r
18 import java.io.InputStream;\r
19 import java.nio.ByteBuffer;\r
20 import java.nio.channels.ReadableByteChannel;\r
21 \r
22 import org.simantics.compressions.impl.DecompressingInputStream;\r
23 import org.simantics.fastlz.FastLZJava;\r
24 \r
25 /**\r
26  * @author Tuukka Lehtonen\r
27  */\r
28 public class FastLZJavaInputStream extends DecompressingInputStream {\r
29 \r
30     public FastLZJavaInputStream(File file) throws FileNotFoundException {\r
31         super(file);\r
32     }\r
33 \r
34     public FastLZJavaInputStream(FileInputStream stream) {\r
35         super(stream);\r
36     }\r
37 \r
38     public FastLZJavaInputStream(InputStream stream) {\r
39         super(stream);\r
40     }\r
41 \r
42     public FastLZJavaInputStream(InputStream stream, ReadableByteChannel channel) {\r
43         super(stream, channel);\r
44     }\r
45 \r
46     @Override\r
47     protected ByteBuffer allocateBuffer(int capacity) {\r
48         return ByteBuffer.allocate(capacity);\r
49     }\r
50     \r
51     @Override\r
52     public void decompress(ByteBuffer compressed, int compressedOffset, int compressedSize, ByteBuffer uncompressed,\r
53             int uncompressedOffset, int uncompressedSize) throws IOException {\r
54         int decompressed = FastLZJava.decompress(compressed.array(), 0,\r
55                 compressedSize, uncompressed.array(), 0, uncompressedSize);\r
56         if (decompressed != uncompressedSize)\r
57             throw new IOException("decompressed " + decompressed + " bytes when " + uncompressedSize + " bytes were expected.");\r
58     }\r
59 \r
60 }\r