Search in sources :

Example 1 with CopyVisitor

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);
        }
    }
}
Also used : Path(java.nio.file.Path) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CopyVisitor(org.olat.core.util.PathUtils.CopyVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) YesMatcher(org.olat.core.util.PathUtils.YesMatcher) FileInputStream(java.io.FileInputStream)

Example 2 with CopyVisitor

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;
    }
}
Also used : Path(java.nio.file.Path) CopyVisitor(org.olat.core.util.PathUtils.CopyVisitor) IOException(java.io.IOException)

Example 3 with CopyVisitor

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;
    }
}
Also used : Path(java.nio.file.Path) CopyVisitor(org.olat.core.util.PathUtils.CopyVisitor) IOException(java.io.IOException)

Example 4 with CopyVisitor

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);
        }
    }
}
Also used : Path(java.nio.file.Path) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CopyVisitor(org.olat.core.util.PathUtils.CopyVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) YesMatcher(org.olat.core.util.PathUtils.YesMatcher) FileInputStream(java.io.FileInputStream)

Aggregations

IOException (java.io.IOException)4 Path (java.nio.file.Path)4 CopyVisitor (org.olat.core.util.PathUtils.CopyVisitor)4 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 YesMatcher (org.olat.core.util.PathUtils.YesMatcher)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2