[serde-*] Make data readers and writers AutoCloseable
This commit is contained in:
@@ -11,7 +11,7 @@ import java.util.PrimitiveIterator;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@RequiredArgsConstructor
|
||||
public class HjsonLexer {
|
||||
public class HjsonLexer implements AutoCloseable {
|
||||
private static final int EMPTY_CODEPOINT = -2;
|
||||
|
||||
private final Reader reader;
|
||||
@@ -482,4 +482,9 @@ public class HjsonLexer {
|
||||
throw TweedDataReadException.builder().message("Failed to read character from input at " + currentPos).cause(e).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,6 +630,11 @@ public class HjsonReader implements TweedDataReader {
|
||||
return contexts.peek();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
lexer.close();
|
||||
}
|
||||
|
||||
private enum Context {
|
||||
VALUE,
|
||||
LIST,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.siphalor.tweed5.data.hjson;
|
||||
|
||||
import de.siphalor.tweed5.dataapi.api.TweedDataWriteException;
|
||||
import de.siphalor.tweed5.dataapi.api.TweedDataVisitor;
|
||||
import de.siphalor.tweed5.dataapi.api.TweedDataWriter;
|
||||
import de.siphalor.tweed5.dataapi.api.decoration.TweedDataCommentDecoration;
|
||||
import de.siphalor.tweed5.dataapi.api.decoration.TweedDataDecoration;
|
||||
import lombok.Data;
|
||||
@@ -12,7 +12,7 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class HjsonWriter implements TweedDataVisitor {
|
||||
public class HjsonWriter implements TweedDataWriter {
|
||||
private static final int PREFILL_INDENT = 10;
|
||||
private static final Pattern LINE_FEED_PATTERN = Pattern.compile("\\n|\\r\\n");
|
||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("^-?\\d+(?:\\.\\d*)?(?:[eE][+-]?\\d+)?$");
|
||||
@@ -580,6 +580,11 @@ public class HjsonWriter implements TweedDataVisitor {
|
||||
return new TweedDataWriteException("Writing Hjson failed", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private enum Context {
|
||||
ROOT,
|
||||
LIST,
|
||||
|
||||
Reference in New Issue
Block a user