Java Examples for net.lingala.zip4j.exception.ZipExceptionConstants
The following java examples will help you to understand the usage of net.lingala.zip4j.exception.ZipExceptionConstants. These source code samples are taken from different open source projects.
Example 1
| Project: MinecraftAutoInstaller-master File: HeaderReader.java View source code |
/**
* Reads end of central directory record
* @return {@link EndCentralDirRecord}
* @throws ZipException
*/
private EndCentralDirRecord readEndOfCentralDirectoryRecord() throws ZipException {
if (zip4jRaf == null) {
throw new ZipException("random access file was null", ZipExceptionConstants.randomAccessFileNull);
}
try {
byte[] ebs = new byte[4];
long pos = zip4jRaf.length() - InternalZipConstants.ENDHDR;
EndCentralDirRecord endCentralDirRecord = new EndCentralDirRecord();
int counter = 0;
do {
zip4jRaf.seek(pos--);
counter++;
} while ((Raw.readLeInt(zip4jRaf, ebs) != InternalZipConstants.ENDSIG) && counter <= 3000);
if ((Raw.readIntLittleEndian(ebs, 0) != InternalZipConstants.ENDSIG)) {
throw new ZipException("zip headers not found. probably not a zip file");
}
byte[] intBuff = new byte[4];
byte[] shortBuff = new byte[2];
//End of central record signature
endCentralDirRecord.setSignature(InternalZipConstants.ENDSIG);
//number of this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//number of the disk with the start of the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDiskStartOfCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory on this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDirOnThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//size of the central directory
readIntoBuff(zip4jRaf, intBuff);
endCentralDirRecord.setSizeOfCentralDir(Raw.readIntLittleEndian(intBuff, 0));
//offset of start of central directory with respect to the starting disk number
readIntoBuff(zip4jRaf, intBuff);
byte[] longBuff = getLongByteFromIntByte(intBuff);
endCentralDirRecord.setOffsetOfStartOfCentralDir(Raw.readLongLittleEndian(longBuff, 0));
//.ZIP file comment length
readIntoBuff(zip4jRaf, shortBuff);
int commentLength = Raw.readShortLittleEndian(shortBuff, 0);
endCentralDirRecord.setCommentLength(commentLength);
//.ZIP file comment
if (commentLength > 0) {
byte[] commentBuf = new byte[commentLength];
readIntoBuff(zip4jRaf, commentBuf);
endCentralDirRecord.setComment(new String(commentBuf));
endCentralDirRecord.setCommentBytes(commentBuf);
} else {
endCentralDirRecord.setComment(null);
}
int diskNumber = endCentralDirRecord.getNoOfThisDisk();
if (diskNumber > 0) {
zipModel.setSplitArchive(true);
} else {
zipModel.setSplitArchive(false);
}
return endCentralDirRecord;
} catch (IOException e) {
throw new ZipException("Probably not a zip file or a corrupted zip file", e, ZipExceptionConstants.notZipFile);
}
}Example 2
| Project: andFHEM-master File: ImportExportService.java View source code |
@SuppressWarnings("unchecked")
public ImportStatus importSettings(File file, String password, Context context) {
ZipFile zipFile;
InputStreamReader importReader = null;
try {
zipFile = new ZipFile(file);
if (zipFile.isEncrypted()) {
zipFile.setPassword(MoreObjects.firstNonNull(password, ""));
}
if (zipFile.getFileHeader(SHARED_PREFERENCES_FILE_NAME) == null) {
return ImportStatus.INVALID_FILE;
}
zipFile.extractFile(SHARED_PREFERENCES_FILE_NAME, fileSystemService.getCacheDir(context).getAbsolutePath());
importReader = new InputStreamReader(new FileInputStream(new File(fileSystemService.getCacheDir(context), SHARED_PREFERENCES_FILE_NAME)));
Map<String, Map<String, String>> content = new Gson().fromJson(importReader, Map.class);
for (Map.Entry<String, Map<String, String>> entry : content.entrySet()) {
sharedPreferencesService.writeAllIn(getSharedPreferencesExportKeys(context).get(entry.getKey()), toImportValues(entry.getValue()), context);
}
return ImportStatus.SUCCESS;
} catch (ZipException e) {
LOGGER.error("importSettings(" + file.getAbsolutePath() + ") - cannot import", e);
if (e.getCode() == ZipExceptionConstants.WRONG_PASSWORD || e.getMessage().contains("Wrong Password")) {
return ImportStatus.WRONG_PASSWORD;
} else {
return ImportStatus.INVALID_FILE;
}
} catch (Exception e) {
LOGGER.error("importSettings(" + file.getAbsolutePath() + ") - cannot import", e);
return ImportStatus.INVALID_FILE;
} finally {
CloseableUtil.close(importReader);
}
}Example 3
| Project: Android-Zip4j-master File: HeaderReader.java View source code |
/**
* Reads end of central directory record
* @return {@link EndCentralDirRecord}
* @throws ZipException
*/
private EndCentralDirRecord readEndOfCentralDirectoryRecord() throws ZipException {
if (zip4jRaf == null) {
throw new ZipException("random access file was null", ZipExceptionConstants.randomAccessFileNull);
}
try {
byte[] ebs = new byte[4];
long pos = zip4jRaf.length() - InternalZipConstants.ENDHDR;
EndCentralDirRecord endCentralDirRecord = new EndCentralDirRecord();
int counter = 0;
do {
zip4jRaf.seek(pos--);
counter++;
} while ((Raw.readLeInt(zip4jRaf, ebs) != InternalZipConstants.ENDSIG) && counter <= 3000);
if ((Raw.readIntLittleEndian(ebs, 0) != InternalZipConstants.ENDSIG)) {
throw new ZipException("zip headers not found. probably not a zip file");
}
byte[] intBuff = new byte[4];
byte[] shortBuff = new byte[2];
//End of central record signature
endCentralDirRecord.setSignature(InternalZipConstants.ENDSIG);
//number of this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//number of the disk with the start of the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDiskStartOfCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory on this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDirOnThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//size of the central directory
readIntoBuff(zip4jRaf, intBuff);
endCentralDirRecord.setSizeOfCentralDir(Raw.readIntLittleEndian(intBuff, 0));
//offset of start of central directory with respect to the starting disk number
readIntoBuff(zip4jRaf, intBuff);
byte[] longBuff = getLongByteFromIntByte(intBuff);
endCentralDirRecord.setOffsetOfStartOfCentralDir(Raw.readLongLittleEndian(longBuff, 0));
//.ZIP file comment length
readIntoBuff(zip4jRaf, shortBuff);
int commentLength = Raw.readShortLittleEndian(shortBuff, 0);
endCentralDirRecord.setCommentLength(commentLength);
//.ZIP file comment
if (commentLength > 0) {
byte[] commentBuf = new byte[commentLength];
readIntoBuff(zip4jRaf, commentBuf);
endCentralDirRecord.setComment(new String(commentBuf));
endCentralDirRecord.setCommentBytes(commentBuf);
} else {
endCentralDirRecord.setComment(null);
}
int diskNumber = endCentralDirRecord.getNoOfThisDisk();
if (diskNumber > 0) {
zipModel.setSplitArchive(true);
} else {
zipModel.setSplitArchive(false);
}
return endCentralDirRecord;
} catch (IOException e) {
throw new ZipException("Probably not a zip file or a corrupted zip file", e, ZipExceptionConstants.notZipFile);
}
}Example 4
| Project: AllArkhamPlugins-master File: HeaderReader.java View source code |
/**
* Reads end of central directory record
*
* @return {@link EndCentralDirRecord}
* @throws ZipException
*/
private EndCentralDirRecord readEndOfCentralDirectoryRecord() throws ZipException {
if (zip4jRaf == null) {
throw new ZipException("random access file was null", ZipExceptionConstants.randomAccessFileNull);
}
try {
byte[] ebs = new byte[4];
long pos = zip4jRaf.length() - InternalZipConstants.ENDHDR;
EndCentralDirRecord endCentralDirRecord = new EndCentralDirRecord();
int counter = 0;
do {
zip4jRaf.seek(pos--);
counter++;
} while ((Raw.readLeInt(zip4jRaf, ebs) != InternalZipConstants.ENDSIG) && counter <= 3000);
if ((Raw.readIntLittleEndian(ebs, 0) != InternalZipConstants.ENDSIG)) {
throw new ZipException("zip headers not found. probably not a zip file");
}
byte[] intBuff = new byte[4];
byte[] shortBuff = new byte[2];
// End of central record signature
endCentralDirRecord.setSignature(InternalZipConstants.ENDSIG);
// number of this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
// number of the disk with the start of the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDiskStartOfCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
// total number of entries in the central directory on this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDirOnThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
// total number of entries in the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
// size of the central directory
readIntoBuff(zip4jRaf, intBuff);
endCentralDirRecord.setSizeOfCentralDir(Raw.readIntLittleEndian(intBuff, 0));
// offset of start of central directory with respect to the starting
// disk number
readIntoBuff(zip4jRaf, intBuff);
byte[] longBuff = getLongByteFromIntByte(intBuff);
endCentralDirRecord.setOffsetOfStartOfCentralDir(Raw.readLongLittleEndian(longBuff, 0));
// .ZIP file comment length
readIntoBuff(zip4jRaf, shortBuff);
int commentLength = Raw.readShortLittleEndian(shortBuff, 0);
endCentralDirRecord.setCommentLength(commentLength);
// .ZIP file comment
if (commentLength > 0) {
byte[] commentBuf = new byte[commentLength];
readIntoBuff(zip4jRaf, commentBuf);
endCentralDirRecord.setComment(new String(commentBuf));
endCentralDirRecord.setCommentBytes(commentBuf);
} else {
endCentralDirRecord.setComment(null);
}
int diskNumber = endCentralDirRecord.getNoOfThisDisk();
if (diskNumber > 0) {
zipModel.setSplitArchive(true);
} else {
zipModel.setSplitArchive(false);
}
return endCentralDirRecord;
} catch (IOException e) {
throw new ZipException("Probably not a zip file or a corrupted zip file", e, ZipExceptionConstants.notZipFile);
}
}Example 5
| Project: SurvivalGamesX-master File: HeaderReader.java View source code |
/**
* Reads end of central directory record
* @return {@link EndCentralDirRecord}
* @throws ZipException
*/
private EndCentralDirRecord readEndOfCentralDirectoryRecord() throws ZipException {
if (zip4jRaf == null) {
throw new ZipException("random access file was null", ZipExceptionConstants.randomAccessFileNull);
}
try {
byte[] ebs = new byte[4];
long pos = zip4jRaf.length() - InternalZipConstants.ENDHDR;
EndCentralDirRecord endCentralDirRecord = new EndCentralDirRecord();
int counter = 0;
do {
zip4jRaf.seek(pos--);
counter++;
} while ((Raw.readLeInt(zip4jRaf, ebs) != InternalZipConstants.ENDSIG) && counter <= 3000);
if ((Raw.readIntLittleEndian(ebs, 0) != InternalZipConstants.ENDSIG)) {
throw new ZipException("zip headers not found. probably not a zip file");
}
byte[] intBuff = new byte[4];
byte[] shortBuff = new byte[2];
//End of central record signature
endCentralDirRecord.setSignature(InternalZipConstants.ENDSIG);
//number of this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//number of the disk with the start of the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDiskStartOfCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory on this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDirOnThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//size of the central directory
readIntoBuff(zip4jRaf, intBuff);
endCentralDirRecord.setSizeOfCentralDir(Raw.readIntLittleEndian(intBuff, 0));
//offset of start of central directory with respect to the starting disk number
readIntoBuff(zip4jRaf, intBuff);
byte[] longBuff = getLongByteFromIntByte(intBuff);
endCentralDirRecord.setOffsetOfStartOfCentralDir(Raw.readLongLittleEndian(longBuff, 0));
//.ZIP file comment length
readIntoBuff(zip4jRaf, shortBuff);
int commentLength = Raw.readShortLittleEndian(shortBuff, 0);
endCentralDirRecord.setCommentLength(commentLength);
//.ZIP file comment
if (commentLength > 0) {
byte[] commentBuf = new byte[commentLength];
readIntoBuff(zip4jRaf, commentBuf);
endCentralDirRecord.setComment(new String(commentBuf));
endCentralDirRecord.setCommentBytes(commentBuf);
} else {
endCentralDirRecord.setComment(null);
}
int diskNumber = endCentralDirRecord.getNoOfThisDisk();
if (diskNumber > 0) {
zipModel.setSplitArchive(true);
} else {
zipModel.setSplitArchive(false);
}
return endCentralDirRecord;
} catch (IOException e) {
throw new ZipException("Probably not a zip file or a corrupted zip file", e, ZipExceptionConstants.notZipFile);
}
}Example 6
| Project: android-ePub-Library-master File: HeaderReader.java View source code |
/**
* Reads end of central directory record
* @return {@link EndCentralDirRecord}
* @throws ZipException
*/
private EndCentralDirRecord readEndOfCentralDirectoryRecord() throws ZipException {
if (zip4jRaf == null) {
throw new ZipException("random access file was null", ZipExceptionConstants.randomAccessFileNull);
}
try {
byte[] ebs = new byte[4];
long pos = zip4jRaf.length() - InternalZipConstants.ENDHDR;
EndCentralDirRecord endCentralDirRecord = new EndCentralDirRecord();
int counter = 0;
do {
zip4jRaf.seek(pos--);
counter++;
} while ((Raw.readLeInt(zip4jRaf, ebs) != InternalZipConstants.ENDSIG) && counter <= 3000);
if ((Raw.readIntLittleEndian(ebs, 0) != InternalZipConstants.ENDSIG)) {
throw new ZipException("zip headers not found. probably not a zip file");
}
byte[] intBuff = new byte[4];
byte[] shortBuff = new byte[2];
//End of central record signature
endCentralDirRecord.setSignature(InternalZipConstants.ENDSIG);
//number of this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//number of the disk with the start of the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setNoOfThisDiskStartOfCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory on this disk
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDirOnThisDisk(Raw.readShortLittleEndian(shortBuff, 0));
//total number of entries in the central directory
readIntoBuff(zip4jRaf, shortBuff);
endCentralDirRecord.setTotNoOfEntriesInCentralDir(Raw.readShortLittleEndian(shortBuff, 0));
//size of the central directory
readIntoBuff(zip4jRaf, intBuff);
endCentralDirRecord.setSizeOfCentralDir(Raw.readIntLittleEndian(intBuff, 0));
//offset of start of central directory with respect to the starting disk number
readIntoBuff(zip4jRaf, intBuff);
byte[] longBuff = getLongByteFromIntByte(intBuff);
endCentralDirRecord.setOffsetOfStartOfCentralDir(Raw.readLongLittleEndian(longBuff, 0));
//.ZIP file comment length
readIntoBuff(zip4jRaf, shortBuff);
int commentLength = Raw.readShortLittleEndian(shortBuff, 0);
endCentralDirRecord.setCommentLength(commentLength);
//.ZIP file comment
if (commentLength > 0) {
byte[] commentBuf = new byte[commentLength];
readIntoBuff(zip4jRaf, commentBuf);
endCentralDirRecord.setComment(new String(commentBuf));
endCentralDirRecord.setCommentBytes(commentBuf);
} else {
endCentralDirRecord.setComment(null);
}
int diskNumber = endCentralDirRecord.getNoOfThisDisk();
if (diskNumber > 0) {
zipModel.setSplitArchive(true);
} else {
zipModel.setSplitArchive(false);
}
return endCentralDirRecord;
} catch (IOException e) {
throw new ZipException("Probably not a zip file or a corrupted zip file", e, ZipExceptionConstants.notZipFile);
}
}