[serde, serde-hjson] Improve HjsonSerde and make it return writer instead of visitor
This commit is contained in:
@@ -6,6 +6,11 @@ import java.io.OutputStream;
|
||||
|
||||
public interface TweedSerde {
|
||||
TweedDataReader createReader(InputStream inputStream);
|
||||
TweedDataVisitor createWriter(OutputStream outputStream) throws IOException;
|
||||
TweedDataWriter createWriter(OutputStream outputStream) throws IOException;
|
||||
|
||||
/**
|
||||
* Yields the file extension that should normally be used for this serde.
|
||||
* @return the file extension, typically with a leading dot.
|
||||
*/
|
||||
String getPreferredFileExtension();
|
||||
}
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
package de.siphalor.tweed5.data.hjson;
|
||||
|
||||
import de.siphalor.tweed5.dataapi.api.TweedDataReader;
|
||||
import de.siphalor.tweed5.dataapi.api.TweedDataVisitor;
|
||||
import de.siphalor.tweed5.dataapi.api.TweedDataWriter;
|
||||
import de.siphalor.tweed5.dataapi.api.TweedSerde;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class HjsonSerde implements TweedSerde {
|
||||
private final HjsonWriter.Options writerOptions;
|
||||
|
||||
@Override
|
||||
public TweedDataReader createReader(InputStream inputStream) {
|
||||
return new HjsonReader(new HjsonLexer(new InputStreamReader(inputStream)));
|
||||
return new HjsonReader(new HjsonLexer(new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TweedDataVisitor createWriter(OutputStream outputStream) throws IOException {
|
||||
return new HjsonWriter(new OutputStreamWriter(outputStream), new HjsonWriter.Options());
|
||||
public TweedDataWriter createWriter(OutputStream outputStream) {
|
||||
return new HjsonWriter(new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)), writerOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFileExtension() {
|
||||
return "";
|
||||
return ".hjson";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user