Moved out of utils, changed CabDecoder -> CabParser

This commit is contained in:
nathan 2016-02-10 18:57:16 +01:00
parent faf9dd1bef
commit 27b5842caa
21 changed files with 87 additions and 78 deletions

View File

@ -19,7 +19,7 @@ This project is **kept in sync** with the utilities library, so "jar hell" is no
<dependency>
<groupId>com.dorkbox</groupId>
<artifactId>CabParser</artifactId>
<version>1.1</version>
<version>2.0</version>
</dependency>
```
@ -31,3 +31,7 @@ https://oss.sonatype.org/content/repositories/releases/com/dorkbox/CabParser-Dor
<h2>License</h2>
This project is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab;
package dorkbox.cabParser;
public class CabException extends Exception {
private static final long serialVersionUID = 1L;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab;
package dorkbox.cabParser;
import java.io.IOException;
import java.io.InputStream;

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab;
package dorkbox.cabParser;
import dorkbox.util.cab.decompress.CabDecompressor;
import dorkbox.util.cab.structure.CabEnumerator;
import dorkbox.util.cab.structure.CabFileEntry;
import dorkbox.util.cab.structure.CabFolderEntry;
import dorkbox.util.cab.structure.CabHeader;
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;
@ -28,7 +28,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
public final class CabDecoder {
public final class CabParser {
private CabInputStream cabInputStream;
private CabStreamSaver streamSaver;
@ -39,7 +39,8 @@ public final class CabDecoder {
public CabFolderEntry[] folders;
public CabFileEntry[] files;
public CabDecoder(InputStream inputStream, final String fileNameToExtract) throws CabException, IOException {
public
CabParser(InputStream inputStream, final String fileNameToExtract) throws CabException, IOException {
if (fileNameToExtract == null || fileNameToExtract.isEmpty()) {
throw new IllegalArgumentException("Filename must be valid!");
}
@ -55,8 +56,8 @@ public final class CabDecoder {
public OutputStream openOutputStream(CabFileEntry cabFile) {
String name = cabFile.getName();
if (fileNameToExtract.equalsIgnoreCase(name)) {
CabDecoder.this.outputStream = new ByteArrayOutputStream((int) cabFile.getSize());
return CabDecoder.this.outputStream;
CabParser.this.outputStream = new ByteArrayOutputStream((int) cabFile.getSize());
return CabParser.this.outputStream;
} else {
return null;
}
@ -67,7 +68,7 @@ public final class CabDecoder {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
} catch (IOException ignored) {
}
}
}
@ -76,7 +77,8 @@ public final class CabDecoder {
readData();
}
public CabDecoder(InputStream inputStream, CabStreamSaver streamSaver) throws CabException, IOException {
public
CabParser(InputStream inputStream, CabStreamSaver streamSaver) throws CabException, IOException {
this.streamSaver = streamSaver;
this.cabInputStream = new CabInputStream(inputStream);
@ -88,7 +90,7 @@ public final class CabDecoder {
*/
public static
String getVersion() {
return "1.1";
return "2.0";
}
public Enumeration<Object> entries() {
@ -174,3 +176,6 @@ public final class CabDecoder {
return this.outputStream;
}
}

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab;
package dorkbox.cabParser;
import dorkbox.util.cab.structure.CabFileEntry;
import dorkbox.cabParser.structure.CabFileEntry;
import java.io.OutputStream;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab;
package dorkbox.cabParser;
public final class Checksum {
@SuppressWarnings("fallthrough")

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab;
package dorkbox.cabParser;
public final class CorruptCabException extends CabException {

View File

@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress;
package dorkbox.cabParser.decompress;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.util.cab.decompress.lzx.DecompressLzx;
import dorkbox.util.cab.decompress.none.DecompressNone;
import dorkbox.util.cab.decompress.zip.DecompressZip;
import dorkbox.util.cab.structure.CabConstants;
import dorkbox.util.cab.structure.CfDataRecord;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.decompress.lzx.DecompressLzx;
import dorkbox.cabParser.decompress.zip.DecompressZip;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.cabParser.decompress.none.DecompressNone;
import dorkbox.cabParser.structure.CabConstants;
import dorkbox.cabParser.structure.CfDataRecord;
public final class CabDecompressor implements CabConstants {
private byte[] readBuffer;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress;
package dorkbox.cabParser.decompress;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.structure.CabConstants;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.structure.CabConstants;
public interface Decompressor extends CabConstants {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress.lzx;
package dorkbox.cabParser.decompress.lzx;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.util.cab.decompress.Decompressor;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.cabParser.decompress.Decompressor;
public final class DecompressLzx implements Decompressor, LZXConstants {
private int[] extraBits = new int[51];
@ -107,14 +107,14 @@ public final class DecompressLzx implements Decompressor, LZXConstants {
int decompressedOutputLength = decompressLoop(outputLength);
System.arraycopy(this.localWindow, this.outputPosition, outputBytes, 0, decompressedOutputLength);
if (this.framesRead++ < LZXConstants.E8_DISABLE_THRESHOLD && this.intelFileSize != 0) {
if (this.framesRead++ < E8_DISABLE_THRESHOLD && this.intelFileSize != 0) {
decodeIntelBlock(outputBytes, decompressedOutputLength);
}
}
@Override
public int getMaxGrowth() {
return LZXConstants.MAX_GROWTH;
return MAX_GROWTH;
}
@Override

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress.lzx;
package dorkbox.cabParser.decompress.lzx;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.cabParser.CorruptCabException;
final class DecompressLzxTree implements LZXConstants {
private int size;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress.lzx;
package dorkbox.cabParser.decompress.lzx;
public interface LZXConstants {
public static final int PRETREE_NUM_ELEMENTS = 20;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress.none;
package dorkbox.cabParser.decompress.none;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.util.cab.decompress.Decompressor;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.cabParser.decompress.Decompressor;
public final class DecompressNone implements Decompressor {
@Override

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress.zip;
package dorkbox.cabParser.decompress.zip;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.util.cab.decompress.Decompressor;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.cabParser.decompress.Decompressor;
public final class DecompressZip implements Decompressor {
private static final int[] ar1 = {3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.decompress.zip;
package dorkbox.cabParser.decompress.zip;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.cabParser.CorruptCabException;
final class DecompressZipState {
private int intA;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.structure;
package dorkbox.cabParser.structure;
public interface CabConstants {
int CAB_BLOCK_SIZE = 32768;

View File

@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.structure;
package dorkbox.cabParser.structure;
import dorkbox.cabParser.CabParser;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import dorkbox.util.cab.CabDecoder;
public final class CabEnumerator implements Enumeration<Object> {
private int fileCount = 0;
private int folderCount = 0;
private CabDecoder cabDecoder;
private CabParser cabParser;
private boolean b;
private int folderIndex;
@ -32,35 +32,35 @@ public final class CabEnumerator implements Enumeration<Object> {
@Override
public Object nextElement() {
if (!this.b) {
if (this.fileCount < this.cabDecoder.header.cFiles) {
return this.cabDecoder.files[this.fileCount++];
if (this.fileCount < this.cabParser.header.cFiles) {
return this.cabParser.files[this.fileCount++];
}
throw new NoSuchElementException();
}
if (this.cabDecoder.files[this.fileCount].iFolder != this.folderIndex) {
this.folderIndex = this.cabDecoder.files[this.fileCount].iFolder;
if (this.cabParser.files[this.fileCount].iFolder != this.folderIndex) {
this.folderIndex = this.cabParser.files[this.fileCount].iFolder;
if (this.folderCount < this.cabDecoder.folders.length) {
return this.cabDecoder.folders[this.folderCount++];
if (this.folderCount < this.cabParser.folders.length) {
return this.cabParser.folders[this.folderCount++];
}
}
if (this.fileCount < this.cabDecoder.header.cFiles) {
return this.cabDecoder.files[this.fileCount++];
if (this.fileCount < this.cabParser.header.cFiles) {
return this.cabParser.files[this.fileCount++];
}
throw new NoSuchElementException();
}
public CabEnumerator(CabDecoder decoder, boolean b) {
this.cabDecoder = decoder;
public CabEnumerator(CabParser decoder, boolean b) {
this.cabParser = decoder;
this.b = b;
this.folderIndex = -2;
}
@Override
public boolean hasMoreElements() {
return this.fileCount < this.cabDecoder.header.cFiles;
return this.fileCount < this.cabParser.header.cFiles;
}
}

View File

@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.structure;
package dorkbox.cabParser.structure;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Date;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.util.bytes.LittleEndian;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.CorruptCabException;
public final class CabFileEntry {
public static final Charset US_ASCII = Charset.forName("US-ASCII");

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.structure;
package dorkbox.cabParser.structure;
import dorkbox.util.bytes.LittleEndian;

View File

@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.structure;
package dorkbox.cabParser.structure;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.util.bytes.LittleEndian;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.CabStreamSaver;
import dorkbox.util.cab.CorruptCabException;
import dorkbox.cabParser.CabStreamSaver;
public final class CabHeader implements CabConstants {

View File

@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.cab.structure;
package dorkbox.cabParser.structure;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import dorkbox.cabParser.CabException;
import dorkbox.cabParser.Checksum;
import dorkbox.cabParser.CorruptCabException;
import dorkbox.util.bytes.LittleEndian;
import dorkbox.util.cab.CabException;
import dorkbox.util.cab.Checksum;
import dorkbox.util.cab.CorruptCabException;
public final class CfDataRecord {
/** checksum of this CFDATA entry , 4bytes */