
dorkbox.cabParser.CabParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of CabParser Show documentation
Show all versions of CabParser Show documentation
Parse and extract data from inside Microsoft .cab files, specifically those compressed with LZX, for java.
/*
* Copyright 2012 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.cabParser;
import dorkbox.cabParser.decompress.CabDecompressor;
import dorkbox.cabParser.structure.CabEnumerator;
import dorkbox.cabParser.structure.CabFileEntry;
import dorkbox.cabParser.structure.CabFolderEntry;
import dorkbox.cabParser.structure.CabHeader;
import dorkbox.util.process.NullOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
public final class CabParser {
private CabInputStream cabInputStream;
private CabStreamSaver streamSaver;
private ByteArrayOutputStream outputStream = null;
public CabHeader header;
public CabFolderEntry[] folders;
public CabFileEntry[] files;
public
CabParser(InputStream inputStream, final String fileNameToExtract) throws CabException, IOException {
if (fileNameToExtract == null || fileNameToExtract.isEmpty()) {
throw new IllegalArgumentException("Filename must be valid!");
}
this.cabInputStream = new CabInputStream(inputStream);
this.streamSaver = new CabStreamSaver() {
@Override
public boolean saveReservedAreaData(byte[] data, int dataLength) {
return false;
}
@Override
public OutputStream openOutputStream(CabFileEntry cabFile) {
String name = cabFile.getName();
if (fileNameToExtract.equalsIgnoreCase(name)) {
CabParser.this.outputStream = new ByteArrayOutputStream((int) cabFile.getSize());
return CabParser.this.outputStream;
} else {
return null;
}
}
@Override
public void closeOutputStream(OutputStream outputStream, CabFileEntry cabFile) {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException ignored) {
}
}
}
};
readData();
}
public
CabParser(InputStream inputStream, CabStreamSaver streamSaver) throws CabException, IOException {
this.streamSaver = streamSaver;
this.cabInputStream = new CabInputStream(inputStream);
readData();
}
/**
* Gets the version number.
*/
public static
String getVersion() {
return "2.9";
}
public Enumeration
© 2015 - 2025 Weber Informatics LLC | Privacy Policy