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:net.dempsy.distconfig.apahcevfs.ApacheVfsPropertiesStore.java

@Override
public int clear(final String... props) throws IOException {
    return mapChecked(() -> {
        final FileObject latest = getLatest(parentDirObj);
        if (latest == null)
            return -1;

        final Properties oldProps = read(latest);
        final Properties newProps = new Properties();
        newProps.putAll(oldProps);//w ww .ja va  2  s.  c  o  m
        Arrays.stream(props).forEach(newProps::remove);

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

From source file:de.innovationgate.wga.common.beans.csconfig.v1.InvalidCSConfigVersionException.java

public InvalidCSConfigVersionException(FileObject file) {
    super("The version of design configuration is too high for this WGA version");
    try {/*from w  w  w . j ava 2 s. co  m*/
        InputStream in = file.getContent().getInputStream();
        _targetVersion = CSConfig.determineMinimumWGAVersion(in);
        in.close();
    } catch (Exception e) {
    }
}

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

@Override
public int push(final Properties props) throws IOException {
    return mapChecked(() -> {
        final FileObject next = nextFile(getLatest(parentDirObj), parentDirObj);
        try (OutputStream os = next.getContent().getOutputStream()) {
            props.store(os, COMMENT);/*from  w w  w . j  a v  a2 s . co m*/
        }
        return new Integer(getVersion(next));
    }, em).intValue();
}

From source file:fulcrum.xml.soap12.Soap12XOMTest.java

@Test
public void testXOM() {
    Document doc = null;/*from   ww  w.  ja v a  2 s.co m*/
    Builder parser = null;
    try {
        FileSystemManager fsManager = VFS.getManager();
        FileObject fileObj = fsManager.resolveFile(SIMPLE);
        if (fileObj != null && fileObj.exists() && fileObj.isReadable()) {

            FileContent content = fileObj.getContent();
            InputStream is = content.getInputStream();
            LOGGER.info("STARTING PARSE:");
            parser = new Builder();
            doc = parser.build(is);
            LOGGER.info("ENDING PARSE");
            System.out.println(doc.toXML());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        parser = null;
    }
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

@Override
public final InputStream readFile(final File file) throws IOException {
    FileObject obj = base.resolveFile(file.getPath());
    return obj.getContent().getInputStream();
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

@Override
public final OutputStream writeFile(final File file) throws IOException {
    FileObject obj = base.resolveFile(file.getPath());
    return obj.getContent().getOutputStream();
}

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

private ContainerConfig readProfileConfig()
        throws SAXException, JAXBException, FileNotFoundException, IOException {
    Unmarshaller um = Bootstrap.createConfigUnmarshaller();
    FileObject profileDir = fileUtility.getProfileDirectory();
    FileObject configFile = profileDir.resolveFile(Strings.CONFIG_XML);
    log.log(Level.FINE, MessageNames.CONFIG_FILE, configFile.toString());
    InputStream is = configFile.getContent().getInputStream();
    ContainerConfig containerConfig = (ContainerConfig) um.unmarshal(is);
    return containerConfig;
}

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

private String getFileLastModified(FileObject fo) {
    DateTimeFormatter ymdhmsFmt = DateTimeUtils.createYmdHmsFormatter();

    try {// www .j  a  va 2 s  .  c  o m
        long millis = fo.getContent().getLastModifiedTime();
        return (millis == 0) ? "" : ymdhmsFmt.print(new DateTime(millis));
    } catch (FileSystemException ex) {
        return "";
    }
}

From source file:net.sf.jabb.util.vfs.CleanUpOnCloseVfsInputStream.java

/**
 * Encapsulate the original InputStream of a file.
 * @param file      the file whose input stream will be opened and encapsulated.
 * @param fsManager the file manager that will be closed when the input stream got closed.
 * @throws FileSystemException//from ww w  . ja  v  a2s .com
 */
public CleanUpOnCloseVfsInputStream(FileObject file, FileSystemManager fsManager) throws FileSystemException {
    this.file = file;
    this.fsManager = fsManager;
    this.inputStream = file.getContent().getInputStream();
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

@Override
public final boolean writeFileAttributes(final File file) throws IOException {
    FileObject obj = base.resolveFile(file.getPath());
    FileContent content = obj.getContent();
    boolean setLastModified;
    if (FileType.FOLDER == obj.getType()) {
        setLastModified = canSetLastModifiedFolder;
    } else {//from   ww w.j a  v a 2s. c  om
        setLastModified = canSetLastModifiedFile;
    }
    if (setLastModified) {
        content.setLastModifiedTime(file.getLastModified());
    }
    return true;
}