private void saveMapObject()

in wilma-extras/shortCircuit/src/main/java/com/epam/wilma/extras/shortcircuit/ShortCircuitResponseInformationFileHandler.java [92:130]


    private void saveMapObject(FileOutputStreamFactory fileOutputStreamFactory, File file, String entryKey, ShortCircuitResponseInformation information) throws IOException {
        // if file does not exists, then create it
        if (!file.exists()) {
            if (file.getParentFile() != null) {
                if (!file.getParentFile().mkdirs()) {
                    //ups, cannot create the necessary folder
                    logger.error("ShortCircuit - cannot create folder: {}", file.getParentFile().getName());
                    return;
                }
            }
            if (!file.createNewFile()) {
                //ups, cannot save
                logger.error("ShortCircuit - cannot create file: {}", file.getName());
                return;
            }
        }
        try (FileOutputStream fos = fileOutputStreamFactory.createFileOutputStream(file)) {
            fos.write(("{\n  \"Key\": \"" + entryKey + "\",\n").getBytes());
            fos.write(("  \"ResponseCode\": " + information.getStatusCode() + ",\n").getBytes());
            fos.write(("  \"ContentType\": \"" + information.getContentType() + "\",\n").getBytes());
            Map<String, String> headers = information.getHeaders();
            if (headers != null) {
                fos.write("  \"Headers\": [".getBytes());
                int j = 1;
                for (String key : headers.keySet()) {
                    fos.write(("    { \"" + key + "\": \"" + encodeString(headers.get(key)) + "\" }").getBytes());
                    if (j != headers.size()) {
                        fos.write(",".getBytes());
                    }
                    fos.write("\n".getBytes());
                    j++;
                }
                fos.write("  ],\n".getBytes());
            }
            fos.write("  \"Body\": ".getBytes());
            String myBody = new JSONObject().put("Body", encodeString(information.getBody())).toString();
            fos.write((myBody + "\n}").getBytes());
        }
    }