All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.algorithmia.development.ResponseHandler Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.algorithmia.development;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

final class ResponseHandler {

    private String FIFOPATH = "/tmp/algoout";

    private PrintStream output;

    ResponseHandler() {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(this.FIFOPATH, true);
            output = new PrintStream(fileOutputStream, true);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

     void writeToPipe(OUTPUT outputObject) {
        Response response = new Response(outputObject);
        String serialized = response.getJsonOutput();
        this.output.println(serialized);
        this.output.flush();
    }

     void writeErrorToPipe(ERRORTYPE e) {
        SerializableException exception = new SerializableException<>(e);
        String serialized = exception.getJsonOutput();
        this.output.println(serialized);
        this.output.flush();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy