Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FileChunkSeq for iterator style folders, namely for Tesser
- Loading branch information
Lassi Immonen
committed
Aug 5, 2015
1 parent
61154fb
commit d197d72
Showing
4 changed files
with
105 additions
and
24 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,56 @@ | ||
package iota; | ||
|
||
import clojure.lang.ASeq; | ||
import clojure.lang.IPersistentMap; | ||
import clojure.lang.ISeq; | ||
import clojure.lang.Obj; | ||
|
||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.ArrayList; | ||
|
||
/* | ||
* Variation of FileSeq which will produce sequence of arrays of data. | ||
* | ||
* Internally uses FileRecordSeq. | ||
* | ||
* This is intended for fold usages that operates on iterables rather | ||
* than core.reducers CollFold protocol. | ||
* | ||
* One example is Tesser https://github.com/aphyr/tesser. | ||
* */ | ||
|
||
|
||
public class FileChunkSeq extends ASeq { | ||
|
||
private final FileRecordSeq seq; | ||
private FileRecordSeq[] parts = null; | ||
|
||
public FileChunkSeq(FileRecordSeq seq) { | ||
this.seq = seq; | ||
} | ||
|
||
public Object first() { | ||
if (parts == null) { | ||
parts = seq.split(seq.start + seq.bufsize); | ||
} | ||
if (parts != null) { | ||
return parts[0].toArray(); | ||
} | ||
return seq.toArray(); | ||
} | ||
|
||
public ISeq next() { | ||
if (parts == null) { | ||
parts = seq.split(seq.start + seq.bufsize); | ||
} | ||
if (parts == null) { | ||
return null; | ||
} | ||
return new FileChunkSeq(parts[1]); | ||
} | ||
|
||
public Obj withMeta(IPersistentMap meta) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
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