TestData.java 1.81 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.aam.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class TestData {
    private static final Logger LOGGER = LoggerFactory.getLogger(TestData.class);

    private TestData() {
    }

    public static String loadTestData(String resourceName) throws IOException {
        if (resourceName.indexOf("_gen_folders") > 0) {
            return TestData.loadData(resourceName).replaceAll("__ID__", String.valueOf(System.currentTimeMillis()));
        }
        if (resourceName.indexOf("_gen_folder_page") > 0) {
            int i = resourceName.indexOf("_gen_folder_page");
            resourceName = resourceName.substring(0, i + "_gen_folder_page".length()) + ".json";
            return TestData.loadData(resourceName).replaceAll("__ID__", String.valueOf(System.currentTimeMillis()));
        }
        return TestData.loadData(resourceName);
    }

    private static String loadData(String resourceName) throws IOException {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(TestData.class.getClassLoader().getResourceAsStream(resourceName)));
            String s = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (s != null) {
                sb.append(s);
                s = br.readLine();
            }
            return sb.toString();
        }
        catch (NullPointerException e) {
            LOGGER.error("Cant read from {} ", (Object)resourceName);
            throw new IOException("Cant read from  " + resourceName);
        }
    }
}