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

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

Introduction

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

Prototype

FileContent getContent() throws FileSystemException;

Source Link

Document

Returns this file's content.

Usage

From source file:com.github.junrar.vfs2.provider.rar.RandomAccessContentAccess.java

/**
 * @param rac/*w  w  w .  jav a 2s.c  om*/
 * @throws FileSystemException
 */
public RandomAccessContentAccess(FileObject file) throws FileSystemException {
    this(file.getContent().getRandomAccessContent(RandomAccessMode.READ));
}

From source file:com.stratuscom.harvester.PropertiesFileReader.java

public Properties getProperties(FileObject fo) throws FileSystemException, IOException {
    InputStream is = fo.getContent().getInputStream();
    Properties props = new Properties();
    props.load(is);/*  w w  w. j a va2s . co m*/
    return props;
}

From source file:com.google.code.docbook4j.VfsURIResolver.java

public Source resolve(String href, String base) throws TransformerException {
    log.debug("Resolving href={} for base={}", href, base);

    try {//from w  w w.  j  ava2 s .c om

        FileObject urlFileObject = FileObjectUtils.resolveFile(href, base);
        return new StreamSource(urlFileObject.getContent().getInputStream());

    } catch (FileSystemException e) {

        log.warn("Error resolving href=" + href + " for base=" + base, e);
        return null;
    }
}

From source file:com.collective.celos.ci.config.deploy.CelosCiTargetParser.java

public CelosCiTarget parse(URI targetFileUri) throws Exception {
    FileObject file = worker.getFileObjectByUri(targetFileUri);
    InputStream is = file.getContent().getInputStream();
    HashMap<String, String> result = Util.JSON_READER.withType(HashMap.class).readValue(is);

    URI hdfsSiteXml = URI.create(getNotNull(result, HADOOP_HDFS_SITE_XML));
    URI hdfsCoreXml = URI.create(getNotNull(result, HADOOP_CORE_SITE_XML));
    URI workflowDir = URI.create(getNotNull(result, WORKFLOWS_DIR_URI));
    URI defaultsFile = URI.create(getNotNull(result, DEFAULTS_DIR_URI));

    URI hiveJdbc = result.get(HIVE_JDBC_URL) != null ? URI.create(result.get(HIVE_JDBC_URL)) : null;

    return new CelosCiTarget(hdfsSiteXml, hdfsCoreXml, workflowDir, defaultsFile, hiveJdbc);
}

From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java

@Test
public void testGetFileObjectByUri() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}

From source file:com.sonicle.webtop.vfs.bol.js.JsGridFile.java

private long getFileSize(FileObject fo) {
    try {/*  w ww .  j  av  a  2  s  . c  o  m*/
        return fo.getContent().getSize();
    } catch (FileSystemException ex) {
        return -1;
    }
}

From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java

@Test
public void testGetFileObjectByUriStringParam() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader()
            .getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI().toString());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}

From source file:io.kahu.hawaii.service.io.FileChangeListener.java

@Override
public void fileChanged(FileChangeEvent fce) throws Exception {
    if (fce != null) {
        FileObject file = fce.getFile();
        if (file.getContent().getSize() > maxFileLength) {
            logManager.error(new ServerException(ServerError.PARSER_MAX_FILESIZE_EXCEEDED,
                    "Handler '" + handler + "', file at: " + file.getName().getPath()));
        } else {/*from   ww w .  ja  v  a2s .  com*/
            logManager.info(CoreLoggers.SERVER, "File changed '" + fce.getFile().getName().getPath() + "'.");
            handler.handleFileChange();
        }
    }
}

From source file:binky.reportrunner.engine.utils.impl.FileSystemHandlerImpl.java

public OutputStream getOutputStreamForUrl(String url) throws IOException {

    FileObject file = fsManager.resolveFile(url);

    return file.getContent().getOutputStream();

}

From source file:net.dempsy.distconfig.apahcevfs.ApacheVfsPropertiesStore.java

@Override
public int merge(final Properties props) throws IOException {
    return mapChecked(() -> {
        final FileObject latest = getLatest(parentDirObj);
        if (latest == null)
            return push(props);

        final Properties oldProps = read(latest);
        final Properties newProps = new Properties();
        newProps.putAll(oldProps);/*www . j a  v a  2 s  .  c  om*/
        newProps.putAll(props);

        final FileObject next = nextFile(latest, parentDirObj);
        try (OutputStream os = next.getContent().getOutputStream()) {
            newProps.store(os, COMMENT);
        }
        return new Integer(getVersion(next));
    }, em).intValue();
}