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

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

package com.algorithmia.development;

import java.io.*;

final class ResponseHandler {

    private String FIFOPATH = "/tmp/algoout";

    private FileOutputStream stream;
    private PrintStream output;


    void preparePipe(){
        if(output == null) {
            try {
                stream  = new FileOutputStream(this.FIFOPATH, true);
                output = new PrintStream(stream, 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 - 2025 Weber Informatics LLC | Privacy Policy