Search in sources :

Example 1 with IContentFile

use of org.polymap.service.fs.spi.IContentFile in project polymap4-core by Polymap4.

the class FsContentProvider method createNew.

/**
 * Creates a new file for the given input.
 * @param fsFolder
 *
 * @param newName
 * @param in
 * @return Newly created {@link FsFile} reflecting the created file.
 */
public IContentFile createNew(FsFolder folder, String newName, InputStream in) throws IOException, NotAuthorizedException, BadRequestException {
    assert newName != null;
    OutputStream fileOut = null;
    try {
        File f = new File(folder.getDir(), newName);
        boolean isNewFile = !f.exists();
        fileOut = new FileOutputStream(f);
        IOUtils.copy(in, fileOut);
        // reload folder if file was created
        if (isNewFile) {
            getSite().invalidateFolder(folder);
        }
        return new FsFile(folder.getPath(), this, f);
    } finally {
        IOUtils.closeQuietly(fileOut);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IContentFile(org.polymap.service.fs.spi.IContentFile) File(java.io.File)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 IContentFile (org.polymap.service.fs.spi.IContentFile)1