Skip to content

Commit 15ab34a

Browse files
author
mgeipel
committed
fixed #57
1 parent 3e205a6 commit 15ab34a

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
B
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C
2+
D
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
default dir = FLUX_DIR + "dir";
2+
3+
dir|
4+
read-dir(recursive="true")|
5+
open-file|
6+
as-lines|
7+
write("stdout");
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2013 Deutsche Nationalbibliothek
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.culturegraph.mf.stream.source;
17+
18+
import java.io.File;
19+
20+
import org.culturegraph.mf.framework.DefaultObjectPipe;
21+
import org.culturegraph.mf.framework.ObjectReceiver;
22+
import org.culturegraph.mf.framework.annotations.Description;
23+
import org.culturegraph.mf.framework.annotations.In;
24+
import org.culturegraph.mf.framework.annotations.Out;
25+
26+
/**
27+
* Reads a directory and emits all filenames found.
28+
*
29+
* @author Markus Michael Geipel
30+
*/
31+
@In(String.class)
32+
@Out(String.class)
33+
@Description("Reads a directory and emits all filenames found.")
34+
public final class DirReader extends DefaultObjectPipe<String, ObjectReceiver<String>> {
35+
36+
private boolean recursive;
37+
38+
public void setRecursive(final boolean recursive) {
39+
this.recursive = recursive;
40+
}
41+
42+
@Override
43+
public void process(final String dir) {
44+
final File file = new File(dir);
45+
if (file.isDirectory()) {
46+
dir(file);
47+
} else {
48+
getReceiver().process(dir);
49+
}
50+
}
51+
52+
private void dir(final File dir) {
53+
final ObjectReceiver<String> receiver = getReceiver();
54+
final File[] files = dir.listFiles();
55+
for (File file : files) {
56+
if (file.isDirectory()) {
57+
if (recursive) {
58+
dir(file);
59+
}
60+
} else {
61+
receiver.process(file.getAbsolutePath());
62+
}
63+
}
64+
}
65+
}

src/main/resources/flux-commands.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open-bzip2 org.culturegraph.mf.stream.source.Bzip2Opener
55
open-http org.culturegraph.mf.stream.source.HttpOpener
66
open-resource org.culturegraph.mf.stream.source.ResourceOpener
77
read-string org.culturegraph.mf.stream.source.StringReader
8-
#ls org.culturegraph.mf.stream.source.DirReader
8+
read-dir org.culturegraph.mf.stream.source.DirReader
99

1010
sort-triples org.culturegraph.mf.stream.pipe.sort.TripleSort
1111
count-triples org.culturegraph.mf.stream.pipe.sort.TripleCount

0 commit comments

Comments
 (0)