Package org.apache.commons.vfs2

Examples of org.apache.commons.vfs2.FileContent


    public void testUnknownContent() throws Exception
    {

        // Try getting the content of an unknown file
        FileObject unknownFile = getReadFolder().resolveFile("unknown-file");
        FileContent content = unknownFile.getContent();
        try
        {
            content.getInputStream();
            fail();
        }
        catch (FileSystemException e)
        {
            assertSameMessage("vfs.provider/read-not-file.error", unknownFile, e);
        }
        try
        {
            content.getSize();
            fail();
        }
        catch (final FileSystemException e)
        {
            assertSameMessage("vfs.provider/get-size-not-file.error", unknownFile, e);
View Full Code Here


        if (file.exists())
        {
            final String newPrefix = prefix + INDENT;
            if (file.getType().hasContent())
            {
                final FileContent content = file.getContent();
                log(newPrefix + "Content-Length: " + content.getSize());
                log(newPrefix + "Last-Modified" + new Date(content.getLastModifiedTime()));
                if (showContent)
                {
                    log(newPrefix + "Content:");
                    logContent(file, newPrefix);
                }
View Full Code Here

     * Finds the provider to use to create a filesystem from a given file.
     */
    public String getScheme(final FileObject file) throws FileSystemException
    {
        // Check the file's mime type for a match
        final FileContent content = file.getContent();
        // final String mimeType = (String) content.getAttribute("content-type");
        final String mimeType = content.getContentInfo().getContentType();
        if (mimeType != null)
        {
            return mimeTypeMap.get(mimeType);
        }

View Full Code Here

                path = manager.resolveName(base, file.getBaseName());
            }
            FileSystemOptions opts = getOptions(path.getScheme());
            FileObject file = (opts == null) ? manager.resolveFile(path.getURI())
                    : manager.resolveFile(path.getURI(), opts);
            FileContent content = file.getContent();
            if (content == null)
            {
                String msg = "Cannot access content of " + file.getName().getFriendlyURI();
                throw new ConfigurationException(msg);
            }
            return content.getInputStream();
        }
        catch (ConfigurationException e)
        {
            throw e;
        }
View Full Code Here

                    : VFS.getManager().resolveFile(url.toString(), opts);
            if (file.getType() != FileType.FILE)
            {
                throw new ConfigurationException("Cannot load a configuration from a directory");
            }
            FileContent content = file.getContent();
            if (content == null)
            {
                String msg = "Cannot access content of " + file.getName().getFriendlyURI();
                throw new ConfigurationException(msg);
            }
            return content.getInputStream();
        }
        catch (FileSystemException fse)
        {
            String msg = "Unable to access " + url.toString();
            throw new ConfigurationException(msg, fse);
View Full Code Here

            // throw an exception if the target URL is a directory
            if (file == null || file.getType() == FileType.FOLDER)
            {
                throw new ConfigurationException("Cannot save a configuration to a directory");
            }
            FileContent content = file.getContent();

            if (content == null)
            {
                throw new ConfigurationException("Cannot access content of " + url);
            }
            return content.getOutputStream();
        }
        catch (FileSystemException fse)
        {
            throw new ConfigurationException("Unable to access " + url, fse);
        }
View Full Code Here

  }

  private static Topology loadTopology( FileObject file ) throws IOException, SAXException {
    log.loadingTopologyFile( file.getName().getFriendlyURI() );
    Digester digester = digesterLoader.newDigester();
    FileContent content = file.getContent();
    Topology topology = digester.parse( content.getInputStream() );
    topology.setName( FilenameUtils.removeExtension( file.getName().getBaseName() ) );
    topology.setTimestamp( content.getLastModifiedTime() );
    return topology;
  }
View Full Code Here

                    : VFS.getManager().resolveFile(url.toString(), opts);
            if (file.getType() != FileType.FILE)
            {
                throw new ConfigurationException("Cannot load a configuration from a directory");
            }
            FileContent content = file.getContent();
            if (content == null)
            {
                String msg = "Cannot access content of " + file.getName().getFriendlyURI();
                throw new ConfigurationException(msg);
            }
            return content.getInputStream();
        }
        catch (FileSystemException fse)
        {
            String msg = "Unable to access " + url.toString();
            throw new ConfigurationException(msg, fse);
View Full Code Here

            // throw an exception if the target URL is a directory
            if (file == null || file.getType() == FileType.FOLDER)
            {
                throw new ConfigurationException("Cannot save a configuration to a directory");
            }
            FileContent content = file.getContent();

            if (content == null)
            {
                throw new ConfigurationException("Cannot access content of " + url);
            }
            return content.getOutputStream();
        }
        catch (FileSystemException fse)
        {
            throw new ConfigurationException("Unable to access " + url, fse);
        }
View Full Code Here

  }

  private static Topology loadTopology( FileObject file ) throws IOException, SAXException {
    log.loadingTopologyFile( file.getName().getFriendlyURI() );
    Digester digester = digesterLoader.newDigester();
    FileContent content = file.getContent();
    TopologyBuilder topologyBuilder = digester.parse( content.getInputStream() );
    Topology topology = topologyBuilder.build();
    topology.setName( FilenameUtils.removeExtension( file.getName().getBaseName() ) );
    topology.setTimestamp( content.getLastModifiedTime() );
    return topology;
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs2.FileContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.