本文整理汇总了Java中java.util.zip.ZipException类的典型用法代码示例。如果您正苦于以下问题:Java ZipException类的具体用法?Java ZipException怎么用?Java ZipException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZipException类属于java.util.zip包,在下文中一共展示了ZipException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGameFileFromFile
import java.util.zip.ZipException; //导入依赖的package包/类
private static GameFile getGameFileFromFile(String file) throws JAXBException, IOException {
final JAXBContext jaxbContext = JAXBContext.newInstance(GameFile.class);
final Unmarshaller um = jaxbContext.createUnmarshaller();
try (InputStream inputStream = FileUtilities.getGameResource(file)) {
// try to get compressed game file
final GZIPInputStream zipStream = new GZIPInputStream(inputStream);
return (GameFile) um.unmarshal(zipStream);
} catch (final ZipException e) {
// if it fails to load the compressed file, get it from plain XML
InputStream stream = null;
stream = FileUtilities.getGameResource(file);
if (stream == null) {
return null;
}
return (GameFile) um.unmarshal(stream);
}
}
示例2: newFileSystem
import java.util.zip.ZipException; //导入依赖的package包/类
@Override
public FileSystem newFileSystem(Path path, Map<String, ?> env)
throws IOException
{
if (path.getFileSystem() != FileSystems.getDefault()) {
throw new UnsupportedOperationException();
}
ensureFile(path);
try {
ZipFileSystem zipfs;
if (env.containsKey("multi-release")) {
zipfs = new JarFileSystem(this, path, env);
} else {
zipfs = new ZipFileSystem(this, path, env);
}
return zipfs;
} catch (ZipException ze) {
String pname = path.toString();
if (pname.endsWith(".zip") || pname.endsWith(".jar"))
throw ze;
throw new UnsupportedOperationException();
}
}
示例3: EntryInputStream
import java.util.zip.ZipException; //导入依赖的package包/类
EntryInputStream(Entry e, SeekableByteChannel zfch)
throws IOException
{
this.zfch = zfch;
rem = e.csize;
size = e.size;
pos = e.locoff;
if (pos == -1) {
Entry e2 = getEntry(e.name);
if (e2 == null) {
throw new ZipException("invalid loc for entry <" + e.name + ">");
}
pos = e2.locoff;
}
pos = -pos; // lazy initialize the real data offset
}
示例4: load
import java.util.zip.ZipException; //导入依赖的package包/类
private QubbleModel load(File file) throws IOException
{
try (ZipFile zipFile = new ZipFile(file))
{
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
if (entry.getName().equals("model.nbt"))
{
NBTTagCompound compound = CompressedStreamTools.read(new DataInputStream(zipFile.getInputStream(entry)));
return QubbleModel.deserialize(compound);
}
}
}
catch (ZipException zipException)
{
return this.loadLegacy(file);
}
return null;
}
示例5: jar
import java.util.zip.ZipException; //导入依赖的package包/类
private void jar(String cmdline) throws IOException {
System.out.println("jar " + cmdline);
baos.reset();
// the run method catches IOExceptions, we need to expose them
ByteArrayOutputStream baes = new ByteArrayOutputStream();
PrintStream err = new PrintStream(baes);
PrintStream saveErr = System.err;
System.setErr(err);
int rc = JAR_TOOL.run(out, err, cmdline.split(" +"));
System.setErr(saveErr);
if (rc != 0) {
String s = baes.toString();
if (s.startsWith("java.util.zip.ZipException: duplicate entry: ")) {
throw new ZipException(s);
}
throw new IOException(s);
}
}
示例6: findCentralDirectory
import java.util.zip.ZipException; //导入依赖的package包/类
static CentralDirectory findCentralDirectory(RandomAccessFile raf) throws IOException, ZipException {
long scanOffset = raf.length() - 22;
if (scanOffset < 0) {
throw new ZipException("File too short to be a zip file: " + raf.length());
}
long stopOffset = scanOffset - 65536;
if (stopOffset < 0) {
stopOffset = 0;
}
int endSig = Integer.reverseBytes(ENDSIG);
do {
raf.seek(scanOffset);
if (raf.readInt() == endSig) {
raf.skipBytes(2);
raf.skipBytes(2);
raf.skipBytes(2);
raf.skipBytes(2);
CentralDirectory dir = new CentralDirectory();
dir.size = ((long) Integer.reverseBytes(raf.readInt())) & 4294967295L;
dir.offset = ((long) Integer.reverseBytes(raf.readInt())) & 4294967295L;
return dir;
}
scanOffset--;
} while (scanOffset >= stopOffset);
throw new ZipException("End Of Central Directory signature not found");
}
示例7: exception
import java.util.zip.ZipException; //导入依赖的package包/类
@Override
public final void exception()
{
Exception ex = getException();
if( ex instanceof BannedFileException )
{
Driver.displayInformation(getComponent(), "File upload cancelled. File extension has been banned.");
}
else if( ex instanceof FileNotFoundException )
{
Driver.displayError(getComponent(), "displayTemplate/readingXSLT", ex); //$NON-NLS-1$
LOGGER.error("Error opening XSLT or clearing staging", ex);
}
else if( ex instanceof ZipException )
{
Driver.displayError(getComponent(), "displayTemplate/unzippingXSLT", ex); //$NON-NLS-1$
LOGGER.error("Error unzippig XSLT", ex);
}
else
{
Driver.displayError(getComponent(), "displayTemplate/uploadingXSLT", ex); //$NON-NLS-1$
LOGGER.error("Error uploading XSLT", ex);
}
}
示例8: readBytes
import java.util.zip.ZipException; //导入依赖的package包/类
private byte[] readBytes(Entry entry) throws IOException {
byte[] header = getHeader(entry);
int csize = entry.compressedSize;
byte[] cbuf = new byte[csize];
zipRandomFile.skipBytes(get2ByteLittleEndian(header, 26) + get2ByteLittleEndian(header, 28));
zipRandomFile.readFully(cbuf, 0, csize);
// is this compressed - offset 8 in the ZipEntry header
if (get2ByteLittleEndian(header, 8) == 0)
return cbuf;
int size = entry.size;
byte[] buf = new byte[size];
if (inflate(cbuf, buf) != size)
throw new ZipException("corrupted zip file");
return buf;
}
示例9: deleteFile
import java.util.zip.ZipException; //导入依赖的package包/类
public void deleteFile(byte[] path, boolean failIfNotExists)
throws IOException
{
checkWritable();
IndexNode inode = getInode(path);
if (inode == null) {
if (path != null && path.length == 0)
throw new ZipException("root directory </> can't not be delete");
if (failIfNotExists)
throw new NoSuchFileException(getString(path));
} else {
if (inode.isDir() && inode.child != null)
throw new DirectoryNotEmptyException(getString(path));
updateDelete(inode);
}
}
示例10: write
import java.util.zip.ZipException; //导入依赖的package包/类
@Override
public void write(byte b[], int off, int len) throws IOException {
if (e.type != Entry.FILECH) // only from sync
ensureOpen();
if (off < 0 || len < 0 || off > b.length - len) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
switch (e.method) {
case METHOD_DEFLATED:
super.write(b, off, len);
break;
case METHOD_STORED:
written += len;
out.write(b, off, len);
break;
default:
throw new ZipException("invalid compression method");
}
crc.update(b, off, len);
}
示例11: getEntriesNames
import java.util.zip.ZipException; //导入依赖的package包/类
/**
* 获得压缩文件内文件列表
*
* @param zipFile 压缩文件
* @return 压缩文件内文件名称
* @throws ZipException 压缩文件格式有误时抛出
* @throws IOException 当解压缩过程出错时抛出
*/
public static ArrayList<String> getEntriesNames(File zipFile) throws ZipException, IOException {
ArrayList<String> entryNames = new ArrayList<String>();
Enumeration<?> entries = getEntriesEnumeration(zipFile);
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
entryNames.add(new String(getEntryName(entry).getBytes("GB2312"), "8859_1"));
}
return entryNames;
}
示例12: exists
import java.util.zip.ZipException; //导入依赖的package包/类
@Override
public boolean exists() throws IOException, ZipException {
ZipFile zip = new ZipFile(this.archive.getSimulationArchiveFile());
ZipEntry entry = zip.getEntry(targetId + "/");
if (entry != null) {
return true;
}
return false;
}
示例13: throwZipException
import java.util.zip.ZipException; //导入依赖的package包/类
static void throwZipException(String filename, long fileSize, String entryName, long localHeaderRelOffset, String msg, int magic) throws ZipException {
final String hexString = Integer.toHexString(magic);
throw new ZipException("file name:" + filename
+ ", file size" + fileSize
+ ", entry name:" + entryName
+ ", entry localHeaderRelOffset:" + localHeaderRelOffset
+ ", "
+ msg + " signature not found; was " + hexString);
}
示例14: getDataPos
import java.util.zip.ZipException; //导入依赖的package包/类
private long getDataPos(Entry e) throws IOException {
if (e.locoff == -1) {
Entry e2 = getEntry0(e.name);
if (e2 == null)
throw new ZipException("invalid loc for entry <" + e.name + ">");
e.locoff = e2.locoff;
}
byte[] buf = new byte[LOCHDR];
if (readFullyAt(buf, 0, buf.length, e.locoff) != buf.length)
throw new ZipException("invalid loc for entry <" + e.name + ">");
return locpos + e.locoff + LOCHDR + LOCNAM(buf) + LOCEXT(buf);
}
示例15: data
import java.util.zip.ZipException; //导入依赖的package包/类
/**
* Generates collection of ZipEntry instances that will be used as data provided parameter is mapped to name of the
* test (takes advantage of fact that ZipEntry.toString() is the same as entry.getName())
*
* @see TestCodeProvider#getDataFromZippedRoot(String, JSLibSingleTestConfigProvider)
* @return a collection of pairs {@link ZipEntry} -> blacklist
*/
@Parameters(name = "{0}")
public static Collection<JSLibSingleTestConfig> data() throws URISyntaxException, ZipException, IOException {
return TestCodeProvider.getDataFromZippedRoots(ECMASCRIPT_TEST_SUITE_ARCHIVE,
new ECMAScriptSingleTestConfigProvider(
REQUIRE_VALIDATOR_FILENAME,
REQUIRE_VALIDATOR_TODO_FILENAME,
BLACKLIST_FILENAME,
BLACKLIST_EXECUTION_FILENAME, BLACKLIST_STRICT_MODE_FILENAME));
}