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

org.keycloak.util.StreamUtil Maven / Gradle / Ivy

package org.keycloak.util;

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

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
public final class StreamUtil {

    private StreamUtil() {
    }

    public static String readString(InputStream in) throws IOException
    {
        char[] buffer = new char[1024];
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int wasRead = 0;
        do
        {
            wasRead = reader.read(buffer, 0, 1024);
            if (wasRead > 0)
            {
                builder.append(buffer, 0, wasRead);
            }
        }
        while (wasRead > -1);

        return builder.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy