Skip to content

Commit

Permalink
switch protobuf translation engine to buffered writer
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffz committed May 15, 2024
1 parent e3f0a02 commit f561920
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gov.hhs.aspr.ms.taskit.protobuf;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
Expand Down Expand Up @@ -200,7 +200,7 @@ public <M extends U, U> Builder addParentChildClassRelationship(Class<M> classRe

return this;
}

/**
* checks the class to determine if it is a ProtocolMessageEnum or a Message and
* if so, gets the Descriptor (which is akin to a class but for a Protobuf
Expand Down Expand Up @@ -294,7 +294,8 @@ void setDebug(boolean debug) {
* @param <M> the type of the appObject
* @throws RuntimeException if there is an IOException during writing
*/
protected <U, M extends U> void writeOutput(Path path, M appObject, Optional<Class<U>> superClass) throws IOException {
protected <U, M extends U> void writeOutput(Path path, M appObject, Optional<Class<U>> superClass)
throws IOException {
Message message;
if (Message.class.isAssignableFrom(appObject.getClass())) {
message = Message.class.cast(appObject);
Expand All @@ -319,7 +320,7 @@ protected <U, M extends U> void writeOutput(Path path, M appObject, Optional<Cla
*/
private <U extends Message> void writeOutput(Path path, U message) {
try {
Writer writer = new FileWriter(path.toFile());
BufferedWriter writer = new BufferedWriter(new FileWriter(path.toFile()));
this.data.jsonPrinter.appendTo(message, writer);

if (debug) {
Expand Down Expand Up @@ -351,16 +352,20 @@ private void printJsonToConsole(String jsonString) {
* @param <T> the return type
* @throws FileNotFoundException
* @throws RuntimeException
* <ul>
* <li>if there is an issue getting the builder method
* from the inputClassRef</li>
* <li>if there is an issue merging the read in JSON
* object into the resulting Protobuf Message builder
* </li>
* </ul>
* @throws ContractException {@linkplain ProtobufCoreTranslationError#INVALID_READ_INPUT_CLASS_REF}
* if the given inputClassRef is not assingable from
* {@linkplain Message}
* <ul>
* <li>if there is an issue getting the builder
* method
* from the inputClassRef</li>
* <li>if there is an issue merging the read in
* JSON
* object into the resulting Protobuf Message
* builder
* </li>
* </ul>
* @throws ContractException {@linkplain ProtobufCoreTranslationError#INVALID_READ_INPUT_CLASS_REF}
* if the given inputClassRef is not assingable
* from
* {@linkplain Message}
*/
protected <T, U> T readInput(Path path, Class<U> inputClassRef) throws IOException {
if (!Message.class.isAssignableFrom(inputClassRef)) {
Expand Down

0 comments on commit f561920

Please sign in to comment.