-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new processing api + refactor fabric resources
- Loading branch information
1 parent
fa90e73
commit e0bfc7e
Showing
13 changed files
with
395 additions
and
79 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
14 changes: 14 additions & 0 deletions
14
brachyura/src/main/java/io/github/coolcrabs/brachyura/processing/ProcessingEntry.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,14 @@ | ||
package io.github.coolcrabs.brachyura.processing; | ||
|
||
import java.io.InputStream; | ||
import java.util.function.Supplier; | ||
|
||
public class ProcessingEntry { | ||
public final Supplier<InputStream> in; | ||
public final ProcessingId id; | ||
|
||
public ProcessingEntry(Supplier<InputStream> in, ProcessingId id) { | ||
this.in = in; | ||
this.id = id; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
brachyura/src/main/java/io/github/coolcrabs/brachyura/processing/ProcessingId.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,11 @@ | ||
package io.github.coolcrabs.brachyura.processing; | ||
|
||
public final class ProcessingId { | ||
public final String path; | ||
public final ProcessingSource source; | ||
|
||
public ProcessingId(String path, ProcessingSource source) { | ||
this.path = path; | ||
this.source = source; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
brachyura/src/main/java/io/github/coolcrabs/brachyura/processing/ProcessingSink.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,8 @@ | ||
package io.github.coolcrabs.brachyura.processing; | ||
|
||
import java.io.InputStream; | ||
import java.util.function.Supplier; | ||
|
||
public interface ProcessingSink { | ||
public void sink(Supplier<InputStream> in, ProcessingId id); | ||
} |
15 changes: 15 additions & 0 deletions
15
brachyura/src/main/java/io/github/coolcrabs/brachyura/processing/ProcessingSource.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,15 @@ | ||
package io.github.coolcrabs.brachyura.processing; | ||
|
||
public abstract class ProcessingSource { | ||
public abstract void getInputs(ProcessingSink sink); | ||
|
||
@Override | ||
public final boolean equals(Object obj) { | ||
return super.equals(obj); | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return super.hashCode(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
brachyura/src/main/java/io/github/coolcrabs/brachyura/processing/Processor.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,8 @@ | ||
package io.github.coolcrabs.brachyura.processing; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
public interface Processor { | ||
void process(Collection<ProcessingEntry> inputs, ProcessingSink sink) throws IOException; | ||
} |
44 changes: 44 additions & 0 deletions
44
brachyura/src/main/java/io/github/coolcrabs/brachyura/processing/ProcessorChain.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,44 @@ | ||
package io.github.coolcrabs.brachyura.processing; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.function.Supplier; | ||
|
||
import io.github.coolcrabs.brachyura.util.Util; | ||
|
||
public class ProcessorChain { | ||
final Processor[] processors; | ||
|
||
public ProcessorChain(Processor...processors) { | ||
this.processors = processors; | ||
} | ||
|
||
public void apply(ProcessingSink out, ProcessingSource... in) { | ||
try { | ||
Collector c = new Collector(); | ||
for (ProcessingSource s : in) { | ||
s.getInputs(c); | ||
} | ||
for (Processor p : processors) { | ||
Collector c2 = new Collector(); | ||
p.process(c.e, c2); | ||
c = c2; | ||
} | ||
for (ProcessingEntry pe : c.e) { | ||
out.sink(pe.in, pe.id); | ||
} | ||
} catch (IOException e) { | ||
Util.sneak(e); | ||
} | ||
} | ||
|
||
static class Collector implements ProcessingSink { | ||
ConcurrentLinkedQueue<ProcessingEntry> e = new ConcurrentLinkedQueue<>(); | ||
|
||
@Override | ||
public void sink(Supplier<InputStream> in, ProcessingId id) { | ||
e.add(new ProcessingEntry(in, id)); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...src/main/java/io/github/coolcrabs/brachyura/processing/sinks/DirectoryProcessingSink.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,35 @@ | ||
package io.github.coolcrabs.brachyura.processing.sinks; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.function.Supplier; | ||
|
||
import io.github.coolcrabs.brachyura.processing.ProcessingId; | ||
import io.github.coolcrabs.brachyura.processing.ProcessingSink; | ||
import io.github.coolcrabs.brachyura.util.Util; | ||
|
||
public class DirectoryProcessingSink implements ProcessingSink { | ||
final Path path; | ||
|
||
public DirectoryProcessingSink(Path path) { | ||
this.path = path; | ||
} | ||
|
||
@Override | ||
public void sink(Supplier<InputStream> in, ProcessingId id) { | ||
try { | ||
Path target = path.resolve(id.path); | ||
Path parent = target.getParent(); | ||
if (parent != null) { | ||
Files.createDirectories(parent); | ||
} | ||
try (InputStream i = in.get()) { | ||
Files.copy(i, target); | ||
} | ||
} catch (IOException e) { | ||
throw Util.sneak(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.