Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implement -print0 (separate path names with NUL character).
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
- Loading branch information
Showing
10 changed files
with
193 additions
and
19 deletions.
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,16 @@ | ||
package com.ning.hfind; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.FileSystem; | ||
|
||
public interface FsItem | ||
{ | ||
ImmutableList<FsItem> getChildren(); | ||
|
||
String getName(); | ||
|
||
FileStatus getStatus(); | ||
|
||
FileSystem getFs(); | ||
} |
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
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,27 @@ | ||
package com.ning.hfind; | ||
|
||
public class PrinterConfig | ||
{ | ||
private boolean depthMode = false; | ||
private boolean endLineWithNull = false; | ||
|
||
public boolean depthMode() | ||
{ | ||
return depthMode; | ||
} | ||
|
||
public void setDepthMode(boolean depthMode) | ||
{ | ||
this.depthMode = depthMode; | ||
} | ||
|
||
public boolean endLineWithNull() | ||
{ | ||
return endLineWithNull; | ||
} | ||
|
||
public void setEndLineWithNull(boolean endLineWithNull) | ||
{ | ||
this.endLineWithNull = endLineWithNull; | ||
} | ||
} |
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
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,39 @@ | ||
package com.ning.hfind; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.FileSystem; | ||
|
||
public class StubFsItem implements FsItem | ||
{ | ||
private final String name; | ||
|
||
public StubFsItem(String name) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public ImmutableList<FsItem> getChildren() | ||
{ | ||
return ImmutableList.of(); | ||
} | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
@Override | ||
public FileStatus getStatus() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public FileSystem getFs() | ||
{ | ||
return null; | ||
} | ||
} |
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.ning.hfind; | ||
|
||
import com.ning.hfind.primary.Expression; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestPrinter | ||
{ | ||
private static final Character NULL_CHARACTER = '\u0000'; | ||
|
||
class SilentPrinter extends Printer | ||
{ | ||
private String lastPathName = null; | ||
|
||
public SilentPrinter(FsItem item, Expression expression, PrinterConfig config) | ||
{ | ||
super(item, expression, config); | ||
} | ||
|
||
@Override | ||
protected void print(String pathName, boolean ignored) | ||
{ | ||
lastPathName = pathName; | ||
} | ||
|
||
public String getLastPathName() | ||
{ | ||
return lastPathName; | ||
} | ||
} | ||
|
||
@Test(groups = "fast") | ||
public void testPrint0() throws Exception | ||
{ | ||
PrinterConfig config = new PrinterConfig(); | ||
config.setEndLineWithNull(true); | ||
|
||
testOneItem("/user/pierre/mouraf.org/", config, NULL_CHARACTER); | ||
testOneItem(String.format("/user/pierre/mouraf.org/%s", NULL_CHARACTER), config, NULL_CHARACTER); | ||
testOneItem(String.format("/user/ pierre %s /mouraf.org/", NULL_CHARACTER), config, NULL_CHARACTER); | ||
} | ||
|
||
private void testOneItem(String pathName, PrinterConfig config, Character lastCharacter) | ||
{ | ||
SilentPrinter printer = new SilentPrinter(new StubFsItem(pathName), Expression.TRUE, config); | ||
printer.run(); | ||
|
||
Assert.assertEquals(printer.getLastPathName().charAt(printer.getLastPathName().length() - 1), lastCharacter.charValue()); | ||
} | ||
} |