本文整理了Java中org.geoserver.util.IOUtils.getZipOutputFile()
方法的一些代码示例,展示了IOUtils.getZipOutputFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getZipOutputFile()
方法的具体详情如下:
包路径:org.geoserver.util.IOUtils
类名称:IOUtils
方法名:getZipOutputFile
[英]Gets the output file for the provided zip entry and checks that it will not be written outside of the target directory.
[中]获取提供的zip项的输出文件,并检查它是否不会写入目标目录之外。
代码示例来源:origin: geoserver/geoserver
public static void decompress(InputStream input, File destDir) throws IOException {
ZipInputStream zin = new ZipInputStream(input);
ZipEntry entry = null;
byte[] buffer = new byte[1024];
while ((entry = zin.getNextEntry()) != null) {
File f = getZipOutputFile(destDir, entry);
if (entry.isDirectory()) {
f.mkdirs();
continue;
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
int n = -1;
while ((n = zin.read(buffer)) != -1) {
out.write(buffer, 0, n);
}
out.flush();
out.close();
}
}
代码示例来源:origin: geoserver/geoserver
public static void decompress(final File inputFile, final File destDir) throws IOException {
try (ZipFile zipFile = new ZipFile(inputFile)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File newFile = getZipOutputFile(destDir, entry);
if (entry.isDirectory()) {
// Assume directories are stored parents first then children.
newFile.mkdir();
continue;
}
InputStream stream = zipFile.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(newFile);
try {
byte[] buf = new byte[1024];
int len;
while ((len = stream.read(buf)) >= 0) saveCompressedStream(buf, fos, len);
} catch (IOException e) {
IOException ioe = new IOException("Not valid archive file type.");
ioe.initCause(e);
throw ioe;
} finally {
fos.flush();
fos.close();
stream.close();
}
}
}
}
代码示例来源:origin: org.geoserver.extension/gs-wps-core
File file = IOUtils.getZipOutputFile(tempDir, entry);
if (entry.isDirectory()) {
file.mkdir();
代码示例来源:origin: org.geoserver/gs-rest
/**
* Simple class implementing a periodic Thread that periodically tries to delete the files that
* were provided to him.
*
* <p>It tries to delete each file at most {@link FileCleaner#maxAttempts} number of times. If
* this number is exceeded it simply throws the file away notifying the users with a warning
* message.
*
* @author Simone Giannecchini, GeoSolutions.
*/
public static final class FileCleaner extends Thread {
/**
* Maximum number of attempts to delete a given {@link File}.
*
* <p>If the provided number of attempts is exceeded we simply drop warn the user and we
* remove the {@link File} from our list.
*/
private int maxAttempts = DEF_MAX_ATTEMPTS;
/** Period in seconds between two checks. */
private volatile long period = DEFAULT_PERIOD;
/**
* Asks this {@link FileCleaner} to clean up this file.
*
* @param fileToDelete {@link File} that we want to permanently delete.
*/
public void addFile(final File fileToDelete) {
// does it exists
内容来源于网络,如有侵权,请联系作者删除!