本文整理汇总了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;
}
}
示例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);
}
}
示例3: zerror
import java.util.zip.ZipError; //导入依赖的package包/类
static void zerror(String msg) {
throw new ZipError(msg);
}
示例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;
}
}
示例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));
}
示例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());
}
示例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);
}
示例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);
}