Search in sources :

Example 1 with HttpServletResponseOutputStream

use of org.olat.core.util.io.HttpServletResponseOutputStream in project OpenOLAT by OpenOLAT.

the class RepositoryEntryImportExport method exportDoExportContent.

/**
 * Export a repository entry referenced by a course node to the given export directory.
 * User importReferencedRepositoryEntry to import again.
 * @return True upon success, false otherwise.
 */
public boolean exportDoExportContent() {
    // export resource
    RepositoryHandler rh = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    MediaResource mr = rh.getAsMediaResource(re.getOlatResource(), false);
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(new File(baseDirectory, CONTENT_FILE));
        InputStream in = mr.getInputStream();
        if (in == null) {
            HttpServletResponse hres = new HttpServletResponseOutputStream(fOut);
            mr.prepare(hres);
        } else {
            IOUtils.copy(mr.getInputStream(), fOut);
        }
        fOut.flush();
    } catch (IOException fnfe) {
        return false;
    } finally {
        IOUtils.closeQuietly(fOut);
        mr.release();
    }
    return true;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) HttpServletResponseOutputStream(org.olat.core.util.io.HttpServletResponseOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 2 with HttpServletResponseOutputStream

use of org.olat.core.util.io.HttpServletResponseOutputStream in project openolat by klemens.

the class RepositoryEntryImportExport method exportDoExportContent.

/**
 * Export a repository entry referenced by a course node to the given export directory.
 * User importReferencedRepositoryEntry to import again.
 * @return True upon success, false otherwise.
 */
public boolean exportDoExportContent() {
    // export resource
    RepositoryHandler rh = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    MediaResource mr = rh.getAsMediaResource(re.getOlatResource(), false);
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(new File(baseDirectory, CONTENT_FILE));
        InputStream in = mr.getInputStream();
        if (in == null) {
            HttpServletResponse hres = new HttpServletResponseOutputStream(fOut);
            mr.prepare(hres);
        } else {
            IOUtils.copy(mr.getInputStream(), fOut);
        }
        fOut.flush();
    } catch (IOException fnfe) {
        return false;
    } finally {
        IOUtils.closeQuietly(fOut);
        mr.release();
    }
    return true;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) HttpServletResponseOutputStream(org.olat.core.util.io.HttpServletResponseOutputStream) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MediaResource (org.olat.core.gui.media.MediaResource)2 HttpServletResponseOutputStream (org.olat.core.util.io.HttpServletResponseOutputStream)2 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)2