// Path: src/main/java/edu/berkeley/nlp/lm/util/StrUtils.java
// public class StrUtils
// {
// 
// 	public static <T> String join(final List<T> objs) {
// 		return join(objs, " ");
// 	}
// 
// 	public static <T> String join(final List<T> objs, final String delim) {
// 		if (objs == null) return "";
// 		return join(objs, delim, 0, objs.size());
// 	}
// 
// 	public static <T> String join(final List<T> objs, final String delim, final int start, final int end) {
// 		if (objs == null) return "";
// 		final StringBuilder sb = new StringBuilder();
// 		boolean first = true;
// 		for (int i = start; i < end; i++) {
// 			if (!first) sb.append(delim);
// 			sb.append(objs.get(i));
// 			first = false;
// 		}
// 		return sb.toString();
// 	}
// 
// 	public static boolean isEmpty(final String s) {
// 		return s == null || s.equals("");
// 	}
// 
// }


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.channels.Channels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import edu.berkeley.nlp.lm.util.StrUtils;
package edu.berkeley.nlp.lm.io;



/**
 * Some IO utility functions. Naming convention: "Hard" means that the function
 * throws a RuntimeException upon failure, "Easy" means it returns null.
 * 
 * @author adampauls
 * @author Percy Liang
 * 
 */
public class IOUtils
{

	public static BufferedReader openIn(final String path) throws IOException {
		return openIn(new File(path));
	}

	public static BufferedReader openIn(final File path) throws IOException {
		InputStream is = getBufferedInputStream(path);
		if (path.getName().endsWith(".gz")) is = new GZIPInputStream(is);
		return new BufferedReader(getReader(is));
	}

	public static BufferedReader openInHard(final String path) {
		return openInHard(new File(path));
	}

	public static BufferedReader openInHard(final File path) {
		try {
			return openIn(path);
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static PrintWriter openOut(final String path) throws IOException {
		return openOut(new File(path));
	}

	public static PrintWriter openOut(final File path) throws IOException {
		OutputStream os = new FileOutputStream(path);
		if (path.getName().endsWith(".gz")) os = new GZIPOutputStream(os);
		return new PrintWriter(getWriter(os));
	}

	public static PrintWriter openOutEasy(final String path) {
// Path: src/main/java/edu/berkeley/nlp/lm/util/StrUtils.java
// public class StrUtils
// {
// 
// 	public static <T> String join(final List<T> objs) {
// 		return join(objs, " ");
// 	}
// 
// 	public static <T> String join(final List<T> objs, final String delim) {
// 		if (objs == null) return "";
// 		return join(objs, delim, 0, objs.size());
// 	}
// 
// 	public static <T> String join(final List<T> objs, final String delim, final int start, final int end) {
// 		if (objs == null) return "";
// 		final StringBuilder sb = new StringBuilder();
// 		boolean first = true;
// 		for (int i = start; i < end; i++) {
// 			if (!first) sb.append(delim);
// 			sb.append(objs.get(i));
// 			first = false;
// 		}
// 		return sb.toString();
// 	}
// 
// 	public static boolean isEmpty(final String s) {
// 		return s == null || s.equals("");
// 	}
// 
// }


// Path: src/main/java/edu/berkeley/nlp/lm/io/IOUtils.java
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.channels.Channels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import edu.berkeley.nlp.lm.util.StrUtils;

package edu.berkeley.nlp.lm.io;



/**
 * Some IO utility functions. Naming convention: "Hard" means that the function
 * throws a RuntimeException upon failure, "Easy" means it returns null.
 * 
 * @author adampauls
 * @author Percy Liang
 * 
 */
public class IOUtils
{

	public static BufferedReader openIn(final String path) throws IOException {
		return openIn(new File(path));
	}

	public static BufferedReader openIn(final File path) throws IOException {
		InputStream is = getBufferedInputStream(path);
		if (path.getName().endsWith(".gz")) is = new GZIPInputStream(is);
		return new BufferedReader(getReader(is));
	}

	public static BufferedReader openInHard(final String path) {
		return openInHard(new File(path));
	}

	public static BufferedReader openInHard(final File path) {
		try {
			return openIn(path);
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static PrintWriter openOut(final String path) throws IOException {
		return openOut(new File(path));
	}

	public static PrintWriter openOut(final File path) throws IOException {
		OutputStream os = new FileOutputStream(path);
		if (path.getName().endsWith(".gz")) os = new GZIPOutputStream(os);
		return new PrintWriter(getWriter(os));
	}

	public static PrintWriter openOutEasy(final String path) {
		if (StrUtils.isEmpty(path)) return null;