Example usage for org.apache.commons.vfs FileObject getContent

List of usage examples for org.apache.commons.vfs FileObject getContent

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getContent.

Prototype

public FileContent getContent() throws FileSystemException;

Source Link

Document

Returns this file's content.

Usage

From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java

public void testFileHasLastModifiedTimestamp() throws FileSystemException {
    FileObject object = ROOT.resolveFile(FILE);
    object.getContent().getLastModifiedTime();
}

From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java

public void testGetLastModifiedTimeFile() throws FileSystemException {
    FileObject object = ROOT.resolveFile(FILE);
    object.getContent().getLastModifiedTime();
}

From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java

public void testGetLastModifiedTimeFolder() throws FileSystemException {
    FileObject object = ROOT.resolveFile(FOLDER);
    object.getContent().getLastModifiedTime();
}

From source file:com.thinkberg.webdav.GetHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }/*from w ww.  ja  v a 2s  . c o m*/

        setHeader(response, object.getContent());

        InputStream is = object.getContent().getInputStream();
        OutputStream os = response.getOutputStream();
        Util.copyStream(is, os);
        is.close();
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:com.thinkberg.moxo.dav.GetHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }//from w w w. j av a  2s. c om

        setHeader(response, object.getContent());

        InputStream is = object.getContent().getInputStream();
        OutputStream os = response.getOutputStream();
        Util.copyStream(is, os);
        is.close();
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:com.sonatype.nexus.plugin.groovyconsole.DefaultScriptStorage.java

private void updateScript(FileObject file) {
    FileName name = file.getName();/*from   w  w w .j  av a2s .  c o m*/
    getLogger().info("New script file found: " + name);

    String script;
    try {
        FileContent content = file.getContent();
        script = IOUtils.toString(content.getInputStream());
        content.close();
    } catch (IOException e) {
        getLogger().warn("Unable to read script file: " + name, e);
        return;
    }

    synchronized (scripts) {
        scripts.put(getName(name), script);
    }
}

From source file:de.ecclesia.kipeto.RepositoryResolver.java

/**
 * Ld die Config vom Default-Repository herunter.
 *//*from   www  . ja  v  a  2  s  .com*/
private Properties loadVfsConfig() throws IOException {
    String configUrl = String.format("%s/%s/%s", defaultRepositoryUrl, DIST_DIR, RESOLVE_CONFIG_FILE);
    log.info("Looking for repository-config at {}", configUrl);
    Properties properties = new Properties();
    FileSystemOptions fso = new FileSystemOptions();
    if (isSftp()) {
        Assert.isTrue(this.keyFile.isFile(), "Keyfile is not a file");
        File[] files = { this.keyFile };
        SftpFileSystemConfigBuilder.getInstance().setIdentities(fso, files);
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso, "yes");
    }

    FileObject fo;
    try {
        fo = VFS.getManager().resolveFile(configUrl, fso);

        BufferedInputStream inputStream = new BufferedInputStream(fo.getContent().getInputStream());

        properties.load(inputStream);
    } catch (FileSystemException e) {
        log.info("No repository-config found at {}", configUrl);
        throw new RuntimeException(e);
    }

    return properties;
}

From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java

public void testCreateFile() throws IOException {
    FileObject object = ROOT.resolveFile(FILE);
    assertFalse(object.exists());/*  w w w. j  a  va2  s  . com*/
    OutputStream os = object.getContent().getOutputStream();
    os.write(0xfc);
    os.close();
    assertTrue(object.exists());
    assertEquals(FileType.FILE, object.getType());
}

From source file:com.thinkberg.vfs.s3.tests.S3FileProviderTest.java

public void testCopyFileWithAttribute() throws FileSystemException {
    if (!BUCKETID.startsWith("s3:")) {
        FileObject srcObject = ROOT.resolveFile(FILE);
        srcObject.createFile();/*from www  .j  av a 2  s  .  c  o  m*/
        srcObject.getContent().setAttribute(ATTR_TESTKEY, ATTR_TESTVALUE);
        assertTrue("source object should exist", srcObject.exists());
        assertEquals("source object attribute missing", ATTR_TESTVALUE,
                srcObject.getContent().getAttribute(ATTR_TESTKEY));
        FileObject dstObject = ROOT.resolveFile(FILE + ".dst");
        assertFalse("destination should not exist", dstObject.exists());
        dstObject.copyFrom(srcObject, ALL_FILE_SELECTOR);
        assertTrue("destination should exist after copy", dstObject.exists());
        assertEquals("destination object attribute missing", ATTR_TESTVALUE,
                dstObject.getContent().getAttribute(ATTR_TESTKEY));

        srcObject.delete();
        dstObject.delete();
    } else {
        LogFactory.getLog(S3FileProviderTest.class)
                .info(String.format("ignoring property test for '%s'", ROOT));
    }
}

From source file:com.panet.imeta.core.row.ValueDataUtil.java

public static Object loadFileContentInBinary(ValueMetaInterface metaA, Object dataA)
        throws KettleValueException {
    if (dataA == null)
        return null;

    FileObject file = null;
    FileInputStream fis = null;//from  ww  w.  j a va 2s  . c  o m
    try {
        file = KettleVFS.getFileObject(dataA.toString());
        fis = (FileInputStream) ((LocalFile) file).getInputStream();
        int fileSize = (int) file.getContent().getSize();
        byte[] content = Const.createByteArray(fileSize);
        fis.read(content, 0, fileSize);
        return content;
    } catch (Exception e) {
        throw new KettleValueException(e);
    } finally {
        try {
            if (file != null)
                file.close();
            if (fis != null)
                fis.close();
        } catch (Exception e) {
        }
        ;
    }
}