當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipException類代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:21,代碼來源:GameFile.java

示例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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ZipFileSystemProvider.java

示例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
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ZipFileSystem.java

示例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;
}
 
開發者ID:ObsidianSuite,項目名稱:ObsidianSuite,代碼行數:25,代碼來源:ImporterQubble.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:InputFilesTest.java

示例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");
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:27,代碼來源:ZipUtil.java

示例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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:25,代碼來源:CalConfigPanel.java

示例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;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:19,代碼來源:ZipFileIndex.java

示例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);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:ZipFileSystem.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:ZipFileSystem.java

示例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;
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:18,代碼來源:ZipUtils.java

示例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;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:10,代碼來源:SimulationEntryImpl.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:TinkerZipFile.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:ZipFileSystem.java

示例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));
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:17,代碼來源:ECMA6TestSuite.java


注:本文中的java.util.zip.ZipException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。