forked from d2fn/guano
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.d2fn.guano; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* FSVisitor | ||
* @author Dietrich Featherston | ||
*/ | ||
public interface FSVisitor { | ||
public void visit(File f, byte[] data, String znode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.d2fn.guano; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* FSWalker | ||
* @author Dietrich Featherston | ||
*/ | ||
public class FSWalker { | ||
|
||
private String localRoot; | ||
private String znodeRoot; | ||
|
||
public FSWalker(String localRoot, String znodeRoot) { | ||
this.localRoot = localRoot; | ||
this.znodeRoot = znodeRoot; | ||
} | ||
|
||
public void go(FSVisitor visitor) { | ||
File f = new File(localRoot); | ||
walk(visitor, f, znodeRoot); | ||
} | ||
|
||
private void walk(FSVisitor visitor, File f, String znode) { | ||
|
||
byte[] data = new byte[0]; | ||
|
||
if(znode.endsWith("_znode")) { | ||
znode = znode.substring(0, znode.length()-6); | ||
} | ||
if(znode.endsWith("/") && znode.length() > 1) { | ||
znode = znode.substring(0, znode.length()-1); | ||
} | ||
|
||
try { | ||
data = FileUtils.readFileToByteArray(f); | ||
} catch (IOException e) {} | ||
|
||
visitor.visit(f, data, znode); | ||
|
||
if(f.isDirectory()) { | ||
File[] children = f.listFiles(); | ||
for(File child : children) { | ||
walk(visitor, child, (znode.equals("/") ? "" : znode) + "/" + child.getName()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters