-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #245 : add MultiFileRecordReader
- Loading branch information
1 parent
29c2a9b
commit b7d79dd
Showing
5 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
easybatch-core/src/main/java/org/easybatch/core/reader/AbstractFileRecordReader.java
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,18 @@ | ||
package org.easybatch.core.reader; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Abstract class for all file readers. | ||
* | ||
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) | ||
*/ | ||
public abstract class AbstractFileRecordReader implements RecordReader { | ||
|
||
protected File file; | ||
|
||
public AbstractFileRecordReader(File file) { | ||
this.file = file; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
easybatch-core/src/main/java/org/easybatch/core/reader/MultiFileRecordReader.java
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,49 @@ | ||
package org.easybatch.core.reader; | ||
|
||
import org.easybatch.core.record.Record; | ||
|
||
import java.io.File; | ||
import java.io.FilenameFilter; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Read records from multiple files <strong>having the same format</strong>. | ||
* | ||
* Returns records read by the delegate reader. | ||
* | ||
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) | ||
*/ | ||
public class MultiFileRecordReader implements RecordReader { | ||
|
||
private File directory; | ||
|
||
private FilenameFilter filenameFilter; | ||
|
||
private AbstractFileRecordReader delegate; | ||
|
||
private List<File> files = new ArrayList<>(); | ||
|
||
public MultiFileRecordReader(final File directory, final FilenameFilter filenameFilter, final AbstractFileRecordReader delegate) { | ||
this.directory = directory; | ||
this.filenameFilter = filenameFilter; | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void open() throws Exception { | ||
Collections.addAll(files, directory.listFiles(filenameFilter)); | ||
} | ||
|
||
@Override | ||
public Record readRecord() throws Exception { | ||
// TODO implement logic | ||
return delegate.readRecord(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
delegate.close(); | ||
} | ||
} |
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