当前位置: 首页>>代码示例>>Java>>正文


Java ZipError类代码示例

本文整理汇总了Java中java.util.zip.ZipError的典型用法代码示例。如果您正苦于以下问题:Java ZipError类的具体用法?Java ZipError怎么用?Java ZipError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ZipError类属于java.util.zip包,在下文中一共展示了ZipError类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newFileSystem

import java.util.zip.ZipError; //导入依赖的package包/类
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env)
    throws IOException
{
    Path path = uriToPath(uri);
    synchronized(filesystems) {
        Path realPath = null;
        if (ensureFile(path)) {
            realPath = path.toRealPath();
            if (filesystems.containsKey(realPath))
                throw new FileSystemAlreadyExistsException();
        }
        ZipFileSystem zipfs = null;
        try {
            zipfs = new ZipFileSystem(this, path, env);
        } catch (ZipError ze) {
            String pname = path.toString();
            if (pname.endsWith(".zip") || pname.endsWith(".jar"))
                throw ze;
            // assume NOT a zip/jar file
            throw new UnsupportedOperationException();
        }
        filesystems.put(realPath, zipfs);
        return zipfs;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ZipFileSystemProvider.java

示例2: getZipMembers

import java.util.zip.ZipError; //导入依赖的package包/类
/**
 * Gets a set of files that are contained in an archive
 *
 * @param archiveAbsolutePath The absolute path to the archive
 * @return A set of files (not directories) that are contained in the zip file
 * @throws IOException If there is an error reading the archive
 */
public static ImmutableSet<Path> getZipMembers(Path archiveAbsolutePath) throws IOException {
  try (FileSystem zipFs = FileSystems.newFileSystem(archiveAbsolutePath, null)) {
    Path root = Iterables.getOnlyElement(zipFs.getRootDirectories());
    return Files.walk(root)
        .filter(path -> !Files.isDirectory(path))
        .map(root::relativize)
        .map(path -> Paths.get(path.toString())) // Clear the filesystem from the path
        .collect(ImmutableSet.toImmutableSet());
  } catch (ZipError error) {
    // For some reason the zip filesystem support throws an error when an IOException would do
    // just as well.
    throw new IOException(
        String.format("Could not read %s because of %s", archiveAbsolutePath, error.toString()),
        error);
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:24,代码来源:Unzip.java

示例3: zerror

import java.util.zip.ZipError; //导入依赖的package包/类
static void zerror(String msg) {
    throw new ZipError(msg);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:ZipFileSystem.java

示例4: probeContentType

import java.util.zip.ZipError; //导入依赖的package包/类
@Override
public String probeContentType(Path path) throws IOException {

	ByteBuffer buf = ByteBuffer.allocate(256);
	try (SeekableByteChannel byteChannel = Files.newByteChannel(path,
			StandardOpenOption.READ)) {
		int read = byteChannel.read(buf);
		if (read < 38) {
			return null;
		}
		;
	}
	buf.flip();

	// Look for PK

	byte[] firstBytes = buf.array();
	String pk = new String(firstBytes, 0, 2, LATIN1);
	if (!(pk.equals("PK") && firstBytes[2] == 3 && firstBytes[3] == 4)) {
		// Did not match magic numbers of ZIP as specified in ePub OCF
		// http://www.idpf.org/epub/30/spec/epub30-ocf.html#app-media-type
		return null;
	}

	String mimetype = new String(firstBytes, 30, 8, LATIN1);
	if (!mimetype.equals(MIMETYPE)) {
		return APPLICATION_ZIP;
	}
	// Read the 'mimetype' file.
	try (ZipInputStream is = new ZipInputStream(new ByteArrayInputStream(
			firstBytes))) {
		ZipEntry entry = is.getNextEntry();
		if (!MIMETYPE.equals(entry.getName())) {
			return APPLICATION_ZIP;
		}
		byte[] mediaTypeBuffer = new byte[256];
		int size = is.read(mediaTypeBuffer);
		if (size < 1) {
			return APPLICATION_ZIP;
		}
		return new String(mediaTypeBuffer, 0, size, ASCII);
	} catch (ZipException | ZipError e) {
		return null;
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:46,代码来源:BundleFileTypeDetector.java

示例5: exitOnJvmError

import java.util.zip.ZipError; //导入依赖的package包/类
public static FatalErrorHandler exitOnJvmError() {
	return exitOnMatchedError(singletonList(Error.class), asList(AssertionError.class, StackOverflowError.class, IOError.class, ZipError.class));
}
 
开发者ID:softindex,项目名称:datakernel,代码行数:4,代码来源:FatalErrorHandlers.java

示例6: test_constructor

import java.util.zip.ZipError; //导入依赖的package包/类
/**
 * @tests {@link java.util.zip.ZipError#ZipError(String)}
 */
public void test_constructor() {
    ZipError error = new ZipError("ZipError");
    assertEquals("ZipError", error.getMessage());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:ZipErrorTest.java

示例7: test_serialization

import java.util.zip.ZipError; //导入依赖的package包/类
/**
 * @tests java.util.zip.ZipError#Serialization()
 */
public void test_serialization() throws Exception {
    ZipError error = new ZipError("serialization test");
    SerializationTest.verifySelf(error);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:ZipErrorTest.java

示例8: testSerializationCompatibility

import java.util.zip.ZipError; //导入依赖的package包/类
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {
    ZipError error = new ZipError("serialization test");
    SerializationTest.verifyGolden(this, error);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:8,代码来源:ZipErrorTest.java


注:本文中的java.util.zip.ZipError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。