Skip to content

Commit

Permalink
Added isReadable, isWritable and isExecutable in FileResource
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 8, 2013
1 parent 93b69c4 commit 481317f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Expand Up @@ -430,4 +430,23 @@ public long getSize()
{
return file.length();
}

@Override
public boolean isExecutable()
{
return (this.file.canExecute() && !this.file.isDirectory());
}

@Override
public boolean isReadable()
{
return (this.file.canRead() && !this.file.isDirectory());
}

@Override
public boolean isWritable()
{
return (this.file.canWrite() && !this.file.isDirectory());
}

}
Expand Up @@ -87,4 +87,19 @@ public interface FileResource<T extends FileResource<T>> extends Resource<File>
*/
public long getSize();

/**
* Returns if a file is writable
*/
public boolean isWritable();

/**
* Returns if a file is readable
*/
public boolean isReadable();

/**
* Returns if a file is executable
*/
public boolean isExecutable();

}
Expand Up @@ -123,4 +123,29 @@ public void testDirectorySize() throws Exception
dir.mkdir();
factory.create(dir).reify(DirectoryResource.class).getSize();
}

@Test
public void testFileFlags() throws Exception
{
File tempFile = File.createTempFile("temp", "file");
tempFile.deleteOnExit();
FileResource<?> resource = factory.create(tempFile).reify(FileResource.class);
Assert.assertFalse(resource.isExecutable());
Assert.assertTrue(resource.isReadable());
Assert.assertTrue(resource.isWritable());
}

@Test
public void testDirectoryFlags() throws Exception
{
File dir = File.createTempFile("temp", "file");
dir.delete();
dir.mkdir();
dir.deleteOnExit();
DirectoryResource resource = factory.create(dir).reify(DirectoryResource.class);
Assert.assertFalse(resource.isExecutable());
Assert.assertFalse(resource.isReadable());
Assert.assertFalse(resource.isWritable());
}

}

0 comments on commit 481317f

Please sign in to comment.