Package org.apache.commons.vfs2

Examples of org.apache.commons.vfs2.FileChangeEvent


        final Capability[] caps = getRequiredCaps();
        if (caps != null)
        {
            for (int i = 0; i < caps.length; i++)
            {
                final Capability cap = caps[i];
                FileSystem fs = readFolder.getFileSystem();
                if (!fs.hasCapability(cap))
                {
//                    String name = fs.getClass().getName();
//                    int index = name.lastIndexOf('.');
View Full Code Here


    assertThat( topoListener.events.size(), is( 1 ) );
    topoListener.events.clear();

    // Add a file to the directory.
    FileObject two = createFile( dir, "two.xml", "org/apache/hadoop/gateway/topology/file/topology-two.xml", 1L );
    fileListener.fileCreated( new FileChangeEvent( two ) );
    topologies = provider.getTopologies();
    assertThat( topologies.size(), is( 2 ) );
    Set<String> names = new HashSet<String>( Arrays.asList( "one", "two" ) );
    Iterator<Topology> iterator = topologies.iterator();
    topology = iterator.next();
    assertThat( names, hasItem( topology.getName() ) );
    names.remove( topology.getName() );
    topology = iterator.next();
    assertThat( names, hasItem( topology.getName() ) );
    names.remove( topology.getName() );
    assertThat( names.size(), is( 0 ) );
    assertThat( topoListener.events.size(), is( 1 ) );
    List<TopologyEvent> events = topoListener.events.get( 0 );
    assertThat( events.size(), is( 1 ) );
    TopologyEvent event = events.get( 0 );
    assertThat( event.getType(), is( TopologyEvent.Type.CREATED ) );
    assertThat( event.getTopology(), notNullValue() );

    // Update a file in the directory.
    two = createFile( dir, "two.xml", "org/apache/hadoop/gateway/topology/file/topology-three.xml", 2L );
    fileListener.fileChanged( new FileChangeEvent( two ) );
    topologies = provider.getTopologies();
    assertThat( topologies.size(), is( 2 ) );
    names = new HashSet<String>( Arrays.asList( "one", "two" ) );
    iterator = topologies.iterator();
    topology = iterator.next();
    assertThat( names, hasItem( topology.getName() ) );
    names.remove( topology.getName() );
    topology = iterator.next();
    assertThat( names, hasItem( topology.getName() ) );
    names.remove( topology.getName() );
    assertThat( names.size(), is( 0 ) );

    // Remove a file from the directory.
    two.delete();
    fileListener.fileDeleted( new FileChangeEvent( two ) );
    topologies = provider.getTopologies();
    assertThat( topologies.size(), is( 1 ) );
    topology = topologies.iterator().next();
    assertThat( topology.getName(), is( "one" ) );
    assertThat( topology.getTimestamp(), is( 1L ) );
View Full Code Here

        // Get file content as a binary stream
        final byte[] expectedBin = expected.getBytes("utf-8");

        // Check lengths
        final FileContent content = file.getContent();
        assertEquals("same content length", expectedBin.length, content.getSize());

        // Read content into byte array
        final InputStream instr = content.getInputStream();
        final ByteArrayOutputStream outstr;
        try
        {
            outstr = new ByteArrayOutputStream(expectedBin.length);
            final byte[] buffer = new byte[256];
View Full Code Here

     * Tests the root file name.
     */
    public void testRootFileName() throws Exception
    {
        // Locate the root file
        final FileName rootName = getReadFolder().getFileSystem().getRoot().getName();

        // Test that the root path is "/"
        assertEquals("root path", "/", rootName.getPath());

        // Test that the root basname is ""
        assertEquals("root base name", "", rootName.getBaseName());

        // Test that the root name has no parent
        assertNull("root parent", rootName.getParent());
    }
View Full Code Here

    /**
     * Tests child file names.
     */
    public void testChildName() throws Exception
    {
        final FileName baseName = getReadFolder().getName();
        final String basePath = baseName.getPath();
        final FileName name = getManager().resolveName(baseName, "some-child", NameScope.CHILD);

        // Test path is absolute
        assertTrue("is absolute", basePath.startsWith("/"));

        // Test base name
        assertEquals("base name", "some-child", name.getBaseName());

        // Test absolute path
        assertEquals("absolute path", basePath + "/some-child", name.getPath());

        // Test parent path
        assertEquals("parent absolute path", basePath, name.getParent().getPath());

        // Try using a compound name to find a child
        assertBadName(name, "a/b", NameScope.CHILD);

        // Check other invalid names
View Full Code Here

    {
        FileSystemManager mgr = VFS.getManager();

        FileObject root = mgr
                .resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr");
        FileName rootName = root.getName();

        testNames(mgr, rootName);

        testChildren(root);
View Full Code Here

                                final String relName,
                                final NameScope scope)
        throws Exception
    {
        // Try the supplied name
        FileName name = getManager().resolveName(baseName, relName, scope);
        assertEquals(expectedPath, name.getPath());

        String temp;

        // Replace the separators
        temp = relName.replace('\\', '/');
        name = getManager().resolveName(baseName, temp, scope);
        assertEquals(expectedPath, name.getPath());

        // And again
        temp = relName.replace('/', '\\');
        name = getManager().resolveName(baseName, temp, scope);
        assertEquals(expectedPath, name.getPath());
    }
View Full Code Here

    /**
     * Tests relative name resolution, relative to the base folder.
     */
    public void testNameResolution() throws Exception
    {
        final FileName baseName = getReadFolder().getName();
        final String parentPath = baseName.getParent().getPath();
        final String path = baseName.getPath();
        final String childPath = path + "/some-child";

        // Test empty relative path
        assertSameName(path, baseName, "");

View Full Code Here

     * Tests descendent name resolution.
     */
    public void testDescendentName()
        throws Exception
    {
        final FileName baseName = getReadFolder().getName();

        // Test direct child
        String path = baseName.getPath() + "/some-child";
        assertSameName(path, baseName, "some-child", NameScope.DESCENDENT);

        // Test compound name
        path = path + "/grand-child";
        assertSameName(path, baseName, "some-child/grand-child", NameScope.DESCENDENT);
View Full Code Here

     * Tests resolution of absolute names.
     */
    public void testAbsoluteNames() throws Exception
    {
        // Test against the base folder
        FileName name = getReadFolder().getName();
        checkAbsoluteNames(name);

        // Test against the root
        name = getReadFolder().getFileSystem().getRoot().getName();
        checkAbsoluteNames(name);
View Full Code Here

TOP

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

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.