Package org.uberfire.java.nio.file.attribute

Examples of org.uberfire.java.nio.file.attribute.BasicFileAttributes


    protected Asset buildAsset(Path file, boolean loadContent) {
        String name = file.getFileName().toString();
        String location = trimLocation(file);

        AssetBuilder assetBuilder = AssetBuilderFactory.getAssetBuilder(name);
        BasicFileAttributes attrs = getFileSystem(file.toUri().toString()).provider().readAttributes(file, BasicFileAttributes.class);
        assetBuilder.uniqueId(encodeUniqueId(file.toUri().toString()))
                    .location(location)
                    .creationDate(attrs.creationTime() == null ? "" : new Date(attrs.creationTime().toMillis()).toString())
                    .lastModificationDate(attrs.lastModifiedTime() == null ? "" : new Date(attrs.lastModifiedTime().toMillis()).toString())
                    // TODO some provider specific details
                    .description("")
                    .owner("");

        if (loadContent) {
View Full Code Here


                final Pair<Integer, Object> result = extractValue( entry );
                _categories.put( result.getK1(), result.getK2().toString() );
            }
        }

        final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();

        final List<String> categories = new ArrayList<String>( _categories.values() );

        this.attrs = new OtherMetaAttributes() {

            @Override
            public List<String> categories() {
                return categories;
            }

            @Override
            public FileTime lastModifiedTime() {
                return fileAttrs.lastModifiedTime();
            }

            @Override
            public FileTime lastAccessTime() {
                return fileAttrs.lastAccessTime();
            }

            @Override
            public FileTime creationTime() {
                return fileAttrs.creationTime();
            }

            @Override
            public boolean isRegularFile() {
                return fileAttrs.isRegularFile();
            }

            @Override
            public boolean isDirectory() {
                return fileAttrs.isDirectory();
            }

            @Override
            public boolean isSymbolicLink() {
                return fileAttrs.isSymbolicLink();
            }

            @Override
            public boolean isOther() {
                return fileAttrs.isOther();
            }

            @Override
            public long size() {
                return fileAttrs.size();
            }

            @Override
            public Object fileKey() {
                return fileAttrs.fileKey();
            }
        };
    }
View Full Code Here

                                final DiscussionRecord o2 ) {
                return o1.getTimestamp().compareTo( o2.getTimestamp() );
            }
        } );

        final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();

        this.attrs = new DiscussionAttributes() {
            @Override
            public List<DiscussionRecord> discussion() {
                return result;
            }

            @Override
            public FileTime lastModifiedTime() {
                return fileAttrs.lastModifiedTime();
            }

            @Override
            public FileTime lastAccessTime() {
                return fileAttrs.lastAccessTime();
            }

            @Override
            public FileTime creationTime() {
                return fileAttrs.creationTime();
            }

            @Override
            public boolean isRegularFile() {
                return fileAttrs.isRegularFile();
            }

            @Override
            public boolean isDirectory() {
                return fileAttrs.isDirectory();
            }

            @Override
            public boolean isSymbolicLink() {
                return fileAttrs.isSymbolicLink();
            }

            @Override
            public boolean isOther() {
                return fileAttrs.isOther();
            }

            @Override
            public long size() {
                return fileAttrs.size();
            }

            @Override
            public Object fileKey() {
                return fileAttrs.fileKey();
            }
        };
    }
View Full Code Here

    private final ConfigAttributes attrs;

    public ConfigView( final AbstractPath path ) {
        super( path );

        final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();

        this.attrs = new ConfigAttributes() {

            @Override
            public FileTime lastModifiedTime() {
                return fileAttrs.lastModifiedTime();
            }

            @Override
            public FileTime lastAccessTime() {
                return fileAttrs.lastAccessTime();
            }

            @Override
            public FileTime creationTime() {
                return fileAttrs.creationTime();
            }

            @Override
            public boolean isRegularFile() {
                return fileAttrs.isRegularFile();
            }

            @Override
            public boolean isDirectory() {
                return fileAttrs.isDirectory();
            }

            @Override
            public boolean isSymbolicLink() {
                return fileAttrs.isSymbolicLink();
            }

            @Override
            public boolean isOther() {
                return fileAttrs.isOther();
            }

            @Override
            public long size() {
                return fileAttrs.size();
            }

            @Override
            public Object fileKey() {
                return fileAttrs.fileKey();
            }
        };
    }
View Full Code Here

        return readAttributes( "*" );
    }

    @Override
    public Map<String, Object> readAttributes( final String... attributes ) {
        final BasicFileAttributes attrs = readAttributes();

        return new HashMap<String, Object>() {{
            for ( final String attribute : attributes ) {
                checkNotEmpty( "attribute", attribute );
                if ( attribute.equals( "*" ) || attribute.equals( IS_REGULAR_FILE ) ) {
                    put( IS_REGULAR_FILE, attrs.isRegularFile() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( IS_DIRECTORY ) ) {
                    put( IS_DIRECTORY, attrs.isDirectory() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( IS_SYMBOLIC_LINK ) ) {
                    put( IS_SYMBOLIC_LINK, attrs.isSymbolicLink() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( IS_OTHER ) ) {
                    put( IS_OTHER, attrs.isOther() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( SIZE ) ) {
                    put( SIZE, new Long( attrs.size() ) );
                }
                if ( attribute.equals( "*" ) || attribute.equals( FILE_KEY ) ) {
                    put( FILE_KEY, attrs.fileKey() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( LAST_MODIFIED_TIME ) ) {
                    put( LAST_MODIFIED_TIME, attrs.lastModifiedTime() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( LAST_ACCESS_TIME ) ) {
                    put( LAST_ACCESS_TIME, attrs.lastAccessTime() );
                }
                if ( attribute.equals( "*" ) || attribute.equals( CREATION_TIME ) ) {
                    put( CREATION_TIME, attrs.creationTime() );
                }
                if ( attribute.equals( "*" ) ) {
                    break;
                }
            }
View Full Code Here

        }

        @Override
        public <T extends BasicFileAttributes> T readAttributes() throws org.uberfire.java.nio.IOException {
            if ( attrs == null ) {
                final BasicFileAttributes basicAtts = ( (BasicFileAttributeView) path.getAttrView( BasicFileAttributeView.class ) ).readAttributes();
                attrs = new DublinCoreAttributes( basicAtts, (String) path.getAttrStorage().getContent().get( "dcore.author" ) );
            }
            return (T) attrs;
        }
View Full Code Here

        }

        final ObjectId id = resolveObjectId( fs.gitRepo(), branchName );
        final String gPath = fixPath( path );

        return new BasicFileAttributes() {

            private long lastModifiedDate = -1;
            private long creationDate = -1;

            @Override
View Full Code Here

        final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider();

        final File tempFile = File.createTempFile( "foo", "bar" );
        final Path path = GeneralPathImpl.newFromFile( fsProvider.getFileSystem( URI.create( "file:///" ) ), tempFile );

        final BasicFileAttributes attrs = fsProvider.readAttributes( path, BasicFileAttributes.class );

        assertThat( attrs ).isNotNull();
        assertThat( attrs.isRegularFile() ).isTrue();
        assertThat( attrs.isDirectory() ).isFalse();
        assertThat( attrs.isSymbolicLink() ).isFalse();
        assertThat( attrs.isOther() ).isFalse();
        assertThat( attrs.size() ).isEqualTo( 0L );
    }
View Full Code Here

        final OutputStream outStream3 = PROVIDER.newOutputStream( path3 );
        outStream3.write( "my cool content".getBytes() );
        outStream3.close();

        final BasicFileAttributes attrs = PROVIDER.readAttributes( path3, BasicFileAttributes.class );

        assertThat( attrs.isDirectory() ).isFalse();
        assertThat( attrs.isRegularFile() ).isTrue();
        assertThat( attrs.creationTime() ).isNotNull();
        assertThat( attrs.lastModifiedTime() ).isNotNull();
        assertThat( attrs.size() ).isEqualTo( 15L );

        try {
            PROVIDER.readAttributes( PROVIDER.getPath( URI.create( "git://user_branch@readattrs-test-repo/not_exists.txt" ) ), BasicFileAttributes.class );
            failBecauseExceptionWasNotThrown( NoSuchFileException.class );
        } catch ( NoSuchFileException e ) {
        }

        assertThat( PROVIDER.readAttributes( path3, MyAttrs.class ) ).isNull();

        final Path rootPath = PROVIDER.getPath( URI.create( "git://user_branch@readattrs-test-repo/" ) );

        final BasicFileAttributes attrsRoot = PROVIDER.readAttributes( rootPath, BasicFileAttributes.class );

        assertThat( attrsRoot.isDirectory() ).isTrue();
        assertThat( attrsRoot.isRegularFile() ).isFalse();
        assertThat( attrsRoot.creationTime() ).isNotNull();
        assertThat( attrsRoot.lastModifiedTime() ).isNotNull();
        assertThat( attrsRoot.size() ).isEqualTo( -1L );
    }
View Full Code Here

    public DublinCoreView( final AbstractPath path ) {
        super( path );
        final Map<String, Object> content = path.getAttrStorage().getContent();

        final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();

        final Map<String, List<String>> dcore = new HashMap<String, List<String>>() {{
            for ( final String property : PROPERTIES ) {
                put( property, new ArrayList<String>() );
            }
        }};

        for ( final Map.Entry<String, Object> entry : content.entrySet() ) {
            if ( entry.getKey().startsWith( TITLE ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( TITLE ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( CREATOR ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( CREATOR ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( SUBJECT ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( SUBJECT ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( DESCRIPTION ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( DESCRIPTION ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( PUBLISHER ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( PUBLISHER ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( CONTRIBUTOR ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( CONTRIBUTOR ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( TYPE ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( TYPE ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( FORMAT ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( FORMAT ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( IDENTIFIER ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( IDENTIFIER ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( SOURCE ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( SOURCE ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( LANGUAGE ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( LANGUAGE ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( RELATION ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( RELATION ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( COVERAGE ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( COVERAGE ).add( result.getK1(), result.getK2() );
            } else if ( entry.getKey().startsWith( RIGHTS ) ) {
                final Pair<Integer, String> result = extractValue( entry );
                dcore.get( RIGHTS ).add( result.getK1(), result.getK2() );
            }
        }

        this.attrs = new DublinCoreAttributes() {
            @Override
            public List<String> titles() {
                return dcore.get( TITLE );
            }

            @Override
            public List<String> creators() {
                return dcore.get( CREATOR );
            }

            @Override
            public List<String> subjects() {
                return dcore.get( SUBJECT );
            }

            @Override
            public List<String> descriptions() {
                return dcore.get( DESCRIPTION );
            }

            @Override
            public List<String> publishers() {
                return dcore.get( PUBLISHER );
            }

            @Override
            public List<String> contributors() {
                return dcore.get( CONTRIBUTOR );
            }

            @Override
            public List<String> types() {
                return dcore.get( TYPE );
            }

            @Override
            public List<String> formats() {
                return dcore.get( FORMAT );
            }

            @Override
            public List<String> identifiers() {
                return dcore.get( IDENTIFIER );
            }

            @Override
            public List<String> sources() {
                return dcore.get( SOURCE );
            }

            @Override
            public List<String> languages() {
                return dcore.get( LANGUAGE );
            }

            @Override
            public List<String> relations() {
                return dcore.get( RELATION );
            }

            @Override
            public List<String> coverages() {
                return dcore.get( COVERAGE );
            }

            @Override
            public List<String> rights() {
                return dcore.get( RIGHTS );
            }

            @Override
            public FileTime lastModifiedTime() {
                return fileAttrs.lastModifiedTime();
            }

            @Override
            public FileTime lastAccessTime() {
                return fileAttrs.lastAccessTime();
            }

            @Override
            public FileTime creationTime() {
                return fileAttrs.creationTime();
            }

            @Override
            public boolean isRegularFile() {
                return fileAttrs.isRegularFile();
            }

            @Override
            public boolean isDirectory() {
                return fileAttrs.isDirectory();
            }

            @Override
            public boolean isSymbolicLink() {
                return fileAttrs.isSymbolicLink();
            }

            @Override
            public boolean isOther() {
                return fileAttrs.isOther();
            }

            @Override
            public long size() {
                return fileAttrs.size();
            }

            @Override
            public Object fileKey() {
                return fileAttrs.fileKey();
            }
        };
    }
View Full Code Here

TOP

Related Classes of org.uberfire.java.nio.file.attribute.BasicFileAttributes

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.