make loading local files easier

This commit is contained in:
fjy 2014-09-30 14:50:48 -07:00
parent 0781781b99
commit 6d2747adcf
1 changed files with 10 additions and 15 deletions

View File

@ -30,11 +30,12 @@ import io.druid.data.input.impl.FileIteratingFirehose;
import io.druid.data.input.impl.StringInputRowParser; import io.druid.data.input.impl.StringInputRowParser;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator; import org.apache.commons.io.LineIterator;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@ -79,26 +80,20 @@ public class LocalFirehoseFactory implements FirehoseFactory<StringInputRowParse
@Override @Override
public Firehose connect(StringInputRowParser firehoseParser) throws IOException public Firehose connect(StringInputRowParser firehoseParser) throws IOException
{ {
File[] foundFiles = baseDir.listFiles( Collection<File> foundFiles = FileUtils.listFiles(
new FilenameFilter() baseDir,
{ new RegexFileFilter(filter),
@Override TrueFileFilter.INSTANCE
public boolean accept(File file, String name)
{
return name.contains(filter);
}
}
); );
if (foundFiles == null || foundFiles.length == 0) { if (foundFiles == null || foundFiles.isEmpty()) {
throw new ISE("Found no files to ingest! Check your schema."); throw new ISE("Found no files to ingest! Check your schema.");
} }
final LinkedList<File> files = Lists.<File>newLinkedList( final LinkedList<File> files = Lists.newLinkedList(
Arrays.asList(foundFiles) foundFiles
); );
return new FileIteratingFirehose( return new FileIteratingFirehose(
new Iterator<LineIterator>() new Iterator<LineIterator>()
{ {