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.webdav.Util.java

public static String getETag(FileObject object) {
    String fileName = object.getName().getPath();
    String lastModified = "";
    try {/* w w  w  .  j  a v a 2s .  com*/
        lastModified = String.valueOf(object.getContent().getLastModifiedTime());
    } catch (FileSystemException e) {
        // ignore error here
    }

    return DigestUtils.shaHex(fileName + lastModified);
}

From source file:com.panet.imeta.core.vfs.KettleVFS.java

public static InputStream getInputStream(FileObject fileObject) throws FileSystemException {
    FileContent content = fileObject.getContent();
    return content.getInputStream();
}

From source file:cc.aileron.commons.resource.ResourceLoaders.java

/**
 * try-load//from   ww  w  .j  av a  2  s.c o  m
 * 
 * @param path
 * @return
 * @throws URISyntaxException
 * @throws MalformedURLException
 * @throws ResourceNotFoundException
 */
private static Resource tryLoad(final String path)
        throws URISyntaxException, MalformedURLException, ResourceNotFoundException {
    for (final Entry<Type, Loader> entry : map.entrySet()) {
        final ResourceLoaders.Type type = entry.getKey();
        final ResourceLoaders.Loader loader = entry.getValue();
        try {
            final FileObject file = loader.get(path);
            if (file.exists()) {
                return new ResourceImpl(file.getContent(), type);
            }
        } catch (final Exception e)// ?????
        {
        }
    }
    throw new ResourceNotFoundException(path);
}

From source file:com.pongasoft.util.io.IOUtils.java

/**
 * Saves the content in the resource.//from  w  ww .j a v  a  2  s  . c  om
 *
 * @param resource the resource to save the content
 * @param content the content to save
 * @throws IOException if there is a problem saving
 */
public static void saveContent(FileObject resource, byte[] content) throws IOException {
    OutputStream os = resource.getContent().getOutputStream();
    try {
        saveContent(os, content);
    } finally {
        os.close();
    }
}

From source file:com.pongasoft.util.io.IOUtils.java

/**
 * Reads the content of the resource/*w  w w . jav a2  s.  c o m*/
 *
 * @param resource
 * @return the whole content
 * @throws IOException if there is an error reading
 */
public static byte[] readContent(FileObject resource) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    InputStream is = resource.getContent().getInputStream();
    try {
        copy(is, baos);
    } finally {
        is.close();
    }

    return baos.toByteArray();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

private static InputStream openInputStream(final FileObject fo) throws FileSystemException {
    return fo.getContent().getInputStream();
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

private static OutputStreamWriter openWriter(final FileObject fo) throws FileSystemException {
    return new OutputStreamWriter(fo.getContent().getOutputStream());
}

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

private static RandomAccessContent openRandomAccessContent(final FileObject fo, final RandomAccessMode mode)
        throws FileSystemException {
    return fo.getContent().getRandomAccessContent(mode);
}

From source file:com.rapleaf.ramhdfs.RamFileSystem.java

private static boolean createDirectory(FileObject fo) {
    try {// w ww. ja v  a2 s . c o m
        fo.createFolder();
        fo.getContent().setLastModifiedTime(System.currentTimeMillis());
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
    return true;
}

From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java

/**
 * Returns a buffered input stream from a file
 * @param fileObject A file object/*w ww.  j a  va  2s .  com*/
 * @return an InputStream from the file object
 * @throws FileSystemException An exception while getting the file
 */
public static InputStream getInputStream(FileObject fileObject) throws FileSystemException {
    return new BufferedInputStream(fileObject.getContent().getInputStream());
}