本文整理了Java中org.geoserver.util.IOUtils.zipDirectory()
方法的一些代码示例,展示了IOUtils.zipDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.zipDirectory()
方法的具体详情如下:
包路径:org.geoserver.util.IOUtils
类名称:IOUtils
方法名:zipDirectory
[英]See #zipDirectory(File,ZipOutputStream,FilenameFilter), this version handles the prefix needed to recursively zip data preserving the relative path of each
[中]请参阅#zipDirectory(File、ZipOutputStream、FilenameFilter),此版本处理递归压缩数据所需的前缀,保留每个文件的相对路径
代码示例来源:origin: geoserver/geoserver
/**
* Zips up the directory contents into the specified {@link ZipOutputStream}.
*
* <p>Note this method does not take ownership of the provided zip output stream, meaning the
* client code is responsible for calling {@link ZipOutputStream#finish() finish()} when it's
* done adding zip entries.
*
* @param directory The directory whose contents have to be zipped up
* @param zipout The {@link ZipOutputStream} that will be populated by the files found
* @param filter An optional filter that can be used to select only certain files. Can be null,
* in that case all files in the directory will be zipped
* @throws IOException
* @throws FileNotFoundException
*/
public static void zipDirectory(
File directory, ZipOutputStream zipout, final FilenameFilter filter)
throws IOException, FileNotFoundException {
zipDirectory(directory, "", zipout, filter);
}
代码示例来源:origin: geoserver/geoserver
zipDirectory(file, newPrefix, zipout, filter);
} else {
ZipEntry entry = new ZipEntry(prefix + file.getName());
代码示例来源:origin: geoserver/geoserver
@Test
public void testZipUnzip() throws IOException {
Path p1 = temp.newFolder("d1").toPath();
p1.resolve("foo/bar").toFile().mkdirs();
Files.touch(p1.resolve("foo/bar/bar.txt").toFile());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ZipOutputStream zout = new ZipOutputStream(bout);
IOUtils.zipDirectory(p1.toFile(), zout, null);
Path p2 = temp.newFolder("d2").toPath();
p2.toFile().mkdirs();
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
IOUtils.decompress(bin, p2.toFile());
assertTrue(p2.resolve("foo/bar/bar.txt").toFile().exists());
}
代码示例来源:origin: org.geoserver.extension/gs-h2
/** Helper method that zips the H2 data directory and returns it as an array of bytes. */
private static byte[] readSqLiteDatabaseDir() throws Exception {
// copy database file to database directory
File outputFile = new File(DATABASE_DIR, "test-database.data.db");
InputStream input = RestTest.class.getResourceAsStream("/test-database.data.db");
IOUtils.copy(input, new FileOutputStream(outputFile));
// zip the database directory
ByteArrayOutputStream output = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(output);
// ignore the lock files
IOUtils.zipDirectory(
DATABASE_DIR, zip, (dir, name) -> !name.toLowerCase().contains("lock"));
zip.close();
// just return the output stream content
return output.toByteArray();
}
}
代码示例来源:origin: org.geoserver/gs-platform
@Test
public void testZipUnzip() throws IOException {
Path p1 = temp.newFolder("d1").toPath();
p1.resolve("foo/bar").toFile().mkdirs();
Files.touch(p1.resolve("foo/bar/bar.txt").toFile());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ZipOutputStream zout = new ZipOutputStream(bout);
IOUtils.zipDirectory(p1.toFile(), zout, null);
Path p2 = temp.newFolder("d2").toPath();
p2.toFile().mkdirs();
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
IOUtils.decompress(bin, p2.toFile());
assertTrue(p2.resolve("foo/bar/bar.txt").toFile().exists());
}
代码示例来源:origin: org.geoserver/gs-wfs
IOUtils.zipDirectory(tempDir, zipOut, filter);
zipOut.finish();
内容来源于网络,如有侵权,请联系作者删除!