-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
2,086 additions
and
2,476 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,5 +83,4 @@ doc/ | |
# ignore out | ||
out/ | ||
|
||
# ignore patches | ||
*.patch |
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
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,42 @@ | ||
package net.querz.io; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
public interface Deserializer<T> { | ||
|
||
T fromStream(InputStream stream) throws IOException; | ||
|
||
default T fromFile(File file) throws IOException { | ||
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) { | ||
return fromStream(bis); | ||
} | ||
} | ||
|
||
default T fromBytes(byte[] data) throws IOException { | ||
ByteArrayInputStream stream = new ByteArrayInputStream(data); | ||
return fromStream(stream); | ||
} | ||
|
||
default T fromResource(Class<?> clazz, String path) throws IOException { | ||
try (InputStream stream = clazz.getClassLoader().getResourceAsStream(path)) { | ||
if (stream == null) { | ||
throw new IOException("resource \"" + path + "\" not found"); | ||
} | ||
return fromStream(stream); | ||
} | ||
} | ||
|
||
default T fromURL(URL url) throws IOException { | ||
try (InputStream stream = url.openStream()) { | ||
return fromStream(stream); | ||
} | ||
} | ||
|
||
|
||
} |
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,7 @@ | ||
package net.querz.io; | ||
|
||
@FunctionalInterface | ||
public interface ExceptionBiFunction <T, U, R, E extends Exception> { | ||
|
||
R accept(T t, U u) throws E; | ||
} |
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,7 @@ | ||
package net.querz.io; | ||
|
||
@FunctionalInterface | ||
public interface ExceptionTriConsumer<T, U, V, E extends Exception> { | ||
|
||
void accept(T t, U u, V v) throws E; | ||
} |
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,13 @@ | ||
package net.querz.io; | ||
|
||
public interface MaxDepthIO { | ||
|
||
default int decrementMaxDepth(int maxDepth) { | ||
if (maxDepth < 0) { | ||
throw new IllegalArgumentException("negative maximum depth is not allowed"); | ||
} else if (maxDepth == 0) { | ||
throw new MaxDepthReachedException("reached maximum depth of NBT structure"); | ||
} | ||
return --maxDepth; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...t/querz/nbt/MaxDepthReachedException.java → ...et/querz/io/MaxDepthReachedException.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
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,26 @@ | ||
package net.querz.io; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
public interface Serializer<T> { | ||
|
||
void toStream(T object, OutputStream out) throws IOException; | ||
|
||
default void toFile(T object, File file) throws IOException { | ||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) { | ||
toStream(object, bos); | ||
} | ||
} | ||
|
||
default byte[] toBytes(T object) throws IOException { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
toStream(object, bos); | ||
bos.close(); | ||
return bos.toByteArray(); | ||
} | ||
} |
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,37 @@ | ||
package net.querz.io; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
|
||
public interface StringDeserializer<T> extends Deserializer<T> { | ||
|
||
T fromReader(Reader reader) throws IOException; | ||
|
||
default T fromString(String s) throws IOException { | ||
return fromReader(new StringReader(s)); | ||
} | ||
|
||
@Override | ||
default T fromStream(InputStream stream) throws IOException { | ||
try (Reader reader = new InputStreamReader(stream)) { | ||
return fromReader(reader); | ||
} | ||
} | ||
|
||
@Override | ||
default T fromFile(File file) throws IOException { | ||
try (Reader reader = new FileReader(file)) { | ||
return fromReader(reader); | ||
} | ||
} | ||
|
||
@Override | ||
default T fromBytes(byte[] data) throws IOException { | ||
return fromReader(new StringReader(new String(data))); | ||
} | ||
} |
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 net.querz.io; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
|
||
public interface StringSerializer<T> extends Serializer<T> { | ||
|
||
void toWriter(T object, Writer writer) throws IOException; | ||
|
||
default String toString(T object) throws IOException { | ||
Writer writer = new StringWriter(); | ||
toWriter(object, writer); | ||
writer.flush(); | ||
return writer.toString(); | ||
} | ||
|
||
@Override | ||
default void toStream(T object, OutputStream stream) throws IOException { | ||
Writer writer = new OutputStreamWriter(stream); | ||
toWriter(object, writer); | ||
writer.flush(); | ||
} | ||
|
||
@Override | ||
default void toFile(T object, File file) throws IOException { | ||
try (Writer writer = new FileWriter(file)) { | ||
toWriter(object, writer); | ||
} | ||
} | ||
} |
Oops, something went wrong.