
darwin.jopenctm.io.PackedInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JOpenCTM Show documentation
Show all versions of JOpenCTM Show documentation
Java implementation of the openCTM Mesh compression file format
The newest version!
/*
* Copyright (C) 2012 Daniel Heinrich
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* (version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see
* or write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301 USA.
*/
package darwin.jopenctm.io;
import java.io.*;
import lzma.sdk.lzma.Decoder;
import org.cservenak.streams.*;
/**
*
* @author daniel
*/
public final class PackedInputStream extends CoderInputStream {
protected PackedInputStream(byte[] packedData) throws IOException {
super(new ByteArrayInputStream(packedData), new CustomWrapper(packedData.length));
}
private static class CustomWrapper implements Coder {
private final Decoder d;
private final int len;
public CustomWrapper(int packedLength) {
d = new Decoder();
len = packedLength;
}
@Override
public void code(final InputStream in, final OutputStream out)
throws IOException {
byte[] properties = new byte[5];
if (in.read(properties) != 5) {
throw new IOException("LZMA file has no header!");
}
if (!d.setDecoderProperties(properties)) {
throw new IOException("Decoder properties cannot be set!");
}
if (!d.code(in, out, len)) {
throw new IOException("Decoding unsuccessful!");
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy