view src/luan/lib/Utils.java @ 84:cca4f8522893

minor changes git-svn-id: https://luan-java.googlecode.com/svn/trunk@85 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 18 Feb 2013 23:15:14 +0000
parents aa7538ae5fb6
children 6db8f286fa6c
line wrap: on
line source

package luan.lib;

import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.IOException;
import java.net.URL;


public final class Utils {
	private Utils() {}  // never

	public static String readAll(Reader in)
		throws IOException
	{
		char[] a = new char[8192];
		StringBuilder buf = new StringBuilder();
		int n;
		while( (n=in.read(a)) != -1 ) {
			buf.append(a,0,n);
		}
		return buf.toString();
	}

	public static String read(File file)
		throws IOException
	{
		Reader in = new FileReader(file);
		String s = readAll(in);
		in.close();
		return s;
	}

	public static String read(URL url)
		throws IOException
	{
		Reader in = new InputStreamReader(url.openStream());
		String s = readAll(in);
		in.close();
		return s;
	}

}