@Override public Iterator<Path> iterator() { return new Iterator<Path>() { private int i = 0; @Override public boolean hasNext() { return (i < getNameCount()); } @Override public Path next() { if( i < getNameCount() ) { Path result = getName( i ); i++; return result; } else { throw new NoSuchElementException(); } } @Override public void remove() { throw new ReadOnlyFileSystemException(); } }; }
@Override public Iterator<Path> iterator() { return new Iterator<Path>() { private int i = 0; @Override public boolean hasNext() { return i < getNameCount(); } @Override public Path next() { if (i < getNameCount()) { Path result = getName(i); i++; return result; } else { throw new NoSuchElementException(); } } @Override public void remove() { throw new ReadOnlyFileSystemException(); } }; }
@Override public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException { if ( readonly ) { throw new ReadOnlyFileSystemException(); } basicHost().setTimes( lastModifiedTime, lastAccessTime, createTime ); }
@Override public void setTimes( @Nullable FileTime lastModifiedTime, @Nullable FileTime lastAccessTime, @Nullable FileTime createTime ) throws IOException { if ( readonly ) { throw new ReadOnlyFileSystemException(); } attis.setTimes( Optional.ofNullable( lastModifiedTime ), Optional.ofNullable( lastAccessTime ), Optional.ofNullable( createTime )); }
static ReadOnlyFileSystemException readOnly() { return new ReadOnlyFileSystemException(); }
private ReadOnlyFileSystemException readOnly() { return new ReadOnlyFileSystemException(); }
@SuppressWarnings({ "PMD.NPathComplexity" }) public static <T extends SeekableByteChannel> FileChannel newChannel( EightyPath pathArg, Set<? extends OpenOption> options, BiFunction<EightyPath, Set<OpenOption>, T> create ) throws IOException { final EightyFileSystem eightyFileSystem = pathArg._getFileSystem(); EightyPath path = toRealPath( pathArg ); Set<OpenOption> impliedOptions = new HashSet<>( options ); if( impliedOptions.isEmpty() ) { impliedOptions.add( READ ); } if ( impliedOptions.contains( APPEND )) { impliedOptions.add( WRITE ); } newByteChannelParentCheck( path ); throwIfPathIsNotAccessible( path ); boolean creating = byteChannelCheckExistence( options, path ); if( options.contains( APPEND ) && options.contains( READ ) ) { throw new IllegalArgumentException( "APPEND + READ not allowed" ); } if( options.contains( APPEND ) && options.contains( TRUNCATE_EXISTING ) ) { throw new IllegalArgumentException( "APPEND + TRUNCATE_EXISTING not allowed" ); } if( Files.isDirectory( path ) ) { throw new FileSystemException( path.toString() + " is a directory" ); } if( impliedOptions.contains( WRITE ) ) { if( eightyFileSystem.isReadOnly() ) { throw new ReadOnlyFileSystemException(); } if ( !creating && !Files.isWritable( path )) { throw new AccessDeniedException( "file not writable" ); } } if ( creating ) { eightyFileSystem.get80().newContent( path ); } T unwachedChannel = eightyFileSystem.addClosable( create.apply( path, impliedOptions ) ); FileChannel ret = new WatchableByteChannel( unwachedChannel, () -> eightyFileSystem.signal( path, StandardWatchEventKinds.ENTRY_MODIFY )); if( creating ) { // e.g. means has a a parent FileTime now = FileTime.from( Clock.systemUTC().instant() ); Files.getFileAttributeView( childGetParent( path ), BasicFileAttributeView.class ).setTimes( now, now, null ); path._getFileSystem().signal( path, StandardWatchEventKinds.ENTRY_CREATE ); } else if ( impliedOptions.contains( WRITE )) { path._getFileSystem().signal( path, StandardWatchEventKinds.ENTRY_MODIFY ); } return ret; }
private void checkWritable() throws IOException { if (readOnly) throw new ReadOnlyFileSystemException(); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testCanNotWriteToReadonlyFile() throws IOException { Files.write( getFile(), CONTENT ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testCanNotAppendToReadonlyFile() throws IOException { Files.write( getFile(), CONTENT, APPEND ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testSetAttributeToReadonlyThrows() throws IOException { Files.setLastModifiedTime( getFile(), FileTime.fromMillis( 500 ) ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testWriteNewFileToReadonly() throws IOException { Files.write( getNonEmptyDir().resolve( "newfile" ), CONTENT ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testMoveFileInReadonly() throws IOException { Files.move( getFile(), getNonEmptyDir().resolve( "newfile" ) ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testCopyFileInReadonly() throws IOException { Files.copy( getFile(), getNonEmptyDir().resolve( "newfile" ) ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testDeleteFileInReadonly() throws IOException { Files.delete( getFile() ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testDeleteDirInReadonly() throws IOException { Files.delete( getEmptyDir() ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class } ) public void testCreateHardLinkInReadonly() throws IOException { Files.createLink( getNonEmptyDir().resolve( "newLink" ), getFile() ); }
@Test( expected = ReadOnlyFileSystemException.class ) @Category( { Readonly.class, SymLink.class } ) public void testCreateSymLinkInReadonly() throws IOException { Files.createSymbolicLink( getNonEmptyDir().resolve( "newLink" ), getFile() ); }