├── res └── values │ └── strings.xml ├── docs └── html │ ├── resources │ ├── tab.gif │ ├── background.gif │ ├── titlebar.gif │ └── titlebar_end.gif │ ├── package-list │ ├── net │ └── lingala │ │ └── zip4j │ │ ├── zip │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── progress │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── crypto │ │ ├── engine │ │ │ ├── package-frame.html │ │ │ ├── package-tree.html │ │ │ └── package-summary.html │ │ ├── PBKDF2 │ │ │ ├── package-frame.html │ │ │ ├── package-tree.html │ │ │ └── package-summary.html │ │ └── package-frame.html │ │ ├── unzip │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── core │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── exception │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── util │ │ ├── package-frame.html │ │ └── package-tree.html │ │ ├── io │ │ └── package-frame.html │ │ └── model │ │ └── package-frame.html │ ├── overview-frame.html │ ├── index.html │ ├── deprecated-list.html │ └── serialized-form.html ├── libs └── android-support-v4.jar ├── AndroidManifest.xml ├── .gitignore ├── src └── net │ └── lingala │ └── zip4j │ ├── io │ ├── BaseInputStream.java │ ├── ZipOutputStream.java │ ├── BaseOutputStream.java │ ├── ZipInputStream.java │ ├── DeflaterOutputStream.java │ ├── InflaterInputStream.java │ └── PartInputStream.java │ ├── crypto │ ├── IDecrypter.java │ ├── IEncrypter.java │ ├── PBKDF2 │ │ ├── PRF.java │ │ ├── PBKDF2HexFormatter.java │ │ ├── BinTools.java │ │ ├── PBKDF2Parameters.java │ │ ├── MacBasedPRF.java │ │ └── PBKDF2Engine.java │ ├── engine │ │ └── ZipCryptoEngine.java │ ├── StandardDecrypter.java │ └── StandardEncrypter.java │ ├── exception │ ├── ZipExceptionConstants.java │ └── ZipException.java │ ├── model │ ├── CentralDirectory.java │ ├── ExtraDataRecord.java │ ├── DataDescriptor.java │ ├── DigitalSignature.java │ ├── ArchiveExtraDataRecord.java │ ├── Zip64EndCentralDirLocator.java │ ├── Zip64ExtendedInfo.java │ ├── AESExtraDataRecord.java │ ├── UnzipEngineParameters.java │ ├── UnzipParameters.java │ ├── EndCentralDirRecord.java │ ├── Zip64EndCentralDirRecord.java │ └── ZipModel.java │ ├── util │ ├── Zip4jConstants.java │ ├── CRCUtil.java │ └── Raw.java │ ├── unzip │ └── UnzipUtil.java │ └── progress │ └── ProgressMonitor.java ├── project.properties └── README.md /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Zip4j 3 | 4 | -------------------------------------------------------------------------------- /docs/html/resources/tab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imasm/Android-Zip4j/HEAD/docs/html/resources/tab.gif -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imasm/Android-Zip4j/HEAD/libs/android-support-v4.jar -------------------------------------------------------------------------------- /docs/html/resources/background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imasm/Android-Zip4j/HEAD/docs/html/resources/background.gif -------------------------------------------------------------------------------- /docs/html/resources/titlebar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imasm/Android-Zip4j/HEAD/docs/html/resources/titlebar.gif -------------------------------------------------------------------------------- /docs/html/resources/titlebar_end.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imasm/Android-Zip4j/HEAD/docs/html/resources/titlebar_end.gif -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Android generated 2 | bin 3 | gen 4 | 5 | #Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | 10 | #IntelliJ IDEA 11 | .idea 12 | *.iml 13 | classes 14 | 15 | #Maven 16 | target 17 | release.properties 18 | pom.xml.* 19 | 20 | #Command line 21 | local.properties 22 | build.xml 23 | proguard-project.txt 24 | -------------------------------------------------------------------------------- /docs/html/package-list: -------------------------------------------------------------------------------- 1 | net.lingala.zip4j.core 2 | net.lingala.zip4j.crypto 3 | net.lingala.zip4j.crypto.PBKDF2 4 | net.lingala.zip4j.crypto.engine 5 | net.lingala.zip4j.exception 6 | net.lingala.zip4j.io 7 | net.lingala.zip4j.model 8 | net.lingala.zip4j.progress 9 | net.lingala.zip4j.unzip 10 | net.lingala.zip4j.util 11 | net.lingala.zip4j.zip 12 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/BaseInputStream.java: -------------------------------------------------------------------------------- 1 | package net.lingala.zip4j.io; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import net.lingala.zip4j.unzip.UnzipEngine; 7 | 8 | public abstract class BaseInputStream extends InputStream { 9 | 10 | public int read() throws IOException { 11 | return 0; 12 | } 13 | 14 | public void seek(long pos) throws IOException { 15 | } 16 | 17 | public int available() throws IOException { 18 | return 0; 19 | } 20 | 21 | public UnzipEngine getUnzipEngine() { 22 | return null; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-8 15 | android.library=true 16 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/zip/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.zip 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.zip

12 |
13 |

Classes

14 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/progress/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.progress 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.progress

12 |
13 |

Classes

14 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/ZipOutputStream.java: -------------------------------------------------------------------------------- 1 | package net.lingala.zip4j.io; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | import net.lingala.zip4j.model.ZipModel; 7 | 8 | public class ZipOutputStream extends DeflaterOutputStream { 9 | 10 | public ZipOutputStream(OutputStream outputStream) { 11 | this(outputStream, null); 12 | } 13 | 14 | public ZipOutputStream(OutputStream outputStream, ZipModel zipModel) { 15 | super(outputStream, zipModel); 16 | } 17 | 18 | public void write(int bval) throws IOException { 19 | byte[] b = new byte[1]; 20 | b[0] = (byte) bval; 21 | write(b, 0, 1); 22 | } 23 | 24 | public void write(byte[] b) throws IOException { 25 | write(b, 0, b.length); 26 | } 27 | 28 | public void write(byte[] b, int off, int len) throws IOException { 29 | crc.update(b, off, len); 30 | updateTotalBytesRead(len); 31 | super.write(b, off, len); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/BaseOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.io; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | 22 | public abstract class BaseOutputStream extends OutputStream { 23 | 24 | public void write(int b) throws IOException { 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android Zip4j 2 | ============= 3 | 4 | Zip4j is a Java library for Zip files created by Srikanth Reddy Lingala. 5 | 6 | Please, visit [Lingala Zip4j site][1] or their [forum][2] to get support for it. 7 | 8 | 9 | License 10 | ------- 11 | 12 | Copyright 2010 Srikanth Reddy Lingala 13 | 14 | Licensed under the Apache License, Version 2.0 (the "License"); 15 | you may not use this file except in compliance with the License. 16 | You may obtain a copy of the License at 17 | 18 | http://www.apache.org/licenses/LICENSE-2.0 19 | 20 | Unless required by applicable law or agreed to in writing, software 21 | distributed under the License is distributed on an "AS IS" BASIS, 22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | See the License for the specific language governing permissions and 24 | limitations under the License. 25 | 26 | 27 | 28 | [1]: http://www.lingala.net/zip4j/ 29 | [2]: http://www.lingala.net/zip4j/forum/index.php 30 | 31 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/IDecrypter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto; 18 | 19 | import net.lingala.zip4j.exception.ZipException; 20 | 21 | public interface IDecrypter { 22 | 23 | public int decryptData(byte[] buff, int start, int len) throws ZipException; 24 | 25 | public int decryptData(byte[] buff) throws ZipException; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/IEncrypter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto; 18 | 19 | import net.lingala.zip4j.exception.ZipException; 20 | 21 | public interface IEncrypter { 22 | 23 | public int encryptData(byte[] buff) throws ZipException; 24 | 25 | public int encryptData(byte[] buff, int start, int len) throws ZipException; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/engine/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto.engine 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.crypto.engine

12 |
13 |

Classes

14 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/PBKDF2/PRF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.PBKDF2; 18 | 19 | /* 20 | * Source referred from Matthias Gartner's PKCS#5 implementation - 21 | * see http://rtner.de/software/PBKDF2.html 22 | */ 23 | 24 | interface PRF 25 | { 26 | public void init(byte[] P); 27 | 28 | public byte[] doFinal(byte[] M); 29 | 30 | public int getHLen(); 31 | } 32 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/unzip/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.unzip 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.unzip

12 |
13 |

Classes

14 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/core/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.core 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.core

12 |
13 |

Classes

14 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/exception/ZipExceptionConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.exception; 18 | 19 | public interface ZipExceptionConstants { 20 | 21 | public static int inputZipParamIsNull = 0001; 22 | 23 | public static int constuctorFileNotFoundException = 0002; 24 | 25 | public static int randomAccessFileNull = 0003; 26 | 27 | public static int notZipFile = 0004; 28 | 29 | public static int WRONG_PASSWORD = 0005; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/exception/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.exception 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.exception

12 |
13 |

Interfaces

14 | 17 |

Exceptions

18 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/PBKDF2/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto.PBKDF2 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.crypto.PBKDF2

12 |
13 |

Classes

14 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/CentralDirectory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | import java.util.ArrayList; 20 | 21 | public class CentralDirectory { 22 | 23 | private ArrayList fileHeaders; 24 | 25 | private DigitalSignature digitalSignature; 26 | 27 | public ArrayList getFileHeaders() { 28 | return fileHeaders; 29 | } 30 | 31 | public void setFileHeaders(ArrayList fileHeaders) { 32 | this.fileHeaders = fileHeaders; 33 | } 34 | 35 | public DigitalSignature getDigitalSignature() { 36 | return digitalSignature; 37 | } 38 | 39 | public void setDigitalSignature(DigitalSignature digitalSignature) { 40 | this.digitalSignature = digitalSignature; 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/ExtraDataRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class ExtraDataRecord { 20 | 21 | private long header; 22 | 23 | private int sizeOfData; 24 | 25 | private byte[] data; 26 | 27 | public long getHeader() { 28 | return header; 29 | } 30 | 31 | public void setHeader(long header) { 32 | this.header = header; 33 | } 34 | 35 | public int getSizeOfData() { 36 | return sizeOfData; 37 | } 38 | 39 | public void setSizeOfData(int sizeOfData) { 40 | this.sizeOfData = sizeOfData; 41 | } 42 | 43 | public byte[] getData() { 44 | return data; 45 | } 46 | 47 | public void setData(byte[] data) { 48 | this.data = data; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/DataDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class DataDescriptor { 20 | 21 | private String crc32; 22 | 23 | private int compressedSize; 24 | 25 | private int uncompressedSize; 26 | 27 | public String getCrc32() { 28 | return crc32; 29 | } 30 | 31 | public void setCrc32(String crc32) { 32 | this.crc32 = crc32; 33 | } 34 | 35 | public int getCompressedSize() { 36 | return compressedSize; 37 | } 38 | 39 | public void setCompressedSize(int compressedSize) { 40 | this.compressedSize = compressedSize; 41 | } 42 | 43 | public int getUncompressedSize() { 44 | return uncompressedSize; 45 | } 46 | 47 | public void setUncompressedSize(int uncompressedSize) { 48 | this.uncompressedSize = uncompressedSize; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/DigitalSignature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class DigitalSignature { 20 | 21 | private int headerSignature; 22 | 23 | private int sizeOfData; 24 | 25 | private String signatureData; 26 | 27 | public int getHeaderSignature() { 28 | return headerSignature; 29 | } 30 | 31 | public void setHeaderSignature(int headerSignature) { 32 | this.headerSignature = headerSignature; 33 | } 34 | 35 | public int getSizeOfData() { 36 | return sizeOfData; 37 | } 38 | 39 | public void setSizeOfData(int sizeOfData) { 40 | this.sizeOfData = sizeOfData; 41 | } 42 | 43 | public String getSignatureData() { 44 | return signatureData; 45 | } 46 | 47 | public void setSignatureData(String signatureData) { 48 | this.signatureData = signatureData; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/ArchiveExtraDataRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class ArchiveExtraDataRecord { 20 | 21 | private int signature; 22 | 23 | private int extraFieldLength; 24 | 25 | private String extraFieldData; 26 | 27 | public int getSignature() { 28 | return signature; 29 | } 30 | 31 | public void setSignature(int signature) { 32 | this.signature = signature; 33 | } 34 | 35 | public int getExtraFieldLength() { 36 | return extraFieldLength; 37 | } 38 | 39 | public void setExtraFieldLength(int extraFieldLength) { 40 | this.extraFieldLength = extraFieldLength; 41 | } 42 | 43 | public String getExtraFieldData() { 44 | return extraFieldData; 45 | } 46 | 47 | public void setExtraFieldData(String extraFieldData) { 48 | this.extraFieldData = extraFieldData; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/util/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.util 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.util

12 |
13 |

Interfaces

14 | 18 |

Classes

19 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.crypto

12 |
13 |

Interfaces

14 | 18 |

Classes

19 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/exception/ZipException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.exception; 18 | 19 | public class ZipException extends Exception { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | private int code = -1; 24 | 25 | public ZipException() { 26 | } 27 | 28 | public ZipException(String msg) { 29 | super(msg); 30 | } 31 | 32 | public ZipException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public ZipException(String msg, int code) { 37 | super(msg); 38 | this.code = code; 39 | } 40 | 41 | public ZipException(String message, Throwable cause, int code) { 42 | super(message, cause); 43 | this.code = code; 44 | } 45 | 46 | public ZipException(Throwable cause) { 47 | super(cause); 48 | } 49 | 50 | public ZipException(Throwable cause, int code) { 51 | super(cause); 52 | this.code = code; 53 | } 54 | 55 | public int getCode() { 56 | return code; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/io/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.io 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.io

12 |
13 |

Classes

14 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/PBKDF2/PBKDF2HexFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.PBKDF2; 18 | 19 | /* 20 | * Source referred from Matthias Gartner's PKCS#5 implementation - 21 | * see http://rtner.de/software/PBKDF2.html 22 | */ 23 | 24 | class PBKDF2HexFormatter 25 | { 26 | public boolean fromString(PBKDF2Parameters p, String s) 27 | { 28 | if (p == null || s == null) 29 | { 30 | return true; 31 | } 32 | 33 | String[] p123 = s.split(":"); 34 | if (p123 == null || p123.length != 3) 35 | { 36 | return true; 37 | } 38 | 39 | byte salt[] = BinTools.hex2bin(p123[0]); 40 | int iterationCount = Integer.parseInt(p123[1]); 41 | byte bDK[] = BinTools.hex2bin(p123[2]); 42 | 43 | p.setSalt(salt); 44 | p.setIterationCount(iterationCount); 45 | p.setDerivedKey(bDK); 46 | return false; 47 | } 48 | 49 | public String toString(PBKDF2Parameters p) 50 | { 51 | String s = BinTools.bin2hex(p.getSalt()) + ":" 52 | + String.valueOf(p.getIterationCount()) + ":" 53 | + BinTools.bin2hex(p.getDerivedKey()); 54 | return s; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /docs/html/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview List 7 | 8 | 9 | 10 | 11 |
All Classes
12 |
13 |

Packages

14 | 27 |
28 |

 

29 | 30 | 31 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/Zip64EndCentralDirLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class Zip64EndCentralDirLocator { 20 | 21 | private long signature; 22 | 23 | private int noOfDiskStartOfZip64EndOfCentralDirRec; 24 | 25 | private long offsetZip64EndOfCentralDirRec; 26 | 27 | private int totNumberOfDiscs; 28 | 29 | public long getSignature() { 30 | return signature; 31 | } 32 | 33 | public void setSignature(long signature) { 34 | this.signature = signature; 35 | } 36 | 37 | public int getNoOfDiskStartOfZip64EndOfCentralDirRec() { 38 | return noOfDiskStartOfZip64EndOfCentralDirRec; 39 | } 40 | 41 | public void setNoOfDiskStartOfZip64EndOfCentralDirRec( 42 | int noOfDiskStartOfZip64EndOfCentralDirRec) { 43 | this.noOfDiskStartOfZip64EndOfCentralDirRec = noOfDiskStartOfZip64EndOfCentralDirRec; 44 | } 45 | 46 | public long getOffsetZip64EndOfCentralDirRec() { 47 | return offsetZip64EndOfCentralDirRec; 48 | } 49 | 50 | public void setOffsetZip64EndOfCentralDirRec(long offsetZip64EndOfCentralDirRec) { 51 | this.offsetZip64EndOfCentralDirRec = offsetZip64EndOfCentralDirRec; 52 | } 53 | 54 | public int getTotNumberOfDiscs() { 55 | return totNumberOfDiscs; 56 | } 57 | 58 | public void setTotNumberOfDiscs(int totNumberOfDiscs) { 59 | this.totNumberOfDiscs = totNumberOfDiscs; 60 | } 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/engine/ZipCryptoEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.engine; 18 | 19 | public class ZipCryptoEngine { 20 | 21 | private final int keys[] = new int[3]; 22 | private static final int[] CRC_TABLE = new int[256]; 23 | 24 | static { 25 | for (int i = 0; i < 256; i++) { 26 | int r = i; 27 | for (int j = 0; j < 8; j++) { 28 | if ((r & 1) == 1) { 29 | r = (r >>> 1) ^ 0xedb88320; 30 | } else { 31 | r >>>= 1; 32 | } 33 | } 34 | CRC_TABLE[i] = r; 35 | } 36 | } 37 | 38 | public ZipCryptoEngine() { 39 | } 40 | 41 | public void initKeys(char[] password) { 42 | keys[0] = 305419896; 43 | keys[1] = 591751049; 44 | keys[2] = 878082192; 45 | for (int i = 0; i < password.length; i++) { 46 | updateKeys((byte) (password[i] & 0xff)); 47 | } 48 | } 49 | 50 | public void updateKeys(byte charAt) { 51 | keys[0] = crc32(keys[0], charAt); 52 | keys[1] += keys[0] & 0xff; 53 | keys[1] = keys[1] * 134775813 + 1; 54 | keys[2] = crc32(keys[2], (byte) (keys[1] >> 24)); 55 | } 56 | 57 | private int crc32(int oldCrc, byte charAt) { 58 | return ((oldCrc >>> 8) ^ CRC_TABLE[(oldCrc ^ charAt) & 0xff]); 59 | } 60 | 61 | public byte decryptByte() { 62 | int temp = keys[2] | 2; 63 | return (byte) ((temp * (temp ^ 1)) >>> 8); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/Zip64ExtendedInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class Zip64ExtendedInfo { 20 | 21 | private int header; 22 | 23 | private int size; 24 | 25 | private long compressedSize; 26 | 27 | private long unCompressedSize; 28 | 29 | private long offsetLocalHeader; 30 | 31 | private int diskNumberStart; 32 | 33 | public Zip64ExtendedInfo() { 34 | compressedSize = -1; 35 | unCompressedSize = -1; 36 | offsetLocalHeader = -1; 37 | diskNumberStart = -1; 38 | } 39 | 40 | public int getHeader() { 41 | return header; 42 | } 43 | 44 | public void setHeader(int header) { 45 | this.header = header; 46 | } 47 | 48 | public int getSize() { 49 | return size; 50 | } 51 | 52 | public void setSize(int size) { 53 | this.size = size; 54 | } 55 | 56 | public long getCompressedSize() { 57 | return compressedSize; 58 | } 59 | 60 | public void setCompressedSize(long compressedSize) { 61 | this.compressedSize = compressedSize; 62 | } 63 | 64 | public long getUnCompressedSize() { 65 | return unCompressedSize; 66 | } 67 | 68 | public void setUnCompressedSize(long unCompressedSize) { 69 | this.unCompressedSize = unCompressedSize; 70 | } 71 | 72 | public long getOffsetLocalHeader() { 73 | return offsetLocalHeader; 74 | } 75 | 76 | public void setOffsetLocalHeader(long offsetLocalHeader) { 77 | this.offsetLocalHeader = offsetLocalHeader; 78 | } 79 | 80 | public int getDiskNumberStart() { 81 | return diskNumberStart; 82 | } 83 | 84 | public void setDiskNumberStart(int diskNumberStart) { 85 | this.diskNumberStart = diskNumberStart; 86 | } 87 | 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/AESExtraDataRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class AESExtraDataRecord { 20 | 21 | private long signature; 22 | private int dataSize; 23 | private int versionNumber; 24 | private String vendorID; 25 | private int aesStrength; 26 | private int compressionMethod; 27 | 28 | public AESExtraDataRecord() { 29 | signature = -1; 30 | dataSize = -1; 31 | versionNumber = -1; 32 | vendorID = null; 33 | aesStrength = -1; 34 | compressionMethod = -1; 35 | } 36 | 37 | 38 | public long getSignature() { 39 | return signature; 40 | } 41 | 42 | 43 | public void setSignature(long signature) { 44 | this.signature = signature; 45 | } 46 | 47 | 48 | public int getDataSize() { 49 | return dataSize; 50 | } 51 | 52 | 53 | public void setDataSize(int dataSize) { 54 | this.dataSize = dataSize; 55 | } 56 | 57 | 58 | public int getVersionNumber() { 59 | return versionNumber; 60 | } 61 | 62 | 63 | public void setVersionNumber(int versionNumber) { 64 | this.versionNumber = versionNumber; 65 | } 66 | 67 | 68 | public String getVendorID() { 69 | return vendorID; 70 | } 71 | 72 | 73 | public void setVendorID(String vendorID) { 74 | this.vendorID = vendorID; 75 | } 76 | 77 | 78 | public int getAesStrength() { 79 | return aesStrength; 80 | } 81 | 82 | 83 | public void setAesStrength(int aesStrength) { 84 | this.aesStrength = aesStrength; 85 | } 86 | 87 | 88 | public int getCompressionMethod() { 89 | return compressionMethod; 90 | } 91 | 92 | 93 | public void setCompressionMethod(int compressionMethod) { 94 | this.compressionMethod = compressionMethod; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/util/Zip4jConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.util; 18 | 19 | public interface Zip4jConstants { 20 | 21 | // Compression Types 22 | static final int COMP_STORE = 0; 23 | // static final int COMP_FILE_SHRUNK = 1; 24 | // static final int COMP_FILE_RED_COMP_FACTOR_1 = 2; 25 | // static final int COMP_FILE_RED_COMP_FACTOR_2 = 3; 26 | // static final int COMP_FILE_RED_COMP_FACTOR_3 = 4; 27 | // static final int COMP_FILE_RED_COMP_FACTOR_4 = 5; 28 | // static final int COMP_FILE_IMPLODED = 6; 29 | static final int COMP_DEFLATE = 8; 30 | // static final int COMP_FILE_ENHANCED_DEFLATED = 9; 31 | // static final int COMP_PKWARE_DATA_COMP_LIB_IMPL = 10; 32 | // static final int COMP_BZIP2 = 12; 33 | // static final int COMP_LZMA = 14; 34 | // static final int COMP_IBM_TERSE = 18; 35 | // static final int COMP_IBM_LZ77 =19; 36 | // static final int COMP_WAVPACK = 97; 37 | // static final int COMP_PPMD = 98; 38 | static final int COMP_AES_ENC = 99; 39 | 40 | //Compression level for deflate algorithm 41 | static final int DEFLATE_LEVEL_FASTEST = 1; 42 | static final int DEFLATE_LEVEL_FAST = 3; 43 | static final int DEFLATE_LEVEL_NORMAL = 5; 44 | static final int DEFLATE_LEVEL_MAXIMUM = 7; 45 | static final int DEFLATE_LEVEL_ULTRA = 9; 46 | 47 | //Encryption types 48 | static final int ENC_NO_ENCRYPTION = -1; 49 | static final int ENC_METHOD_STANDARD = 0; 50 | // static final int ENC_METHOD_STRONG = 1; 51 | static final int ENC_METHOD_AES = 99; 52 | 53 | //AES Key Strength 54 | static final int AES_STRENGTH_128 = 0x01; 55 | static final int AES_STRENGTH_192 = 0x02; 56 | static final int AES_STRENGTH_256 = 0x03; 57 | } 58 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/UnzipEngineParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | import java.io.FileOutputStream; 20 | 21 | import net.lingala.zip4j.crypto.IDecrypter; 22 | import net.lingala.zip4j.unzip.UnzipEngine; 23 | 24 | public class UnzipEngineParameters { 25 | 26 | private ZipModel zipModel; 27 | 28 | private FileHeader fileHeader; 29 | 30 | private LocalFileHeader localFileHeader; 31 | 32 | private IDecrypter iDecryptor; 33 | 34 | private FileOutputStream outputStream; 35 | 36 | private UnzipEngine unzipEngine; 37 | 38 | public ZipModel getZipModel() { 39 | return zipModel; 40 | } 41 | 42 | public void setZipModel(ZipModel zipModel) { 43 | this.zipModel = zipModel; 44 | } 45 | 46 | public FileHeader getFileHeader() { 47 | return fileHeader; 48 | } 49 | 50 | public void setFileHeader(FileHeader fileHeader) { 51 | this.fileHeader = fileHeader; 52 | } 53 | 54 | public LocalFileHeader getLocalFileHeader() { 55 | return localFileHeader; 56 | } 57 | 58 | public void setLocalFileHeader(LocalFileHeader localFileHeader) { 59 | this.localFileHeader = localFileHeader; 60 | } 61 | 62 | public IDecrypter getIDecryptor() { 63 | return iDecryptor; 64 | } 65 | 66 | public void setIDecryptor(IDecrypter decrypter) { 67 | iDecryptor = decrypter; 68 | } 69 | 70 | public FileOutputStream getOutputStream() { 71 | return outputStream; 72 | } 73 | 74 | public void setOutputStream(FileOutputStream outputStream) { 75 | this.outputStream = outputStream; 76 | } 77 | 78 | public UnzipEngine getUnzipEngine() { 79 | return unzipEngine; 80 | } 81 | 82 | public void setUnzipEngine(UnzipEngine unzipEngine) { 83 | this.unzipEngine = unzipEngine; 84 | } 85 | 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/ZipInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.io; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | import net.lingala.zip4j.exception.ZipException; 23 | 24 | public class ZipInputStream extends InputStream { 25 | 26 | private BaseInputStream is; 27 | 28 | public ZipInputStream(BaseInputStream is) { 29 | this.is = is; 30 | } 31 | 32 | public int read() throws IOException { 33 | int readByte = is.read(); 34 | if (readByte != -1) { 35 | is.getUnzipEngine().updateCRC(readByte); 36 | } 37 | return readByte; 38 | } 39 | 40 | public int read(byte[] b) throws IOException { 41 | return read(b, 0, b.length); 42 | } 43 | 44 | public int read(byte[] b, int off, int len) throws IOException { 45 | int readLen = is.read(b, off, len); 46 | if (readLen > 0 && is.getUnzipEngine() != null) { 47 | is.getUnzipEngine().updateCRC(b, off, readLen); 48 | } 49 | return readLen; 50 | } 51 | 52 | /** 53 | * Closes the input stream and releases any resources. 54 | * This method also checks for the CRC of the extracted file. 55 | * If CRC check has to be skipped use close(boolean skipCRCCheck) method 56 | * 57 | * @throws IOException 58 | */ 59 | public void close() throws IOException { 60 | close(false); 61 | } 62 | 63 | /** 64 | * Closes the input stream and releases any resources. 65 | * If skipCRCCheck flag is set to true, this method skips CRC Check 66 | * of the extracted file 67 | * 68 | * @throws IOException 69 | */ 70 | public void close(boolean skipCRCCheck) throws IOException { 71 | try { 72 | is.close(); 73 | if (!skipCRCCheck && is.getUnzipEngine() != null) { 74 | is.getUnzipEngine().checkCRC(); 75 | } 76 | } catch (ZipException e) { 77 | throw new IOException(e.getMessage()); 78 | } 79 | } 80 | 81 | public int available() throws IOException { 82 | return is.available(); 83 | } 84 | 85 | public long skip(long n) throws IOException { 86 | return is.skip(n); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/UnzipParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class UnzipParameters { 20 | 21 | private boolean ignoreReadOnlyFileAttribute; 22 | private boolean ignoreHiddenFileAttribute; 23 | private boolean ignoreArchiveFileAttribute; 24 | private boolean ignoreSystemFileAttribute; 25 | private boolean ignoreAllFileAttributes; 26 | private boolean ignoreDateTimeAttributes; 27 | 28 | public boolean isIgnoreReadOnlyFileAttribute() { 29 | return ignoreReadOnlyFileAttribute; 30 | } 31 | 32 | public void setIgnoreReadOnlyFileAttribute(boolean ignoreReadOnlyFileAttribute) { 33 | this.ignoreReadOnlyFileAttribute = ignoreReadOnlyFileAttribute; 34 | } 35 | 36 | public boolean isIgnoreHiddenFileAttribute() { 37 | return ignoreHiddenFileAttribute; 38 | } 39 | 40 | public void setIgnoreHiddenFileAttribute(boolean ignoreHiddenFileAttribute) { 41 | this.ignoreHiddenFileAttribute = ignoreHiddenFileAttribute; 42 | } 43 | 44 | public boolean isIgnoreArchiveFileAttribute() { 45 | return ignoreArchiveFileAttribute; 46 | } 47 | 48 | public void setIgnoreArchiveFileAttribute(boolean ignoreArchiveFileAttribute) { 49 | this.ignoreArchiveFileAttribute = ignoreArchiveFileAttribute; 50 | } 51 | 52 | public boolean isIgnoreSystemFileAttribute() { 53 | return ignoreSystemFileAttribute; 54 | } 55 | 56 | public void setIgnoreSystemFileAttribute(boolean ignoreSystemFileAttribute) { 57 | this.ignoreSystemFileAttribute = ignoreSystemFileAttribute; 58 | } 59 | 60 | public boolean isIgnoreAllFileAttributes() { 61 | return ignoreAllFileAttributes; 62 | } 63 | 64 | public void setIgnoreAllFileAttributes(boolean ignoreAllFileAttributes) { 65 | this.ignoreAllFileAttributes = ignoreAllFileAttributes; 66 | } 67 | 68 | public boolean isIgnoreDateTimeAttributes() { 69 | return ignoreDateTimeAttributes; 70 | } 71 | 72 | public void setIgnoreDateTimeAttributes(boolean ignoreDateTimeAttributes) { 73 | this.ignoreDateTimeAttributes = ignoreDateTimeAttributes; 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/model/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.model 7 | 8 | 9 | 10 | 11 |

net.lingala.zip4j.model

12 |
13 |

Classes

14 | 32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/PBKDF2/BinTools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.PBKDF2; 18 | 19 | /* 20 | * Source referred from Matthias Gartner's PKCS#5 implementation - 21 | * see http://rtner.de/software/PBKDF2.html 22 | */ 23 | 24 | class BinTools 25 | { 26 | public static final String hex = "0123456789ABCDEF"; 27 | 28 | public static String bin2hex(final byte[] b) 29 | { 30 | if (b == null) 31 | { 32 | return ""; 33 | } 34 | StringBuffer sb = new StringBuffer(2 * b.length); 35 | for (int i = 0; i < b.length; i++) 36 | { 37 | int v = (256 + b[i]) % 256; 38 | sb.append(hex.charAt((v / 16) & 15)); 39 | sb.append(hex.charAt((v % 16) & 15)); 40 | } 41 | return sb.toString(); 42 | } 43 | 44 | public static byte[] hex2bin(final String s) 45 | { 46 | String m = s; 47 | if (s == null) 48 | { 49 | // Allow empty input string. 50 | m = ""; 51 | } 52 | else if (s.length() % 2 != 0) 53 | { 54 | // Assume leading zero for odd string length 55 | m = "0" + s; 56 | } 57 | byte r[] = new byte[m.length() / 2]; 58 | for (int i = 0, n = 0; i < m.length(); n++) 59 | { 60 | char h = m.charAt(i++); 61 | char l = m.charAt(i++); 62 | r[n] = (byte) (hex2bin(h) * 16 + hex2bin(l)); 63 | } 64 | return r; 65 | } 66 | 67 | public static int hex2bin(char c) 68 | { 69 | if (c >= '0' && c <= '9') 70 | { 71 | return (c - '0'); 72 | } 73 | if (c >= 'A' && c <= 'F') 74 | { 75 | return (c - 'A' + 10); 76 | } 77 | if (c >= 'a' && c <= 'f') 78 | { 79 | return (c - 'a' + 10); 80 | } 81 | throw new IllegalArgumentException( 82 | "Input string may only contain hex digits, but found '" + c 83 | + "'"); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/util/CRCUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.util; 18 | 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.util.zip.CRC32; 24 | 25 | import net.lingala.zip4j.exception.ZipException; 26 | import net.lingala.zip4j.progress.ProgressMonitor; 27 | 28 | public class CRCUtil { 29 | 30 | private static final int BUF_SIZE = 1 << 14; //16384 31 | 32 | public static long computeFileCRC(String inputFile) throws ZipException { 33 | return computeFileCRC(inputFile, null); 34 | } 35 | 36 | /** 37 | * Calculates CRC of a file 38 | * @param inputFile - file for which crc has to be calculated 39 | * @return crc of the file 40 | * @throws ZipException 41 | */ 42 | public static long computeFileCRC(String inputFile, ProgressMonitor progressMonitor) throws ZipException { 43 | 44 | if (!Zip4jUtil.isStringNotNullAndNotEmpty(inputFile)) { 45 | throw new ZipException("input file is null or empty, cannot calculate CRC for the file"); 46 | } 47 | InputStream inputStream = null; 48 | try { 49 | Zip4jUtil.checkFileReadAccess(inputFile); 50 | 51 | inputStream = new FileInputStream(new File(inputFile)); 52 | 53 | byte[] buff = new byte[BUF_SIZE]; 54 | int readLen = -2; 55 | CRC32 crc32 = new CRC32(); 56 | 57 | while ((readLen = inputStream.read(buff)) != -1) { 58 | crc32.update(buff, 0, readLen); 59 | if (progressMonitor != null) { 60 | progressMonitor.updateWorkCompleted(readLen); 61 | if (progressMonitor.isCancelAllTasks()) { 62 | progressMonitor 63 | .setResult(ProgressMonitor.RESULT_CANCELLED); 64 | progressMonitor.setState(ProgressMonitor.STATE_READY); 65 | return 0; 66 | } 67 | } 68 | } 69 | 70 | return crc32.getValue(); 71 | } catch (IOException e) { 72 | throw new ZipException(e); 73 | } catch (Exception e) { 74 | throw new ZipException(e); 75 | } finally { 76 | if (inputStream != null) { 77 | try { 78 | inputStream.close(); 79 | } catch (IOException e) { 80 | throw new ZipException("error while closing the file after calculating crc"); 81 | } 82 | } 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /docs/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Generated Documentation (Untitled) 7 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | <noscript> 68 | <div>JavaScript is disabled on your browser.</div> 69 | </noscript> 70 | <h2>Frame Alert</h2> 71 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/PBKDF2/PBKDF2Parameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.PBKDF2; 18 | /* 19 | * Source referred from Matthias Gartner's PKCS#5 implementation - 20 | * see http://rtner.de/software/PBKDF2.html 21 | */ 22 | public class PBKDF2Parameters 23 | { 24 | protected byte[] salt; 25 | 26 | protected int iterationCount; 27 | 28 | protected String hashAlgorithm; 29 | 30 | protected String hashCharset; 31 | 32 | protected byte[] derivedKey; 33 | 34 | public PBKDF2Parameters() 35 | { 36 | this.hashAlgorithm = null; 37 | this.hashCharset = "UTF-8"; 38 | this.salt = null; 39 | this.iterationCount = 1000; 40 | this.derivedKey = null; 41 | } 42 | 43 | public PBKDF2Parameters(String hashAlgorithm, String hashCharset, 44 | byte[] salt, int iterationCount) 45 | { 46 | this.hashAlgorithm = hashAlgorithm; 47 | this.hashCharset = hashCharset; 48 | this.salt = salt; 49 | this.iterationCount = iterationCount; 50 | this.derivedKey = null; 51 | } 52 | 53 | public PBKDF2Parameters(String hashAlgorithm, String hashCharset, 54 | byte[] salt, int iterationCount, byte[] derivedKey) 55 | { 56 | this.hashAlgorithm = hashAlgorithm; 57 | this.hashCharset = hashCharset; 58 | this.salt = salt; 59 | this.iterationCount = iterationCount; 60 | this.derivedKey = derivedKey; 61 | } 62 | 63 | public int getIterationCount() 64 | { 65 | return iterationCount; 66 | } 67 | 68 | public void setIterationCount(int iterationCount) 69 | { 70 | this.iterationCount = iterationCount; 71 | } 72 | 73 | public byte[] getSalt() 74 | { 75 | return salt; 76 | } 77 | 78 | public void setSalt(byte[] salt) 79 | { 80 | this.salt = salt; 81 | } 82 | 83 | public byte[] getDerivedKey() 84 | { 85 | return derivedKey; 86 | } 87 | 88 | public void setDerivedKey(byte[] derivedKey) 89 | { 90 | this.derivedKey = derivedKey; 91 | } 92 | 93 | public String getHashAlgorithm() 94 | { 95 | return hashAlgorithm; 96 | } 97 | 98 | public void setHashAlgorithm(String hashAlgorithm) 99 | { 100 | this.hashAlgorithm = hashAlgorithm; 101 | } 102 | 103 | public String getHashCharset() 104 | { 105 | return hashCharset; 106 | } 107 | 108 | public void setHashCharset(String hashCharset) 109 | { 110 | this.hashCharset = hashCharset; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/PBKDF2/MacBasedPRF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.PBKDF2; 18 | 19 | import java.security.InvalidKeyException; 20 | import java.security.NoSuchAlgorithmException; 21 | import java.security.NoSuchProviderException; 22 | 23 | import javax.crypto.Mac; 24 | import javax.crypto.spec.SecretKeySpec; 25 | 26 | /* 27 | * Source referred from Matthias Gartner's PKCS#5 implementation - 28 | * see http://rtner.de/software/PBKDF2.html 29 | */ 30 | 31 | public class MacBasedPRF implements PRF 32 | { 33 | protected Mac mac; 34 | 35 | protected int hLen; 36 | 37 | protected String macAlgorithm; 38 | 39 | public MacBasedPRF(String macAlgorithm) 40 | { 41 | this.macAlgorithm = macAlgorithm; 42 | try 43 | { 44 | mac = Mac.getInstance(macAlgorithm); 45 | hLen = mac.getMacLength(); 46 | } 47 | catch (NoSuchAlgorithmException e) 48 | { 49 | throw new RuntimeException(e); 50 | } 51 | } 52 | 53 | public MacBasedPRF(String macAlgorithm, String provider) 54 | { 55 | this.macAlgorithm = macAlgorithm; 56 | try 57 | { 58 | mac = Mac.getInstance(macAlgorithm, provider); 59 | hLen = mac.getMacLength(); 60 | } 61 | catch (NoSuchAlgorithmException e) 62 | { 63 | throw new RuntimeException(e); 64 | } 65 | catch (NoSuchProviderException e) 66 | { 67 | throw new RuntimeException(e); 68 | } 69 | } 70 | 71 | public byte[] doFinal(byte[] M) 72 | { 73 | byte[] r = mac.doFinal(M); 74 | return r; 75 | } 76 | 77 | public byte[] doFinal() { 78 | byte[] r = mac.doFinal(); 79 | return r; 80 | } 81 | 82 | public int getHLen() 83 | { 84 | return hLen; 85 | } 86 | 87 | public void init(byte[] P) 88 | { 89 | try 90 | { 91 | mac.init(new SecretKeySpec(P, macAlgorithm)); 92 | } 93 | catch (InvalidKeyException e) 94 | { 95 | throw new RuntimeException(e); 96 | } 97 | } 98 | 99 | public void update(byte[] U) { 100 | 101 | try { 102 | mac.update(U); 103 | } catch (IllegalStateException e) { 104 | throw new RuntimeException(e); 105 | } 106 | 107 | } 108 | 109 | public void update (byte[] U, int start, int len) { 110 | try { 111 | mac.update(U, start, len); 112 | } catch (IllegalStateException e) { 113 | throw new RuntimeException(e); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/EndCentralDirRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class EndCentralDirRecord { 20 | 21 | private long signature; 22 | 23 | private int noOfThisDisk; 24 | 25 | private int noOfThisDiskStartOfCentralDir; 26 | 27 | private int totNoOfEntriesInCentralDirOnThisDisk; 28 | 29 | private int totNoOfEntriesInCentralDir; 30 | 31 | private int sizeOfCentralDir; 32 | 33 | private long offsetOfStartOfCentralDir; 34 | 35 | private int commentLength; 36 | 37 | private String comment; 38 | 39 | private byte[] commentBytes; 40 | 41 | public long getSignature() { 42 | return signature; 43 | } 44 | 45 | public void setSignature(long signature) { 46 | this.signature = signature; 47 | } 48 | 49 | public int getNoOfThisDisk() { 50 | return noOfThisDisk; 51 | } 52 | 53 | public void setNoOfThisDisk(int noOfThisDisk) { 54 | this.noOfThisDisk = noOfThisDisk; 55 | } 56 | 57 | public int getNoOfThisDiskStartOfCentralDir() { 58 | return noOfThisDiskStartOfCentralDir; 59 | } 60 | 61 | public void setNoOfThisDiskStartOfCentralDir(int noOfThisDiskStartOfCentralDir) { 62 | this.noOfThisDiskStartOfCentralDir = noOfThisDiskStartOfCentralDir; 63 | } 64 | 65 | public int getTotNoOfEntriesInCentralDirOnThisDisk() { 66 | return totNoOfEntriesInCentralDirOnThisDisk; 67 | } 68 | 69 | public void setTotNoOfEntriesInCentralDirOnThisDisk( 70 | int totNoOfEntriesInCentralDirOnThisDisk) { 71 | this.totNoOfEntriesInCentralDirOnThisDisk = totNoOfEntriesInCentralDirOnThisDisk; 72 | } 73 | 74 | public int getTotNoOfEntriesInCentralDir() { 75 | return totNoOfEntriesInCentralDir; 76 | } 77 | 78 | public void setTotNoOfEntriesInCentralDir(int totNoOfEntrisInCentralDir) { 79 | this.totNoOfEntriesInCentralDir = totNoOfEntrisInCentralDir; 80 | } 81 | 82 | public int getSizeOfCentralDir() { 83 | return sizeOfCentralDir; 84 | } 85 | 86 | public void setSizeOfCentralDir(int sizeOfCentralDir) { 87 | this.sizeOfCentralDir = sizeOfCentralDir; 88 | } 89 | 90 | public long getOffsetOfStartOfCentralDir() { 91 | return offsetOfStartOfCentralDir; 92 | } 93 | 94 | public void setOffsetOfStartOfCentralDir(long offSetOfStartOfCentralDir) { 95 | this.offsetOfStartOfCentralDir = offSetOfStartOfCentralDir; 96 | } 97 | 98 | public int getCommentLength() { 99 | return commentLength; 100 | } 101 | 102 | public void setCommentLength(int commentLength) { 103 | this.commentLength = commentLength; 104 | } 105 | 106 | public String getComment() { 107 | return comment; 108 | } 109 | 110 | public void setComment(String comment) { 111 | this.comment = comment; 112 | } 113 | 114 | public byte[] getCommentBytes() { 115 | return commentBytes; 116 | } 117 | 118 | public void setCommentBytes(byte[] commentBytes) { 119 | this.commentBytes = commentBytes; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /docs/html/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Deprecated API

66 |

Contents

67 |
68 | 69 |
70 | 71 | 72 | 73 | 74 | 83 |
84 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/DeflaterOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.io; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | import java.util.zip.Deflater; 23 | 24 | import net.lingala.zip4j.exception.ZipException; 25 | import net.lingala.zip4j.model.ZipModel; 26 | import net.lingala.zip4j.model.ZipParameters; 27 | import net.lingala.zip4j.util.InternalZipConstants; 28 | import net.lingala.zip4j.util.Zip4jConstants; 29 | 30 | public class DeflaterOutputStream extends CipherOutputStream { 31 | 32 | private byte[] buff; 33 | protected Deflater deflater; 34 | private boolean firstBytesRead; 35 | 36 | public DeflaterOutputStream(OutputStream outputStream, ZipModel zipModel) { 37 | super(outputStream, zipModel); 38 | deflater = new Deflater(); 39 | buff = new byte[InternalZipConstants.BUFF_SIZE]; 40 | firstBytesRead = false; 41 | } 42 | 43 | public void putNextEntry(File file, ZipParameters zipParameters) 44 | throws ZipException { 45 | super.putNextEntry(file, zipParameters); 46 | if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) { 47 | deflater.reset(); 48 | if ((zipParameters.getCompressionLevel() < 0 || zipParameters 49 | .getCompressionLevel() > 9) 50 | && zipParameters.getCompressionLevel() != -1) { 51 | throw new ZipException( 52 | "invalid compression level for deflater. compression level should be in the range of 0-9"); 53 | } 54 | deflater.setLevel(zipParameters.getCompressionLevel()); 55 | } 56 | } 57 | 58 | public void write(byte[] b) throws IOException { 59 | write(b, 0, b.length); 60 | } 61 | 62 | private void deflate () throws IOException { 63 | int len = deflater.deflate(buff, 0, buff.length); 64 | if (len > 0) { 65 | if (deflater.finished()) { 66 | if (len == 4) return; 67 | if (len < 4) { 68 | decrementCompressedFileSize(4 - len); 69 | return; 70 | } 71 | len -= 4; 72 | } 73 | if (!firstBytesRead) { 74 | super.write(buff, 2, len - 2); 75 | firstBytesRead = true; 76 | } else { 77 | super.write(buff, 0, len); 78 | } 79 | } 80 | } 81 | 82 | public void write(int bval) throws IOException { 83 | byte[] b = new byte[1]; 84 | b[0] = (byte) bval; 85 | write(b, 0, 1); 86 | } 87 | 88 | public void write(byte[] buf, int off, int len) throws IOException { 89 | if (zipParameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) { 90 | super.write(buf, off, len); 91 | } else { 92 | deflater.setInput(buf, off, len); 93 | while (!deflater.needsInput()) { 94 | deflate(); 95 | } 96 | } 97 | } 98 | 99 | public void closeEntry() throws IOException, ZipException { 100 | if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) { 101 | if (!deflater.finished()) { 102 | deflater.finish(); 103 | while (!deflater.finished()) { 104 | deflate(); 105 | } 106 | } 107 | firstBytesRead = false; 108 | } 109 | super.closeEntry(); 110 | } 111 | 112 | public void finish() throws IOException, ZipException { 113 | super.finish(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/StandardDecrypter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto; 18 | 19 | import net.lingala.zip4j.crypto.engine.ZipCryptoEngine; 20 | import net.lingala.zip4j.exception.ZipException; 21 | import net.lingala.zip4j.exception.ZipExceptionConstants; 22 | import net.lingala.zip4j.model.FileHeader; 23 | import net.lingala.zip4j.util.InternalZipConstants; 24 | 25 | public class StandardDecrypter implements IDecrypter { 26 | 27 | private FileHeader fileHeader; 28 | private byte[] crc = new byte[4]; 29 | private ZipCryptoEngine zipCryptoEngine; 30 | 31 | public StandardDecrypter(FileHeader fileHeader, byte[] headerBytes) throws ZipException{ 32 | if (fileHeader == null) { 33 | throw new ZipException("one of more of the input parameters were null in StandardDecryptor"); 34 | } 35 | 36 | this.fileHeader = fileHeader; 37 | this.zipCryptoEngine = new ZipCryptoEngine(); 38 | init(headerBytes); 39 | } 40 | 41 | public int decryptData(byte[] buff) throws ZipException { 42 | return decryptData(buff, 0, buff.length); 43 | } 44 | 45 | public int decryptData(byte[] buff, int start, int len) throws ZipException { 46 | if (start < 0 || len < 0) { 47 | throw new ZipException("one of the input parameters were null in standard decrpyt data"); 48 | } 49 | 50 | try { 51 | for (int i = 0; i < len; i++) { 52 | int val = buff[i] & 0xff; 53 | val = (val ^ zipCryptoEngine.decryptByte()) & 0xff; 54 | zipCryptoEngine.updateKeys((byte) val); 55 | buff[i] = (byte)val; 56 | } 57 | return len; 58 | } catch (Exception e) { 59 | throw new ZipException(e); 60 | } 61 | } 62 | 63 | public void init(byte[] headerBytes) throws ZipException { 64 | byte[] crcBuff = fileHeader.getCrcBuff(); 65 | crc[3] = (byte) (crcBuff[3] & 0xFF); 66 | crc[2] = (byte) ((crcBuff[3] >> 8) & 0xFF); 67 | crc[1] = (byte) ((crcBuff[3] >> 16) & 0xFF); 68 | crc[0] = (byte) ((crcBuff[3] >> 24) & 0xFF); 69 | 70 | if(crc[2] > 0 || crc[1] > 0 || crc[0] > 0) 71 | throw new IllegalStateException("Invalid CRC in File Header"); 72 | 73 | if (fileHeader.getPassword() == null || fileHeader.getPassword().length <= 0) { 74 | throw new ZipException("Wrong password!", ZipExceptionConstants.WRONG_PASSWORD); 75 | } 76 | 77 | zipCryptoEngine.initKeys(fileHeader.getPassword()); 78 | 79 | try { 80 | int result = headerBytes[0]; 81 | for (int i = 0; i < InternalZipConstants.STD_DEC_HDR_SIZE; i++) { 82 | // Commented this as this check cannot always be trusted 83 | // New functionality: If there is an error in extracting a password protected file, 84 | // "Wrong Password?" text is appended to the exception message 85 | // if(i+1 == InternalZipConstants.STD_DEC_HDR_SIZE && ((byte)(result ^ zipCryptoEngine.decryptByte()) != crc[3]) && !isSplit) 86 | // throw new ZipException("Wrong password!", ZipExceptionConstants.WRONG_PASSWORD); 87 | 88 | zipCryptoEngine.updateKeys((byte) (result ^ zipCryptoEngine.decryptByte())); 89 | if (i+1 != InternalZipConstants.STD_DEC_HDR_SIZE) 90 | result = headerBytes[i+1]; 91 | } 92 | } catch (Exception e) { 93 | throw new ZipException(e); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/Zip64EndCentralDirRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | public class Zip64EndCentralDirRecord { 20 | 21 | private long signature; 22 | 23 | private long sizeOfZip64EndCentralDirRec; 24 | 25 | private int versionMadeBy; 26 | 27 | private int versionNeededToExtract; 28 | 29 | private int noOfThisDisk; 30 | 31 | private int noOfThisDiskStartOfCentralDir; 32 | 33 | private long totNoOfEntriesInCentralDirOnThisDisk; 34 | 35 | private long totNoOfEntriesInCentralDir; 36 | 37 | private long sizeOfCentralDir; 38 | 39 | private long offsetStartCenDirWRTStartDiskNo; 40 | 41 | private byte[] extensibleDataSector; 42 | 43 | public long getSignature() { 44 | return signature; 45 | } 46 | 47 | public void setSignature(long signature) { 48 | this.signature = signature; 49 | } 50 | 51 | public long getSizeOfZip64EndCentralDirRec() { 52 | return sizeOfZip64EndCentralDirRec; 53 | } 54 | 55 | public void setSizeOfZip64EndCentralDirRec(long sizeOfZip64EndCentralDirRec) { 56 | this.sizeOfZip64EndCentralDirRec = sizeOfZip64EndCentralDirRec; 57 | } 58 | 59 | public int getVersionMadeBy() { 60 | return versionMadeBy; 61 | } 62 | 63 | public void setVersionMadeBy(int versionMadeBy) { 64 | this.versionMadeBy = versionMadeBy; 65 | } 66 | 67 | public int getVersionNeededToExtract() { 68 | return versionNeededToExtract; 69 | } 70 | 71 | public void setVersionNeededToExtract(int versionNeededToExtract) { 72 | this.versionNeededToExtract = versionNeededToExtract; 73 | } 74 | 75 | public int getNoOfThisDisk() { 76 | return noOfThisDisk; 77 | } 78 | 79 | public void setNoOfThisDisk(int noOfThisDisk) { 80 | this.noOfThisDisk = noOfThisDisk; 81 | } 82 | 83 | public int getNoOfThisDiskStartOfCentralDir() { 84 | return noOfThisDiskStartOfCentralDir; 85 | } 86 | 87 | public void setNoOfThisDiskStartOfCentralDir(int noOfThisDiskStartOfCentralDir) { 88 | this.noOfThisDiskStartOfCentralDir = noOfThisDiskStartOfCentralDir; 89 | } 90 | 91 | public long getTotNoOfEntriesInCentralDirOnThisDisk() { 92 | return totNoOfEntriesInCentralDirOnThisDisk; 93 | } 94 | 95 | public void setTotNoOfEntriesInCentralDirOnThisDisk( 96 | long totNoOfEntriesInCentralDirOnThisDisk) { 97 | this.totNoOfEntriesInCentralDirOnThisDisk = totNoOfEntriesInCentralDirOnThisDisk; 98 | } 99 | 100 | public long getTotNoOfEntriesInCentralDir() { 101 | return totNoOfEntriesInCentralDir; 102 | } 103 | 104 | public void setTotNoOfEntriesInCentralDir(long totNoOfEntriesInCentralDir) { 105 | this.totNoOfEntriesInCentralDir = totNoOfEntriesInCentralDir; 106 | } 107 | 108 | public long getSizeOfCentralDir() { 109 | return sizeOfCentralDir; 110 | } 111 | 112 | public void setSizeOfCentralDir(long sizeOfCentralDir) { 113 | this.sizeOfCentralDir = sizeOfCentralDir; 114 | } 115 | 116 | public long getOffsetStartCenDirWRTStartDiskNo() { 117 | return offsetStartCenDirWRTStartDiskNo; 118 | } 119 | 120 | public void setOffsetStartCenDirWRTStartDiskNo( 121 | long offsetStartCenDirWRTStartDiskNo) { 122 | this.offsetStartCenDirWRTStartDiskNo = offsetStartCenDirWRTStartDiskNo; 123 | } 124 | 125 | public byte[] getExtensibleDataSector() { 126 | return extensibleDataSector; 127 | } 128 | 129 | public void setExtensibleDataSector(byte[] extensibleDataSector) { 130 | this.extensibleDataSector = extensibleDataSector; 131 | } 132 | 133 | 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/unzip/UnzipUtil.java: -------------------------------------------------------------------------------- 1 | package net.lingala.zip4j.unzip; 2 | 3 | import java.io.File; 4 | 5 | import net.lingala.zip4j.exception.ZipException; 6 | import net.lingala.zip4j.model.FileHeader; 7 | import net.lingala.zip4j.model.UnzipParameters; 8 | import net.lingala.zip4j.util.InternalZipConstants; 9 | import net.lingala.zip4j.util.Zip4jUtil; 10 | 11 | public class UnzipUtil { 12 | 13 | public static void applyFileAttributes(FileHeader fileHeader, File file) throws ZipException { 14 | applyFileAttributes(fileHeader, file, null); 15 | } 16 | 17 | public static void applyFileAttributes(FileHeader fileHeader, File file, 18 | UnzipParameters unzipParameters) throws ZipException{ 19 | 20 | if (fileHeader == null) { 21 | throw new ZipException("cannot set file properties: file header is null"); 22 | } 23 | 24 | if (file == null) { 25 | throw new ZipException("cannot set file properties: output file is null"); 26 | } 27 | 28 | if (!Zip4jUtil.checkFileExists(file)) { 29 | throw new ZipException("cannot set file properties: file doesnot exist"); 30 | } 31 | 32 | if (unzipParameters == null || !unzipParameters.isIgnoreDateTimeAttributes()) { 33 | setFileLastModifiedTime(fileHeader, file); 34 | } 35 | 36 | if (unzipParameters == null) { 37 | setFileAttributes(fileHeader, file, true, true, true, true); 38 | } else { 39 | if (unzipParameters.isIgnoreAllFileAttributes()) { 40 | setFileAttributes(fileHeader, file, false, false, false, false); 41 | } else { 42 | setFileAttributes(fileHeader, file, !unzipParameters.isIgnoreReadOnlyFileAttribute(), 43 | !unzipParameters.isIgnoreHiddenFileAttribute(), 44 | !unzipParameters.isIgnoreArchiveFileAttribute(), 45 | !unzipParameters.isIgnoreSystemFileAttribute()); 46 | } 47 | } 48 | } 49 | 50 | private static void setFileAttributes(FileHeader fileHeader, File file, boolean setReadOnly, 51 | boolean setHidden, boolean setArchive, boolean setSystem) throws ZipException { 52 | if (fileHeader == null) { 53 | throw new ZipException("invalid file header. cannot set file attributes"); 54 | } 55 | 56 | byte[] externalAttrbs = fileHeader.getExternalFileAttr(); 57 | if (externalAttrbs == null) { 58 | return; 59 | } 60 | 61 | int atrrib = externalAttrbs[0]; 62 | switch (atrrib) { 63 | case InternalZipConstants.FILE_MODE_READ_ONLY: 64 | if (setReadOnly) Zip4jUtil.setFileReadOnly(file); 65 | break; 66 | case InternalZipConstants.FILE_MODE_HIDDEN: 67 | case InternalZipConstants.FOLDER_MODE_HIDDEN: 68 | if (setHidden) Zip4jUtil.setFileHidden(file); 69 | break; 70 | case InternalZipConstants.FILE_MODE_ARCHIVE: 71 | case InternalZipConstants.FOLDER_MODE_ARCHIVE: 72 | if (setArchive) Zip4jUtil.setFileArchive(file); 73 | break; 74 | case InternalZipConstants.FILE_MODE_READ_ONLY_HIDDEN: 75 | if (setReadOnly) Zip4jUtil.setFileReadOnly(file); 76 | if (setHidden) Zip4jUtil.setFileHidden(file); 77 | break; 78 | case InternalZipConstants.FILE_MODE_READ_ONLY_ARCHIVE: 79 | if (setArchive) Zip4jUtil.setFileArchive(file); 80 | if (setReadOnly) Zip4jUtil.setFileReadOnly(file); 81 | break; 82 | case InternalZipConstants.FILE_MODE_HIDDEN_ARCHIVE: 83 | case InternalZipConstants.FOLDER_MODE_HIDDEN_ARCHIVE: 84 | if (setArchive) Zip4jUtil.setFileArchive(file); 85 | if (setHidden) Zip4jUtil.setFileHidden(file); 86 | break; 87 | case InternalZipConstants.FILE_MODE_READ_ONLY_HIDDEN_ARCHIVE: 88 | if (setArchive) Zip4jUtil.setFileArchive(file); 89 | if (setReadOnly) Zip4jUtil.setFileReadOnly(file); 90 | if (setHidden) Zip4jUtil.setFileHidden(file); 91 | break; 92 | case InternalZipConstants.FILE_MODE_SYSTEM: 93 | if (setReadOnly) Zip4jUtil.setFileReadOnly(file); 94 | if (setHidden) Zip4jUtil.setFileHidden(file); 95 | if (setSystem) Zip4jUtil.setFileSystemMode(file); 96 | break; 97 | default: 98 | //do nothing 99 | break; 100 | } 101 | } 102 | 103 | private static void setFileLastModifiedTime(FileHeader fileHeader, File file) throws ZipException { 104 | if (fileHeader.getLastModFileTime() <= 0) { 105 | return; 106 | } 107 | 108 | if (file.exists()) { 109 | file.setLastModified(Zip4jUtil.dosToJavaTme(fileHeader.getLastModFileTime())); 110 | } 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/StandardEncrypter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto; 18 | 19 | import java.util.Random; 20 | 21 | import net.lingala.zip4j.crypto.engine.ZipCryptoEngine; 22 | import net.lingala.zip4j.exception.ZipException; 23 | import net.lingala.zip4j.util.InternalZipConstants; 24 | 25 | public class StandardEncrypter implements IEncrypter { 26 | 27 | private ZipCryptoEngine zipCryptoEngine; 28 | private byte[] headerBytes; 29 | 30 | public StandardEncrypter(char[] password, int crc) throws ZipException { 31 | if (password == null || password.length <= 0) { 32 | throw new ZipException("input password is null or empty in standard encrpyter constructor"); 33 | } 34 | 35 | this.zipCryptoEngine = new ZipCryptoEngine(); 36 | 37 | this.headerBytes = new byte[InternalZipConstants.STD_DEC_HDR_SIZE]; 38 | init(password, crc); 39 | } 40 | 41 | private void init(char[] password, int crc) throws ZipException { 42 | if (password == null || password.length <= 0) { 43 | throw new ZipException("input password is null or empty, cannot initialize standard encrypter"); 44 | } 45 | zipCryptoEngine.initKeys(password); 46 | headerBytes = generateRandomBytes(InternalZipConstants.STD_DEC_HDR_SIZE); 47 | // Initialize again since the generated bytes were encrypted. 48 | zipCryptoEngine.initKeys(password); 49 | 50 | headerBytes[InternalZipConstants.STD_DEC_HDR_SIZE - 1] = (byte)((crc >>> 24)); 51 | headerBytes[InternalZipConstants.STD_DEC_HDR_SIZE - 2] = (byte)((crc >>> 16)); 52 | 53 | if (headerBytes.length < InternalZipConstants.STD_DEC_HDR_SIZE) { 54 | throw new ZipException("invalid header bytes generated, cannot perform standard encryption"); 55 | } 56 | 57 | encryptData(headerBytes); 58 | } 59 | 60 | public int encryptData(byte[] buff) throws ZipException { 61 | if (buff == null) { 62 | throw new NullPointerException(); 63 | } 64 | return encryptData(buff, 0, buff.length); 65 | } 66 | 67 | public int encryptData(byte[] buff, int start, int len) throws ZipException { 68 | 69 | if (len < 0) { 70 | throw new ZipException("invalid length specified to decrpyt data"); 71 | } 72 | 73 | try { 74 | for (int i = start; i < start + len; i++) { 75 | buff[i] = encryptByte(buff[i]); 76 | } 77 | return len; 78 | } catch (Exception e) { 79 | throw new ZipException(e); 80 | } 81 | } 82 | 83 | protected byte encryptByte(byte val) { 84 | byte temp_val = (byte) (val ^ zipCryptoEngine.decryptByte() & 0xff); 85 | zipCryptoEngine.updateKeys(val); 86 | return temp_val; 87 | } 88 | 89 | protected byte[] generateRandomBytes(int size) throws ZipException { 90 | 91 | if (size <= 0) { 92 | throw new ZipException("size is either 0 or less than 0, cannot generate header for standard encryptor"); 93 | } 94 | 95 | byte[] buff = new byte[size]; 96 | 97 | Random rand = new Random(); 98 | 99 | for (int i = 0; i < buff.length; i ++) { 100 | // Encrypted to get less predictability for poorly implemented 101 | // rand functions. 102 | buff[i] = encryptByte((byte) rand.nextInt(256)); 103 | } 104 | 105 | // buff[0] = (byte)87; 106 | // buff[1] = (byte)176; 107 | // buff[2] = (byte)-49; 108 | // buff[3] = (byte)-43; 109 | // buff[4] = (byte)93; 110 | // buff[5] = (byte)-204; 111 | // buff[6] = (byte)-105; 112 | // buff[7] = (byte)213; 113 | // buff[8] = (byte)-80; 114 | // buff[9] = (byte)-8; 115 | // buff[10] = (byte)21; 116 | // buff[11] = (byte)242; 117 | 118 | // for( int j=0; j<2; j++ ) { 119 | // Random rand = new Random(); 120 | // int i = rand.nextInt(); 121 | // buff[0+j*4] = (byte)(i>>24); 122 | // buff[1+j*4] = (byte)(i>>16); 123 | // buff[2+j*4] = (byte)(i>>8); 124 | // buff[3+j*4] = (byte)i; 125 | // } 126 | return buff; 127 | } 128 | 129 | public byte[] getHeaderBytes() { 130 | return headerBytes; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /docs/html/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Serialized Form 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Serialized Form

66 |
67 |
68 | 97 |
98 | 99 |
100 | 101 | 102 | 103 | 104 | 113 |
114 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/zip/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.zip Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.zip

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 80 |
81 | 82 |
83 | 84 | 85 | 86 | 87 | 96 |
97 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/progress/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.progress Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.progress

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 80 |
81 | 82 |
83 | 84 | 85 | 86 | 87 | 96 |
97 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/zip/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.zip 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.zip

66 |
67 |
68 | 85 |
86 | 87 |
88 | 89 | 90 | 91 | 92 | 101 |
102 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/progress/ProgressMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.progress; 18 | 19 | import net.lingala.zip4j.exception.ZipException; 20 | 21 | /** 22 | * If Zip4j is set to run in thread mode, this class helps retrieve current progress 23 | * 24 | */ 25 | public class ProgressMonitor { 26 | 27 | private int state; 28 | private long totalWork; 29 | private long workCompleted; 30 | private int percentDone; 31 | private int currentOperation; 32 | private String fileName; 33 | private int result; 34 | private Throwable exception; 35 | private boolean cancelAllTasks; 36 | private boolean pause; 37 | 38 | //Progress monitor States 39 | public static final int STATE_READY = 0; 40 | public static final int STATE_BUSY = 1; 41 | 42 | //Progress monitor result codes 43 | public static final int RESULT_SUCCESS = 0; 44 | public static final int RESULT_WORKING = 1; 45 | public static final int RESULT_ERROR = 2; 46 | public static final int RESULT_CANCELLED = 3; 47 | 48 | //Operation Types 49 | public static final int OPERATION_NONE = -1; 50 | public static final int OPERATION_ADD = 0; 51 | public static final int OPERATION_EXTRACT = 1; 52 | public static final int OPERATION_REMOVE = 2; 53 | public static final int OPERATION_CALC_CRC = 3; 54 | public static final int OPERATION_MERGE = 4; 55 | 56 | public ProgressMonitor() { 57 | reset(); 58 | percentDone = 0; 59 | } 60 | 61 | public int getState() { 62 | return state; 63 | } 64 | 65 | public void setState(int state) { 66 | this.state = state; 67 | } 68 | 69 | public long getTotalWork() { 70 | return totalWork; 71 | } 72 | 73 | public void setTotalWork(long totalWork) { 74 | this.totalWork = totalWork; 75 | } 76 | 77 | public long getWorkCompleted() { 78 | return workCompleted; 79 | } 80 | 81 | public void updateWorkCompleted(long workCompleted) { 82 | this.workCompleted += workCompleted; 83 | percentDone = (int)((this.workCompleted*100/totalWork)); 84 | if (percentDone > 100) { 85 | percentDone = 100; 86 | } 87 | while (pause) { 88 | try { 89 | Thread.sleep(150); 90 | } catch (InterruptedException e) { 91 | //Do nothing 92 | } 93 | } 94 | } 95 | 96 | public int getPercentDone() { 97 | return percentDone; 98 | } 99 | 100 | public void setPercentDone(int percentDone) { 101 | this.percentDone = percentDone; 102 | } 103 | 104 | public int getResult() { 105 | return result; 106 | } 107 | 108 | public void setResult(int result) { 109 | this.result = result; 110 | } 111 | 112 | public String getFileName() { 113 | return fileName; 114 | } 115 | 116 | public void setFileName(String fileName) { 117 | this.fileName = fileName; 118 | } 119 | 120 | public int getCurrentOperation() { 121 | return currentOperation; 122 | } 123 | 124 | public void setCurrentOperation(int currentOperation) { 125 | this.currentOperation = currentOperation; 126 | } 127 | 128 | public Throwable getException() { 129 | return exception; 130 | } 131 | 132 | public void setException(Throwable exception) { 133 | this.exception = exception; 134 | } 135 | 136 | public void endProgressMonitorSuccess() throws ZipException { 137 | reset(); 138 | result = ProgressMonitor.RESULT_SUCCESS; 139 | } 140 | 141 | public void endProgressMonitorError(Throwable e) throws ZipException { 142 | reset(); 143 | result = ProgressMonitor.RESULT_ERROR; 144 | exception = e; 145 | } 146 | 147 | public void reset() { 148 | currentOperation = OPERATION_NONE; 149 | state = STATE_READY; 150 | fileName = null; 151 | totalWork = 0; 152 | workCompleted = 0; 153 | } 154 | 155 | public void fullReset() { 156 | reset(); 157 | exception = null; 158 | result = RESULT_SUCCESS; 159 | percentDone = 0; 160 | } 161 | 162 | public boolean isCancelAllTasks() { 163 | return cancelAllTasks; 164 | } 165 | 166 | public void cancelAllTasks() { 167 | this.cancelAllTasks = true; 168 | } 169 | 170 | public boolean isPause() { 171 | return pause; 172 | } 173 | 174 | public void setPause(boolean pause) { 175 | this.pause = pause; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/core/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.core Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.core

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 82 |
83 | 84 |
85 | 86 | 87 | 88 | 89 | 98 |
99 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/model/ZipModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.model; 18 | 19 | import java.util.List; 20 | 21 | public class ZipModel implements Cloneable { 22 | 23 | private List localFileHeaderList; 24 | 25 | private List dataDescriptorList; 26 | 27 | private ArchiveExtraDataRecord archiveExtraDataRecord; 28 | 29 | private CentralDirectory centralDirectory; 30 | 31 | private EndCentralDirRecord endCentralDirRecord; 32 | 33 | private Zip64EndCentralDirLocator zip64EndCentralDirLocator; 34 | 35 | private Zip64EndCentralDirRecord zip64EndCentralDirRecord; 36 | 37 | private boolean splitArchive; 38 | 39 | private long splitLength; 40 | 41 | private String zipFile; 42 | 43 | private boolean isZip64Format; 44 | 45 | private boolean isNestedZipFile; 46 | 47 | private long start; 48 | 49 | private long end; 50 | 51 | private String fileNameCharset; 52 | 53 | public ZipModel() { 54 | splitLength = -1; 55 | } 56 | 57 | public List getLocalFileHeaderList() { 58 | return localFileHeaderList; 59 | } 60 | 61 | public void setLocalFileHeaderList(List localFileHeaderList) { 62 | this.localFileHeaderList = localFileHeaderList; 63 | } 64 | 65 | public List getDataDescriptorList() { 66 | return dataDescriptorList; 67 | } 68 | 69 | public void setDataDescriptorList(List dataDescriptorList) { 70 | this.dataDescriptorList = dataDescriptorList; 71 | } 72 | 73 | public CentralDirectory getCentralDirectory() { 74 | return centralDirectory; 75 | } 76 | 77 | public void setCentralDirectory(CentralDirectory centralDirectory) { 78 | this.centralDirectory = centralDirectory; 79 | } 80 | 81 | public EndCentralDirRecord getEndCentralDirRecord() { 82 | return endCentralDirRecord; 83 | } 84 | 85 | public void setEndCentralDirRecord(EndCentralDirRecord endCentralDirRecord) { 86 | this.endCentralDirRecord = endCentralDirRecord; 87 | } 88 | 89 | public ArchiveExtraDataRecord getArchiveExtraDataRecord() { 90 | return archiveExtraDataRecord; 91 | } 92 | 93 | public void setArchiveExtraDataRecord( 94 | ArchiveExtraDataRecord archiveExtraDataRecord) { 95 | this.archiveExtraDataRecord = archiveExtraDataRecord; 96 | } 97 | 98 | public boolean isSplitArchive() { 99 | return splitArchive; 100 | } 101 | 102 | public void setSplitArchive(boolean splitArchive) { 103 | this.splitArchive = splitArchive; 104 | } 105 | 106 | public String getZipFile() { 107 | return zipFile; 108 | } 109 | 110 | public void setZipFile(String zipFile) { 111 | this.zipFile = zipFile; 112 | } 113 | 114 | public Zip64EndCentralDirLocator getZip64EndCentralDirLocator() { 115 | return zip64EndCentralDirLocator; 116 | } 117 | 118 | public void setZip64EndCentralDirLocator( 119 | Zip64EndCentralDirLocator zip64EndCentralDirLocator) { 120 | this.zip64EndCentralDirLocator = zip64EndCentralDirLocator; 121 | } 122 | 123 | public Zip64EndCentralDirRecord getZip64EndCentralDirRecord() { 124 | return zip64EndCentralDirRecord; 125 | } 126 | 127 | public void setZip64EndCentralDirRecord( 128 | Zip64EndCentralDirRecord zip64EndCentralDirRecord) { 129 | this.zip64EndCentralDirRecord = zip64EndCentralDirRecord; 130 | } 131 | 132 | public boolean isZip64Format() { 133 | return isZip64Format; 134 | } 135 | 136 | public void setZip64Format(boolean isZip64Format) { 137 | this.isZip64Format = isZip64Format; 138 | } 139 | 140 | public boolean isNestedZipFile() { 141 | return isNestedZipFile; 142 | } 143 | 144 | public void setNestedZipFile(boolean isNestedZipFile) { 145 | this.isNestedZipFile = isNestedZipFile; 146 | } 147 | 148 | public long getStart() { 149 | return start; 150 | } 151 | 152 | public void setStart(long start) { 153 | this.start = start; 154 | } 155 | 156 | public long getEnd() { 157 | return end; 158 | } 159 | 160 | public void setEnd(long end) { 161 | this.end = end; 162 | } 163 | 164 | public long getSplitLength() { 165 | return splitLength; 166 | } 167 | 168 | public void setSplitLength(long splitLength) { 169 | this.splitLength = splitLength; 170 | } 171 | 172 | public Object clone() throws CloneNotSupportedException { 173 | return super.clone(); 174 | } 175 | 176 | public String getFileNameCharset() { 177 | return fileNameCharset; 178 | } 179 | 180 | public void setFileNameCharset(String fileNameCharset) { 181 | this.fileNameCharset = fileNameCharset; 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/progress/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.progress 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.progress

66 |
67 |
68 | 87 |
88 | 89 |
90 | 91 | 92 | 93 | 94 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/engine/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto.engine Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.crypto.engine

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 81 |
82 | 83 |
84 | 85 | 86 | 87 | 88 | 97 |
98 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/unzip/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.unzip Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.unzip

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 82 |
83 | 84 |
85 | 86 | 87 | 88 | 89 | 98 |
99 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/exception/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.exception Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.exception

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 88 |

Interface Hierarchy

89 | 92 |
93 | 94 |
95 | 96 | 97 | 98 | 99 | 108 |
109 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/InflaterInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.io; 18 | 19 | import java.io.EOFException; 20 | import java.io.IOException; 21 | import java.io.RandomAccessFile; 22 | import java.util.zip.DataFormatException; 23 | import java.util.zip.Inflater; 24 | 25 | import net.lingala.zip4j.unzip.UnzipEngine; 26 | import net.lingala.zip4j.util.InternalZipConstants; 27 | import net.lingala.zip4j.util.Zip4jConstants; 28 | 29 | public class InflaterInputStream extends PartInputStream { 30 | 31 | private Inflater inflater; 32 | private byte[] buff; 33 | private byte[] oneByteBuff = new byte[1]; 34 | private UnzipEngine unzipEngine; 35 | private long bytesWritten; 36 | private long uncompressedSize; 37 | 38 | public InflaterInputStream(RandomAccessFile raf, long start, long len, UnzipEngine unzipEngine) { 39 | super(raf, start, len, unzipEngine); 40 | this.inflater = new Inflater(true); 41 | this.buff = new byte[InternalZipConstants.BUFF_SIZE]; 42 | this.unzipEngine = unzipEngine; 43 | bytesWritten = 0; 44 | uncompressedSize = unzipEngine.getFileHeader().getUncompressedSize(); 45 | } 46 | 47 | public int read() throws IOException { 48 | return read(oneByteBuff, 0, 1) == -1 ? -1 : oneByteBuff[0] & 0xff; 49 | } 50 | 51 | public int read(byte[] b) throws IOException { 52 | if (b == null) { 53 | throw new NullPointerException("input buffer is null"); 54 | } 55 | 56 | return read(b, 0, b.length); 57 | } 58 | 59 | public int read(byte[] b, int off, int len) throws IOException { 60 | 61 | if (b == null) { 62 | throw new NullPointerException("input buffer is null"); 63 | } else if (off < 0 || len < 0 || len > b.length - off) { 64 | throw new IndexOutOfBoundsException(); 65 | } else if (len == 0) { 66 | return 0; 67 | } 68 | 69 | try { 70 | int n; 71 | if (bytesWritten >= uncompressedSize) 72 | return -1; 73 | while ((n = inflater.inflate(b, off, len)) == 0) { 74 | if (inflater.finished() || inflater.needsDictionary()) { 75 | return -1; 76 | } 77 | if (inflater.needsInput()) { 78 | fill(); 79 | } 80 | } 81 | bytesWritten += n; 82 | return n; 83 | } catch (DataFormatException e) { 84 | String s = "Invalid ZLIB data format"; 85 | if (e.getMessage() != null) { 86 | s = e.getMessage(); 87 | } 88 | if (unzipEngine != null) { 89 | if (unzipEngine.getLocalFileHeader().isEncrypted() && 90 | unzipEngine.getLocalFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) { 91 | s += " - Wrong Password?"; 92 | } 93 | } 94 | throw new IOException(s); 95 | } 96 | } 97 | 98 | private void fill() throws IOException { 99 | int len = super.read(buff, 0, buff.length); 100 | if (len == -1) { 101 | throw new EOFException("Unexpected end of ZLIB input stream"); 102 | } 103 | inflater.setInput(buff, 0, len); 104 | } 105 | 106 | /** 107 | * Skips specified number of bytes of uncompressed data. 108 | * @param n the number of bytes to skip 109 | * @return the actual number of bytes skipped. 110 | * @exception IOException if an I/O error has occurred 111 | * @exception IllegalArgumentException if n < 0 112 | */ 113 | public long skip(long n) throws IOException { 114 | if (n < 0) { 115 | throw new IllegalArgumentException("negative skip length"); 116 | } 117 | int max = (int)Math.min(n, Integer.MAX_VALUE); 118 | int total = 0; 119 | byte[] b = new byte[512]; 120 | while (total < max) { 121 | int len = max - total; 122 | if (len > b.length) { 123 | len = b.length; 124 | } 125 | len = read(b, 0, len); 126 | if (len == -1) { 127 | break; 128 | } 129 | total += len; 130 | } 131 | return total; 132 | } 133 | 134 | 135 | public void seek(long pos) throws IOException { 136 | super.seek(pos); 137 | } 138 | 139 | /** 140 | * Returns 0 after EOF has been reached, otherwise always return 1. 141 | *

142 | * Programs should not count on this method to return the actual number 143 | * of bytes that could be read without blocking. 144 | * 145 | * @return 1 before EOF and 0 after EOF. 146 | * @exception IOException if an I/O error occurs. 147 | * 148 | */ 149 | public int available() { 150 | return inflater.finished() ? 0 : 1; 151 | } 152 | 153 | public void close() throws IOException { 154 | inflater.end(); 155 | super.close(); 156 | } 157 | 158 | public UnzipEngine getUnzipEngine() { 159 | return super.getUnzipEngine(); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/PBKDF2/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto.PBKDF2 Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 |

JavaScript is disabled on your browser.
19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.crypto.PBKDF2

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 | 82 |
83 | 84 |
85 | 86 | 87 | 88 | 89 | 98 |
99 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/unzip/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.unzip 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.unzip

66 |
67 |
68 | 93 |
94 | 95 |
96 | 97 | 98 | 99 | 100 | 109 |
110 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/engine/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto.engine 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.crypto.engine

66 |
67 |
68 | 91 |
92 | 93 |
94 | 95 | 96 | 97 | 98 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/core/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.core 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.core

66 |
67 |
68 | 97 |
98 | 99 |
100 | 101 | 102 | 103 | 104 | 113 |
114 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/crypto/PBKDF2/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.crypto.PBKDF2 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.crypto.PBKDF2

66 |
67 |
68 | 93 |
94 | 95 |
96 | 97 | 98 | 99 | 100 | 109 |
110 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/io/PartInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.io; 18 | 19 | import java.io.IOException; 20 | import java.io.RandomAccessFile; 21 | 22 | import net.lingala.zip4j.crypto.AESDecrypter; 23 | import net.lingala.zip4j.crypto.IDecrypter; 24 | import net.lingala.zip4j.exception.ZipException; 25 | import net.lingala.zip4j.unzip.UnzipEngine; 26 | import net.lingala.zip4j.util.InternalZipConstants; 27 | import net.lingala.zip4j.util.Zip4jConstants; 28 | 29 | public class PartInputStream extends BaseInputStream 30 | { 31 | private RandomAccessFile raf; 32 | private long bytesRead, length; 33 | private UnzipEngine unzipEngine; 34 | private IDecrypter decrypter; 35 | private byte[] oneByteBuff = new byte[1]; 36 | private byte[] aesBlockByte = new byte[16]; 37 | private int aesBytesReturned = 0; 38 | private boolean isAESEncryptedFile = false; 39 | private int count = -1; 40 | 41 | public PartInputStream(RandomAccessFile raf, long start, long len, UnzipEngine unzipEngine) { 42 | this.raf = raf; 43 | this.unzipEngine = unzipEngine; 44 | this.decrypter = unzipEngine.getDecrypter(); 45 | this.bytesRead = 0; 46 | this.length = len; 47 | this.isAESEncryptedFile = unzipEngine.getFileHeader().isEncrypted() && 48 | unzipEngine.getFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES; 49 | } 50 | 51 | public int available() { 52 | long amount = length - bytesRead; 53 | if (amount > Integer.MAX_VALUE) 54 | return Integer.MAX_VALUE; 55 | return (int) amount; 56 | } 57 | 58 | public int read() throws IOException { 59 | if (bytesRead >= length) 60 | return -1; 61 | 62 | if (isAESEncryptedFile) { 63 | if (aesBytesReturned == 0 || aesBytesReturned == 16) { 64 | if (read(aesBlockByte) == -1) { 65 | return -1; 66 | } 67 | aesBytesReturned = 0; 68 | } 69 | return aesBlockByte[aesBytesReturned++] & 0xff; 70 | } else { 71 | return read(oneByteBuff, 0, 1) == -1 ? -1 : oneByteBuff[0] & 0xff; 72 | } 73 | } 74 | 75 | public int read(byte[] b) throws IOException { 76 | return read(b, 0, b.length); 77 | } 78 | 79 | public int read(byte[] b, int off, int len) throws IOException { 80 | if (len > length - bytesRead) { 81 | len = (int) (length - bytesRead); 82 | if (len == 0) { 83 | checkAndReadAESMacBytes(); 84 | return -1; 85 | } 86 | } 87 | 88 | if (unzipEngine.getDecrypter() instanceof AESDecrypter) { 89 | if (bytesRead + len < length) { 90 | if (len % 16 != 0) { 91 | len = len - (len%16); 92 | } 93 | } 94 | } 95 | 96 | synchronized (raf) { 97 | count = raf.read(b, off, len); 98 | if ((count < len) && unzipEngine.getZipModel().isSplitArchive()) { 99 | raf.close(); 100 | raf = unzipEngine.startNextSplitFile(); 101 | if (count < 0) count = 0; 102 | int newlyRead = raf.read(b, count, len-count); 103 | if (newlyRead > 0) 104 | count += newlyRead; 105 | } 106 | } 107 | 108 | if (count > 0) { 109 | if (decrypter != null) { 110 | try { 111 | decrypter.decryptData(b, off, count); 112 | } catch (ZipException e) { 113 | throw new IOException(e.getMessage()); 114 | } 115 | } 116 | bytesRead += count; 117 | } 118 | 119 | if (bytesRead >= length) { 120 | checkAndReadAESMacBytes(); 121 | } 122 | 123 | return count; 124 | } 125 | 126 | private void checkAndReadAESMacBytes() throws IOException { 127 | if (isAESEncryptedFile) { 128 | if (decrypter != null && decrypter instanceof AESDecrypter) { 129 | if (((AESDecrypter)decrypter).getStoredMac() != null) { 130 | //Stored mac already set 131 | return; 132 | } 133 | byte[] macBytes = new byte[InternalZipConstants.AES_AUTH_LENGTH]; 134 | int readLen = -1; 135 | readLen = raf.read(macBytes); 136 | if (readLen != InternalZipConstants.AES_AUTH_LENGTH) { 137 | if (unzipEngine.getZipModel().isSplitArchive()) { 138 | raf.close(); 139 | raf = unzipEngine.startNextSplitFile(); 140 | int newlyRead = raf.read(macBytes, readLen, InternalZipConstants.AES_AUTH_LENGTH - readLen); 141 | readLen += newlyRead; 142 | } else { 143 | throw new IOException("Error occured while reading stored AES authentication bytes"); 144 | } 145 | } 146 | 147 | ((AESDecrypter)unzipEngine.getDecrypter()).setStoredMac(macBytes); 148 | } 149 | } 150 | } 151 | 152 | public long skip(long amount) throws IOException { 153 | if (amount < 0) 154 | throw new IllegalArgumentException(); 155 | if (amount > length - bytesRead) 156 | amount = length - bytesRead; 157 | bytesRead += amount; 158 | return amount; 159 | } 160 | 161 | public void close() throws IOException { 162 | raf.close(); 163 | } 164 | 165 | public void seek(long pos) throws IOException { 166 | raf.seek(pos); 167 | } 168 | 169 | public UnzipEngine getUnzipEngine() { 170 | return this.unzipEngine; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/util/Raw.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.util; 18 | 19 | import java.io.DataInput; 20 | import java.io.IOException; 21 | 22 | import net.lingala.zip4j.exception.ZipException; 23 | 24 | public class Raw 25 | { 26 | public static long readLongLittleEndian(byte[] array,int pos){ 27 | long temp = 0; 28 | temp |= array[pos+7]&0xff; 29 | temp <<=8; 30 | temp |= array[pos+6]&0xff; 31 | temp <<=8; 32 | temp |= array[pos+5]&0xff; 33 | temp <<=8; 34 | temp |= array[pos+4]&0xff; 35 | temp <<=8; 36 | temp |= array[pos+3]&0xff; 37 | temp <<=8; 38 | temp |= array[pos+2]&0xff; 39 | temp <<=8; 40 | temp |= array[pos+1]&0xff; 41 | temp <<=8; 42 | temp |= array[pos]&0xff; 43 | return temp; 44 | } 45 | 46 | public static int readLeInt(DataInput di, byte[] b) throws ZipException{ 47 | try { 48 | di.readFully(b, 0, 4); 49 | } catch (IOException e) { 50 | throw new ZipException(e); 51 | } 52 | return ((b[0] & 0xff) | (b[1] & 0xff) << 8) 53 | | ((b[2] & 0xff) | (b[3] & 0xff) << 8) << 16; 54 | } 55 | 56 | public static int readShortLittleEndian(byte[] b, int off){ 57 | return (b[off] & 0xff) | (b[off+1] & 0xff) << 8; 58 | } 59 | 60 | public static final short readShortBigEndian(byte[] array, int pos) { 61 | short temp = 0; 62 | temp |= array[pos] & 0xff; 63 | temp <<= 8; 64 | temp |= array[pos + 1] & 0xff; 65 | return temp; 66 | } 67 | 68 | public static int readIntLittleEndian(byte[] b, int off){ 69 | return ((b[off] & 0xff) | (b[off+1] & 0xff) << 8) 70 | | ((b[off+2] & 0xff) | (b[off+3] & 0xff) << 8) << 16; 71 | } 72 | 73 | public static byte[] toByteArray(int in,int outSize) { 74 | byte[] out = new byte[outSize]; 75 | byte[] intArray = toByteArray(in); 76 | for( int i=0; i> 8); 87 | out[2] = (byte)(in >> 16); 88 | out[3] = (byte)(in >> 24); 89 | 90 | return out; 91 | } 92 | 93 | public static final void writeShortLittleEndian(byte[] array, int pos, 94 | short value) { 95 | array[pos +1] = (byte) (value >>> 8); 96 | array[pos ] = (byte) (value & 0xFF); 97 | 98 | } 99 | 100 | public static final void writeIntLittleEndian(byte[] array, int pos,int value) { 101 | array[pos+3] = (byte) (value >>>24); 102 | array[pos+2] = (byte) (value >>>16); 103 | array[pos+1] = (byte) (value >>>8); 104 | array[pos] = (byte) (value &0xFF); 105 | 106 | } 107 | 108 | public static void writeLongLittleEndian(byte[] array, int pos, long value){ 109 | array[pos+7] = (byte) (value >>>56); 110 | array[pos+6] = (byte) (value >>>48); 111 | array[pos+5] = (byte) (value >>>40); 112 | array[pos+4] = (byte) (value >>>32); 113 | array[pos+3] = (byte) (value >>>24); 114 | array[pos+2] = (byte) (value >>>16); 115 | array[pos+1] = (byte) (value >>>8); 116 | array[pos] = (byte) (value &0xFF); 117 | } 118 | 119 | public static byte bitArrayToByte(int[] bitArray) throws ZipException { 120 | if (bitArray == null) { 121 | throw new ZipException("bit array is null, cannot calculate byte from bits"); 122 | } 123 | 124 | if (bitArray.length != 8) { 125 | throw new ZipException("invalid bit array length, cannot calculate byte"); 126 | } 127 | 128 | if(!checkBits(bitArray)) { 129 | throw new ZipException("invalid bits provided, bits contain other values than 0 or 1"); 130 | } 131 | 132 | int retNum = 0; 133 | for (int i = 0; i < bitArray.length; i++) { 134 | retNum += Math.pow(2, i) * bitArray[i]; 135 | } 136 | 137 | return (byte)retNum; 138 | } 139 | 140 | private static boolean checkBits(int[] bitArray) { 141 | for (int i = 0; i < bitArray.length; i++) { 142 | if (bitArray[i] != 0 && bitArray[i] != 1) { 143 | return false; 144 | } 145 | } 146 | return true; 147 | } 148 | 149 | public static void prepareBuffAESIVBytes(byte[] buff, int nonce, int length) { 150 | buff[0] = (byte)nonce; 151 | buff[1] = (byte)(nonce >> 8); 152 | buff[2] = (byte)(nonce >> 16); 153 | buff[3] = (byte)(nonce >> 24); 154 | buff[4] = 0; 155 | buff[5] = 0; 156 | buff[6] = 0; 157 | buff[7] = 0; 158 | buff[8] = 0; 159 | buff[9] = 0; 160 | buff[10] = 0; 161 | buff[11] = 0; 162 | buff[12] = 0; 163 | buff[13] = 0; 164 | buff[14] = 0; 165 | buff[15] = 0; 166 | } 167 | 168 | /** 169 | * Converts a char array to byte array 170 | * @param charArray 171 | * @return byte array representation of the input char array 172 | */ 173 | public static byte[] convertCharArrayToByteArray(char[] charArray) { 174 | if (charArray == null) { 175 | throw new NullPointerException(); 176 | } 177 | 178 | byte[] bytes = new byte[charArray.length]; 179 | for(int i=0;i 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.exception 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Package net.lingala.zip4j.exception

66 |
67 |
68 |
    69 |
  • 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
    Interface Summary 
    InterfaceDescription
    ZipExceptionConstants 
    83 |
  • 84 |
  • 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
    Exception Summary 
    ExceptionDescription
    ZipException 
    98 |
  • 99 |
100 |
101 | 102 |
103 | 104 | 105 | 106 | 107 | 116 |
117 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/html/net/lingala/zip4j/util/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net.lingala.zip4j.util Class Hierarchy 7 | 8 | 9 | 10 | 11 | 17 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 35 |
36 | 63 | 64 |
65 |

Hierarchy For Package net.lingala.zip4j.util

66 | Package Hierarchies: 67 | 70 |
71 |
72 |

Class Hierarchy

73 |
    74 |
  • java.lang.Object 75 | 81 |
  • 82 |
83 |

Interface Hierarchy

84 | 88 |
89 | 90 |
91 | 92 | 93 | 94 | 95 | 104 |
105 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /src/net/lingala/zip4j/crypto/PBKDF2/PBKDF2Engine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Srikanth Reddy Lingala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, 11 | * software distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.lingala.zip4j.crypto.PBKDF2; 18 | 19 | import net.lingala.zip4j.util.Raw; 20 | 21 | /* 22 | * Source referred from Matthias Gartner's PKCS#5 implementation - 23 | * see http://rtner.de/software/PBKDF2.html 24 | */ 25 | 26 | public class PBKDF2Engine 27 | { 28 | protected PBKDF2Parameters parameters; 29 | 30 | protected PRF prf; 31 | 32 | public PBKDF2Engine() 33 | { 34 | this.parameters = null; 35 | prf = null; 36 | } 37 | 38 | public PBKDF2Engine(PBKDF2Parameters parameters) 39 | { 40 | this.parameters = parameters; 41 | prf = null; 42 | } 43 | 44 | public PBKDF2Engine(PBKDF2Parameters parameters, PRF prf) 45 | { 46 | this.parameters = parameters; 47 | this.prf = prf; 48 | } 49 | 50 | public byte[] deriveKey(char[] inputPassword) 51 | { 52 | return deriveKey(inputPassword, 0); 53 | } 54 | 55 | public byte[] deriveKey(char[] inputPassword, int dkLen) 56 | { 57 | byte[] r = null; 58 | byte P[] = null; 59 | if (inputPassword == null) 60 | { 61 | throw new NullPointerException(); 62 | } 63 | 64 | P = Raw.convertCharArrayToByteArray(inputPassword); 65 | 66 | assertPRF(P); 67 | if (dkLen == 0) 68 | { 69 | dkLen = prf.getHLen(); 70 | } 71 | r = PBKDF2(prf, parameters.getSalt(), parameters.getIterationCount(), 72 | dkLen); 73 | return r; 74 | } 75 | 76 | public boolean verifyKey(char[] inputPassword) 77 | { 78 | byte[] referenceKey = getParameters().getDerivedKey(); 79 | if (referenceKey == null || referenceKey.length == 0) 80 | { 81 | return false; 82 | } 83 | byte[] inputKey = deriveKey(inputPassword, referenceKey.length); 84 | 85 | if (inputKey == null || inputKey.length != referenceKey.length) 86 | { 87 | return false; 88 | } 89 | for (int i = 0; i < inputKey.length; i++) 90 | { 91 | if (inputKey[i] != referenceKey[i]) 92 | { 93 | return false; 94 | } 95 | } 96 | return true; 97 | } 98 | 99 | protected void assertPRF(byte[] P) 100 | { 101 | if (prf == null) 102 | { 103 | prf = new MacBasedPRF(parameters.getHashAlgorithm()); 104 | } 105 | prf.init(P); 106 | } 107 | 108 | public PRF getPseudoRandomFunction() 109 | { 110 | return prf; 111 | } 112 | 113 | protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen) 114 | { 115 | if (S == null) 116 | { 117 | S = new byte[0]; 118 | } 119 | int hLen = prf.getHLen(); 120 | int l = ceil(dkLen, hLen); 121 | int r = dkLen - (l - 1) * hLen; 122 | byte T[] = new byte[l * hLen]; 123 | int ti_offset = 0; 124 | for (int i = 1; i <= l; i++) 125 | { 126 | _F(T, ti_offset, prf, S, c, i); 127 | ti_offset += hLen; 128 | } 129 | if (r < hLen) 130 | { 131 | // Incomplete last block 132 | byte DK[] = new byte[dkLen]; 133 | System.arraycopy(T, 0, DK, 0, dkLen); 134 | return DK; 135 | } 136 | return T; 137 | } 138 | 139 | protected int ceil(int a, int b) 140 | { 141 | int m = 0; 142 | if (a % b > 0) 143 | { 144 | m = 1; 145 | } 146 | return a / b + m; 147 | } 148 | 149 | protected void _F(byte[] dest, int offset, PRF prf, byte[] S, int c, 150 | int blockIndex) 151 | { 152 | int hLen = prf.getHLen(); 153 | byte U_r[] = new byte[hLen]; 154 | 155 | // U0 = S || INT (i); 156 | byte U_i[] = new byte[S.length + 4]; 157 | System.arraycopy(S, 0, U_i, 0, S.length); 158 | INT(U_i, S.length, blockIndex); 159 | 160 | for (int i = 0; i < c; i++) 161 | { 162 | U_i = prf.doFinal(U_i); 163 | xor(U_r, U_i); 164 | } 165 | System.arraycopy(U_r, 0, dest, offset, hLen); 166 | } 167 | 168 | protected void xor(byte[] dest, byte[] src) 169 | { 170 | for (int i = 0; i < dest.length; i++) 171 | { 172 | dest[i] ^= src[i]; 173 | } 174 | } 175 | 176 | protected void INT(byte[] dest, int offset, int i) 177 | { 178 | dest[offset + 0] = (byte) (i / (256 * 256 * 256)); 179 | dest[offset + 1] = (byte) (i / (256 * 256)); 180 | dest[offset + 2] = (byte) (i / (256)); 181 | dest[offset + 3] = (byte) (i); 182 | } 183 | 184 | public PBKDF2Parameters getParameters() 185 | { 186 | return parameters; 187 | } 188 | 189 | public void setParameters(PBKDF2Parameters parameters) 190 | { 191 | this.parameters = parameters; 192 | } 193 | 194 | public void setPseudoRandomFunction(PRF prf) 195 | { 196 | this.prf = prf; 197 | } 198 | } 199 | --------------------------------------------------------------------------------