Search in sources :

Example 6 with LocalImpl

use of org.olat.core.util.vfs.LocalImpl in project OpenOLAT by OpenOLAT.

the class DataStepForm method isSame.

private boolean isSame(VFSItem currentTarget, File uploadedFile) {
    if (currentTarget instanceof LocalImpl) {
        LocalImpl local = (LocalImpl) currentTarget;
        File currentFile = local.getBasefile();
        if (currentFile.length() == uploadedFile.length()) {
            try {
                return org.apache.commons.io.FileUtils.contentEquals(currentFile, uploadedFile);
            } catch (IOException e) {
                logError("", e);
            // do nothing -> return false at the end
            }
        }
    }
    return false;
}
Also used : IOException(java.io.IOException) LocalImpl(org.olat.core.util.vfs.LocalImpl) File(java.io.File)

Example 7 with LocalImpl

use of org.olat.core.util.vfs.LocalImpl in project openolat by klemens.

the class WebDocumentRunController method getWebDocument.

private LocalFileImpl getWebDocument(RepositoryEntry entry) {
    OLATResource resource = entry.getOlatResource();
    VFSContainer fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
    LocalFileImpl document = null;
    for (VFSItem item : fResourceFileroot.getItems()) {
        if (item instanceof VFSLeaf && item instanceof LocalImpl) {
            LocalFileImpl localItem = (LocalFileImpl) item;
            if (localItem != null && !localItem.getBasefile().isHidden()) {
                document = (LocalFileImpl) item;
            }
        }
    }
    return document;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VFSItem(org.olat.core.util.vfs.VFSItem) LocalImpl(org.olat.core.util.vfs.LocalImpl)

Example 8 with LocalImpl

use of org.olat.core.util.vfs.LocalImpl in project openolat by klemens.

the class DataStepForm method isSame.

private boolean isSame(VFSItem currentTarget, File uploadedFile) {
    if (currentTarget instanceof LocalImpl) {
        LocalImpl local = (LocalImpl) currentTarget;
        File currentFile = local.getBasefile();
        if (currentFile.length() == uploadedFile.length()) {
            try {
                return org.apache.commons.io.FileUtils.contentEquals(currentFile, uploadedFile);
            } catch (IOException e) {
                logError("", e);
            // do nothing -> return false at the end
            }
        }
    }
    return false;
}
Also used : IOException(java.io.IOException) LocalImpl(org.olat.core.util.vfs.LocalImpl) File(java.io.File)

Example 9 with LocalImpl

use of org.olat.core.util.vfs.LocalImpl in project openolat by klemens.

the class WorkThreadInformations method setInfoFiles.

public static void setInfoFiles(String filePath, VFSLeaf leaf) {
    try {
        File file = new File(WebappHelper.getUserDataRoot(), "threadInfos");
        if (!file.exists()) {
            file.mkdirs();
        }
        if (leaf instanceof LocalImpl) {
            filePath = ((LocalImpl) leaf).getBasefile().getAbsolutePath();
        }
        File infoFile = new File(file, Thread.currentThread().getName());
        FileUtils.save(infoFile, filePath, "UTF-8");
    } catch (Exception e) {
        log.error("Cannot write info message about FolderIndexerWorker: " + filePath, e);
    }
}
Also used : LocalImpl(org.olat.core.util.vfs.LocalImpl) File(java.io.File)

Example 10 with LocalImpl

use of org.olat.core.util.vfs.LocalImpl in project openolat by klemens.

the class ZipUtil method addToZip.

public static boolean addToZip(VFSItem vfsItem, String currentPath, ZipOutputStream out) {
    boolean success = true;
    InputStream in = null;
    byte[] buffer = new byte[FileUtils.BSIZE];
    try {
        // The separator / is the separator defined by the ZIP standard
        String itemName = currentPath.length() == 0 ? vfsItem.getName() : currentPath + "/" + vfsItem.getName();
        if (vfsItem instanceof VFSContainer) {
            out.putNextEntry(new ZipEntry(itemName + "/"));
            out.closeEntry();
            List<VFSItem> items = ((VFSContainer) vfsItem).getItems();
            for (Iterator<VFSItem> iter = items.iterator(); iter.hasNext(); ) {
                if (!addToZip(iter.next(), itemName, out)) {
                    success = false;
                    break;
                }
            }
        } else {
            out.putNextEntry(new ZipEntry(itemName));
            in = ((VFSLeaf) vfsItem).getInputStream();
            int c;
            while ((c = in.read(buffer, 0, buffer.length)) != -1) {
                out.write(buffer, 0, c);
            }
            out.closeEntry();
        }
    } catch (IOException ioe) {
        String name = vfsItem.getName();
        if (vfsItem instanceof LocalImpl) {
            name = ((LocalImpl) vfsItem).getBasefile().getAbsolutePath();
        }
        log.error("I/O error while adding " + name + " to zip:" + ioe);
        return false;
    } finally {
        FileUtils.closeSafely(in);
    }
    return success;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) ZipEntry(java.util.zip.ZipEntry) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) LocalImpl(org.olat.core.util.vfs.LocalImpl)

Aggregations

LocalImpl (org.olat.core.util.vfs.LocalImpl)18 File (java.io.File)10 IOException (java.io.IOException)10 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 BufferedOutputStream (java.io.BufferedOutputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 BufferedInputStream (java.io.BufferedInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 FileChoosenEvent (org.olat.core.commons.controllers.filechooser.FileChoosenEvent)2 Translator (org.olat.core.gui.translator.Translator)2 AssertException (org.olat.core.logging.AssertException)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2