summaryrefslogtreecommitdiff
path: root/gi/posterior-regularisation/prjava/src/io/FileUtil.java
blob: 6720d08756c71865045517d78c8a19907770dfb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package io;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.io.*;
public class FileUtil 
{
	public static BufferedReader reader(File file) throws FileNotFoundException, IOException
	{
		if (file.getName().endsWith(".gz"))
			return new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), "UTF8"));
		else
			return new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
	}
	
	public static PrintStream printstream(File file) throws FileNotFoundException, IOException
	{
		if (file.getName().endsWith(".gz"))
			return new PrintStream(new GZIPOutputStream(new FileOutputStream(file)), true, "UTF8");
		else
			return new PrintStream(new FileOutputStream(file), true, "UTF8");
	}

	public static Scanner openInFile(String filename)
	{
		Scanner localsc=null;
		try
		{
			localsc=new Scanner(new FileInputStream(filename), "UTF8");

		}catch(IOException ioe){
			System.out.println(ioe.getMessage());
		}
		return localsc;
	}
	
	public static FileInputStream openInputStream(String infilename)
	{
		FileInputStream fis=null;
		try {
			fis = new FileInputStream(infilename);
			
		} catch (IOException ioe) {
			System.out.println(ioe.getMessage());
		}
		return fis;
	}
}