Permalink
Browse files

groovy support

  • Loading branch information...
cinterloper committed Dec 22, 2014
1 parent 665f03f commit acf7fa7b5b099113059ac675a6921ed8ffc05325
Showing with 65 additions and 0 deletions.
  1. +3 −0 build.gradle
  2. +4 −0 examples/groovyfs.sh
  3. +58 −0 src/main/groovy/net/fusejna/examples/GroovyFS.groovy
View
@@ -1,4 +1,5 @@
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven-publish'
@@ -9,8 +10,10 @@ repositories {
mavenCentral()
}
dependencies {
compile 'net.java.dev.jna:jna:3.5.2'
compile "org.codehaus.groovy:groovy-all:2.1.5"
}
task uberJar(type: Jar) {
View
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd "`dirname "$0"`"
./run.sh net.fusejna.examples.GroovyFS "$@"
@@ -0,0 +1,58 @@
package net.fusejna.examples;
import java.io.File;
import java.nio.ByteBuffer;
import net.fusejna.DirectoryFiller;
import net.fusejna.ErrorCodes;
import net.fusejna.FuseException;
import net.fusejna.StructFuseFileInfo.FileInfoWrapper;
import net.fusejna.StructStat.StatWrapper;
import net.fusejna.types.TypeMode.NodeType;
import net.fusejna.util.FuseFilesystemAdapterFull;
public class GroovyFS extends FuseFilesystemAdapterFull
{
public static void main(final String... args) throws FuseException
{
if (args.length != 1) {
System.err.println("Usage: GroovyFS <mountpoint>");
System.exit(1);
}
new GroovyFS().log(true).mount(args[0]);
}
final String filename = "/hello.txt";
final String contents = "Hello World!\n";
@Override
public int getattr(final String path, final StatWrapper stat)
{
if (path.equals(File.separator)) { // Root directory
stat.setMode(NodeType.DIRECTORY);
return 0;
}
if (path.equals(filename)) { // hello.txt
stat.setMode(NodeType.FILE).size(contents.length());
return 0;
}
return -ErrorCodes.ENOENT();
}
@Override
public int read(final String path, final ByteBuffer buffer, final long size, final long offset, final FileInfoWrapper info)
{
// Compute substring that we are being asked to read
final String s = contents.substring((int) offset,
(int) Math.max(offset, Math.min(contents.length() - offset, offset + size)));
buffer.put(s.getBytes());
return s.getBytes().length;
}
@Override
public int readdir(final String path, final DirectoryFiller filler)
{
filler.add(filename);
return 0;
}
}

0 comments on commit acf7fa7

Please sign in to comment.