use of org.olat.core.util.PathUtils.CopyVisitor in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processItemFiles.
/**
* Process the file of an item's package
* @param item
* @param itemInfos
*/
protected void processItemFiles(QuestionItemImpl item, DocInfos docInfos) {
// a package with an item
String dir = item.getDirectory();
String rootFilename = item.getRootFilename();
VFSContainer container = qpoolFileStorage.getContainer(dir);
if (docInfos != null && docInfos.getRoot() != null) {
try {
Path destDir = ((LocalImpl) container).getBasefile().toPath();
// unzip to container
Path path = docInfos.getRoot();
Files.walkFileTree(path, new CopyVisitor(path, destDir, new YesMatcher()));
} catch (IOException e) {
log.error("", e);
}
} else if (importedFilename.toLowerCase().endsWith(".zip")) {
ZipUtil.unzipStrict(importedFile, container);
} else {
VFSLeaf endFile = container.createChildLeaf(rootFilename);
OutputStream out = null;
FileInputStream in = null;
try {
out = endFile.getOutputStream(false);
in = new FileInputStream(importedFile);
IOUtils.copy(in, out);
} catch (IOException e) {
log.error("", e);
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
}
}
}
use of org.olat.core.util.PathUtils.CopyVisitor in project openolat by klemens.
the class FileResource method copyResource.
public static boolean copyResource(File file, String filename, File targetDirectory, PathMatcher filter) {
try {
Path path = getResource(file, filename);
if (path == null) {
return false;
}
Path destDir = targetDirectory.toPath();
Files.walkFileTree(path, new CopyVisitor(path, destDir, filter));
PathUtils.closeSubsequentFS(path);
return true;
} catch (IOException e) {
log.error("", e);
return false;
}
}
use of org.olat.core.util.PathUtils.CopyVisitor in project OpenOLAT by OpenOLAT.
the class FileResource method copyResource.
public static boolean copyResource(File file, String filename, File targetDirectory, PathMatcher filter) {
try {
Path path = getResource(file, filename);
if (path == null) {
return false;
}
Path destDir = targetDirectory.toPath();
Files.walkFileTree(path, new CopyVisitor(path, destDir, filter));
PathUtils.closeSubsequentFS(path);
return true;
} catch (IOException e) {
log.error("", e);
return false;
}
}
use of org.olat.core.util.PathUtils.CopyVisitor in project openolat by klemens.
the class QTIImportProcessor method processItemFiles.
/**
* Process the file of an item's package
* @param item
* @param itemInfos
*/
protected void processItemFiles(QuestionItemImpl item, DocInfos docInfos) {
// a package with an item
String dir = item.getDirectory();
String rootFilename = item.getRootFilename();
VFSContainer container = qpoolFileStorage.getContainer(dir);
if (docInfos != null && docInfos.getRoot() != null) {
try {
Path destDir = ((LocalImpl) container).getBasefile().toPath();
// unzip to container
Path path = docInfos.getRoot();
Files.walkFileTree(path, new CopyVisitor(path, destDir, new YesMatcher()));
} catch (IOException e) {
log.error("", e);
}
} else if (importedFilename.toLowerCase().endsWith(".zip")) {
ZipUtil.unzipStrict(importedFile, container);
} else {
VFSLeaf endFile = container.createChildLeaf(rootFilename);
OutputStream out = null;
FileInputStream in = null;
try {
out = endFile.getOutputStream(false);
in = new FileInputStream(importedFile);
IOUtils.copy(in, out);
} catch (IOException e) {
log.error("", e);
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
}
}
}
Aggregations