package io.pivotal.labs.cfenv;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class ResourceUtils {

    public static String loadResource(String name) throws IOException {
        try (InputStream stream = openResource(name)) {
            Scanner scanner = new Scanner(stream, StandardCharsets.UTF_8.name()).useDelimiter("\\z");
            String content = scanner.next();
            IOException exception = scanner.ioException();
            if (exception != null) throw exception;
            return content;
        }
    }

    public static InputStream openResource(String name) throws FileNotFoundException {
        InputStream stream = ResourceUtils.class.getResourceAsStream(name);
        if (stream == null) throw new FileNotFoundException(name);
        return stream;
    }

}

package io.pivotal.labs.cfenv;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ResourceUtils {

    public static String loadResource(String name) throws IOException {
        try (InputStream stream = openResource(name)) {
            StringBuilder buffer = new StringBuilder();
            InputStreamReader reader = new InputStreamReader(stream);
            while (true) {
                int character = reader.read();
                if (character == -1) break;
                buffer.append((char) character);
            }
            return buffer.toString();
        }
    }

    public static InputStream openResource(String name) throws FileNotFoundException {
        InputStream stream = ResourceUtils.class.getResourceAsStream(name);
        if (stream == null) throw new FileNotFoundException(name);
        return stream;
    }

}

Fix resource loading to work with files bigger than a kilobyte
Fix resource loading to work with files bigger than a kilobyte

Signed-off-by: Ben Grohbiel <f31bec9830c462ca5208f6f388c04b025df0947c@pivotal.io>
