diff --git a/src/dorkbox/util/cab/CabStreamSaver.java b/src/dorkbox/util/cab/CabStreamSaver.java index 09badf4..0c673be 100644 --- a/src/dorkbox/util/cab/CabStreamSaver.java +++ b/src/dorkbox/util/cab/CabStreamSaver.java @@ -15,12 +15,12 @@ */ package dorkbox.util.cab; -import java.io.OutputStream; - import dorkbox.util.cab.structure.CabFileEntry; +import java.io.OutputStream; + public interface CabStreamSaver { - public abstract OutputStream openOutputStream(CabFileEntry entry); - public abstract void closeOutputStream(OutputStream outputStream, CabFileEntry entry); - public abstract boolean saveReservedAreaData(byte[] data, int dataLength); + OutputStream openOutputStream(CabFileEntry entry); + void closeOutputStream(OutputStream outputStream, CabFileEntry entry); + boolean saveReservedAreaData(byte[] data, int dataLength); } diff --git a/src/dorkbox/util/cab/decompress/Decompressor.java b/src/dorkbox/util/cab/decompress/Decompressor.java index 00ddbb3..78de244 100644 --- a/src/dorkbox/util/cab/decompress/Decompressor.java +++ b/src/dorkbox/util/cab/decompress/Decompressor.java @@ -20,8 +20,8 @@ import dorkbox.util.cab.structure.CabConstants; public interface Decompressor extends CabConstants { - public abstract void init(int windowBits) throws CabException; - public abstract void decompress(byte[] inputBytes, byte[] outputBytes, int inputLength, int outputLength) throws CabException; - public abstract int getMaxGrowth(); - public abstract void reset(int windowBits) throws CabException; + void init(int windowBits) throws CabException; + void decompress(byte[] inputBytes, byte[] outputBytes, int inputLength, int outputLength) throws CabException; + int getMaxGrowth(); + void reset(int windowBits) throws CabException; } diff --git a/src/dorkbox/util/cab/decompress/lzx/DecompressLzx.java b/src/dorkbox/util/cab/decompress/lzx/DecompressLzx.java index d920c98..f4127b5 100644 --- a/src/dorkbox/util/cab/decompress/lzx/DecompressLzx.java +++ b/src/dorkbox/util/cab/decompress/lzx/DecompressLzx.java @@ -150,11 +150,11 @@ public final class DecompressLzx implements Decompressor, LZXConstants { private int decompressLoop(int bytesToRead) throws CabException { int i = bytesToRead; - int lastWindowPosition = 0; + int lastWindowPosition; int k; int m; - if (this.readHeader == true) { + if (this.readHeader) { // read header if (readBits(1) == 1) { k = readBits(16); @@ -266,6 +266,7 @@ public final class DecompressLzx implements Decompressor, LZXConstants { return lastWindowPosition; } + @SuppressWarnings("NumericCastThatLosesPrecision") private void decodeIntelBlock(byte[] bytes, int outLength) { if (outLength <= 6 || !this.intelStarted) { this.intelCursorPos += outLength; @@ -281,7 +282,7 @@ public final class DecompressLzx implements Decompressor, LZXConstants { // save bytes while (abs_off < 6) { this.savedBytes[abs_off] = bytes[adjustedOutLength + abs_off]; - bytes[adjustedOutLength + abs_off] = -24; + bytes[adjustedOutLength + abs_off] = (byte) -24; abs_off++; } @@ -383,6 +384,7 @@ public final class DecompressLzx implements Decompressor, LZXConstants { } while (i < this.wndSize); } + @SuppressWarnings("NumericCastThatLosesPrecision") private void verbatimAlgo(int this_run) throws CorruptCabException { int i = this.windowPosition; int mask = this.windowMask; @@ -480,6 +482,7 @@ public final class DecompressLzx implements Decompressor, LZXConstants { return i; } + @SuppressWarnings("NumericCastThatLosesPrecision") private void alignedAlgo(int this_run) throws CorruptCabException { int windowPos = this.windowPosition; int mask = this.windowMask; diff --git a/src/dorkbox/util/cab/decompress/zip/DecompressZip.java b/src/dorkbox/util/cab/decompress/zip/DecompressZip.java index 785d312..b083dad 100644 --- a/src/dorkbox/util/cab/decompress/zip/DecompressZip.java +++ b/src/dorkbox/util/cab/decompress/zip/DecompressZip.java @@ -111,7 +111,8 @@ public final class DecompressZip implements Decompressor { } } - private void b() throws CabException { + @SuppressWarnings({"NumericCastThatLosesPrecision", "Duplicates"}) + private void bits() throws CabException { int i = this.int3; int j = this.outputLength; byte[] arrayOfByte1 = this.outputBytes; @@ -125,6 +126,7 @@ public final class DecompressZip implements Decompressor { byte[] arrayOfByte3 = this.state2.byteA; int k = this.int1; int m = this.int2; + do { if (this.index > this.inputPlus4) { break; @@ -222,34 +224,39 @@ public final class DecompressZip implements Decompressor { } private void readStuffcommon() throws CabException { - this.state1.c(); - this.state2.c(); + this.state1.main(); + this.state2.main(); } - private void c() { + private void setup() { int i = 0; + do { - this.state1.byteA[i] = 8; + this.state1.byteA[i] = (byte) 8; i++; } while (i <= 143); + i = 144; do { - this.state1.byteA[i] = 9; + this.state1.byteA[i] = (byte) 9; i++; } while (i <= 255); i = 256; + do { - this.state1.byteA[i] = 7; + this.state1.byteA[i] = (byte) 7; i++; } while (i <= 279); i = 280; + do { - this.state1.byteA[i] = 8; + this.state1.byteA[i] = (byte) 8; i++; } while (i <= 287); + i = 0; do { - this.state2.byteA[i] = 5; + this.state2.byteA[i] = (byte) 5; i++; } while (i < 32); } @@ -258,7 +265,8 @@ public final class DecompressZip implements Decompressor { return byte1 & 0xFF | (byte2 & 0xFF) << 8; } - private void d() throws CabException { + @SuppressWarnings("NumericCastThatLosesPrecision") + private void expand() throws CabException { check(); int i = calc(5) + 257; int j = calc(5) + 1; @@ -268,9 +276,9 @@ public final class DecompressZip implements Decompressor { check(); } for (int n = k; n < ar3.length; n++) { - this.state3.byteA[ar3[n]] = 0; + this.state3.byteA[ar3[n]] = (byte) 0; } - this.state3.c(); + this.state3.main(); int m = i + j; int n = 0; while (n < m) { @@ -299,7 +307,7 @@ public final class DecompressZip implements Decompressor { throw new CorruptCabException(); } for (i3 = 0; i3 < i2; i3++) { - this.bytes[n++] = 0; + this.bytes[n++] = (byte) 0; } } else { i2 = calc(7) + 11; @@ -307,20 +315,21 @@ public final class DecompressZip implements Decompressor { throw new CorruptCabException(); } for (i3 = 0; i3 < i2; i3++) { - this.bytes[n++] = 0; + this.bytes[n++] = (byte) 0; } } } } + System.arraycopy(this.bytes, 0, this.state1.byteA, 0, i); for (n = i; n < 288; n++) { - this.state1.byteA[n] = 0; + this.state1.byteA[n] = (byte) 0; } for (n = 0; n < j; n++) { this.state2.byteA[n] = this.bytes[n + i]; } for (n = j; n < 32; n++) { - this.state2.byteA[n] = 0; + this.state2.byteA[n] = (byte) 0; } if (this.state1.byteA[256] == 0) { throw new CorruptCabException(); @@ -344,26 +353,26 @@ public final class DecompressZip implements Decompressor { int i = calc(1); int j = calc(2); if (j == 2) { - d(); + expand(); readStuffcommon(); - b(); + bits(); return; } if (j == 1) { - c(); + setup(); readStuffcommon(); - b(); + bits(); return; } if (j == 0) { - e(); + verify(); return; } throw new CabException(); } - private void e() throws CabException { + private void verify() throws CabException { mod(); if (this.index >= this.inputPlus4) { throw new CorruptCabException(); @@ -371,7 +380,8 @@ public final class DecompressZip implements Decompressor { int i = makeShort(this.inputBytes[this.index], this.inputBytes[this.index + 1]); int j = makeShort(this.inputBytes[this.index + 2], this.inputBytes[this.index + 3]); - if ((short) i != (short) (j ^ 0xFFFFFFFF)) { + //noinspection NumericCastThatLosesPrecision + if ((short) i != (short) (~j)) { throw new CorruptCabException(); } diff --git a/src/dorkbox/util/cab/decompress/zip/DecompressZipState.java b/src/dorkbox/util/cab/decompress/zip/DecompressZipState.java index caaa150..f1f9f4e 100644 --- a/src/dorkbox/util/cab/decompress/zip/DecompressZipState.java +++ b/src/dorkbox/util/cab/decompress/zip/DecompressZipState.java @@ -45,7 +45,7 @@ final class DecompressZipState { this.intA4 = new int[this.intA * 2]; } - void c() throws CorruptCabException { + void main() throws CorruptCabException { int[] arrayOfInt1 = new int[17]; int[] arrayOfInt2 = new int[17]; int k = 0; diff --git a/src/dorkbox/util/cab/structure/CabConstants.java b/src/dorkbox/util/cab/structure/CabConstants.java index da59da2..274fc52 100644 --- a/src/dorkbox/util/cab/structure/CabConstants.java +++ b/src/dorkbox/util/cab/structure/CabConstants.java @@ -16,39 +16,39 @@ package dorkbox.util.cab.structure; public interface CabConstants { - public static final int CAB_BLOCK_SIZE = 32768; - public static final int CAB_BLOCK_SIZE_THRESH = 32767; + int CAB_BLOCK_SIZE = 32768; + int CAB_BLOCK_SIZE_THRESH = 32767; - public static final int COMPRESSION_TYPE_NONE = 0; - public static final int COMPRESSION_TYPE_MSZIP = 1; - public static final int COMPRESSION_TYPE_QUANTUM = 2; - public static final int COMPRESSION_TYPE_LZX = 3; + int COMPRESSION_TYPE_NONE = 0; + int COMPRESSION_TYPE_MSZIP = 1; + int COMPRESSION_TYPE_QUANTUM = 2; + int COMPRESSION_TYPE_LZX = 3; - public static final int RESERVED_CFHEADER = 1; - public static final int RESERVED_CFFOLDER = 2; + int RESERVED_CFHEADER = 1; + int RESERVED_CFFOLDER = 2; - public static final int RESERVED_CFDATA = 3; + int RESERVED_CFDATA = 3; - public static final int CAB_PROGRESS_INPUT = 1; + int CAB_PROGRESS_INPUT = 1; /** * FLAG_PREV_CABINET is set if this cabinet file is not the first in a set * of cabinet files. When this bit is set, the szCabinetPrev and szDiskPrev * fields are present in this CFHEADER. */ - static final int FLAG_PREV_CABINET = 0x0001; + int FLAG_PREV_CABINET = 0x0001; /** * FLAG_NEXT_CABINET is set if this cabinet file is not the last in a set of * cabinet files. When this bit is set, the szCabinetNext and szDiskNext * fields are present in this CFHEADER. */ - static final int FLAG_NEXT_CABINET = 0x0002; + int FLAG_NEXT_CABINET = 0x0002; /** * FLAG_RESERVE_PRESENT is set if this cabinet file contains any reserved * fields. When this bit is set, the cbCFHeader, cbCFFolder, and cbCFData * fields are present in this CFHEADER. */ - static final int FLAG_RESERVE_PRESENT = 0x0004; + int FLAG_RESERVE_PRESENT = 0x0004; } diff --git a/src/dorkbox/util/cab/structure/CabFolderEntry.java b/src/dorkbox/util/cab/structure/CabFolderEntry.java index cab2184..f4b8f04 100644 --- a/src/dorkbox/util/cab/structure/CabFolderEntry.java +++ b/src/dorkbox/util/cab/structure/CabFolderEntry.java @@ -15,16 +15,18 @@ */ package dorkbox.util.cab.structure; +import dorkbox.util.bytes.LittleEndian; + import java.io.IOException; import java.io.InputStream; -import dorkbox.util.bytes.LittleEndian; - public final class CabFolderEntry implements CabConstants { /** offset of the first CFDATA block in this folder, 4bytes */ public long coffCabStart; + /** number of CFDATA blocks in this folder, 2bytes */ public int cCFData; + /** compression type indicator , 2bytes */ public int compressionMethod = 0;