package ro.dcsi.internship;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class CsvExporter2 {
	CsvExporter2(){
		System.out.println("csv exporter called");
	}
	public void export(String inputFileName, String outputFileName) throws IOException{
		FileReader fileReader = new FileReader(inputFileName);
		BufferedReader bufferedReader = new BufferedReader(fileReader);
		FileWriter fileWriter = new FileWriter(outputFileName);
		String s;
		try{
			while((s = bufferedReader.readLine()) != null){
				fileWriter.append(s + " \n");
			}
		}
		catch (IOException e){
			e.printStackTrace();
		}
		fileReader.close();
		fileWriter.close();
	}
        public String readHeading(String fileName) {
            ArrayList<User> usersArray = new ArrayList<User>();
            String s = new String();
            try {
                FileReader fr = new FileReader(fileName);
                BufferedReader br = new BufferedReader(fr);
                
                s = br.readLine();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return s;
        }
	
	public List<User> readUsers(String fileName){
		ArrayList<User> userArray = new ArrayList<User>();
		try {
			FileReader fileReader = new FileReader(fileName);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			String s;
                        String[] splited;
			while((s = bufferedReader.readLine()) != null){
                            splited = s.split(",");
                            userArray.add(new User(splited[0],splited[1],splited[2]));
			}
			return userArray;
		} catch (IOException e) {
			e.printStackTrace();
			return new ArrayList<User>();
		}
	}

}

@@ -290,16 +290,66 @@
 ogger;%0A%0A
+import org.junit.experimental.theories.Theories;%0A%0A
 public c
@@ -383,16 +383,17 @@
 orter2()
+ 
 %7B%0A%09%09Syst
@@ -434,16 +434,17 @@
 d%22);%0A%09%7D%0A
+%0A
 %09public 
@@ -518,16 +518,17 @@
 xception
+ 
 %7B%0A%09%09File
@@ -719,16 +719,17 @@
 s;%0A%09%09try
+ 
 %7B%0A%09%09%09whi
@@ -722,32 +722,33 @@
 %09%09try %7B%0A%09%09%09while
+ 
 ((s = bufferedRe
@@ -772,16 +772,17 @@
 != null)
+ 
 %7B%0A%09%09%09%09fi
@@ -817,19 +817,17 @@
 %09%09%09%7D%0A%09%09%7D
-%0A%09%09
+ 
 catch (I
@@ -839,16 +839,17 @@
 ption e)
+ 
 %7B%0A%09%09%09e.p
@@ -917,24 +917,18 @@
 e();%0A%09%7D%0A
-        
+%0A%09
 public S
@@ -964,28 +964,18 @@
 Name) %7B%0A
-            
+%09%09
 ArrayLis
@@ -1018,28 +1018,18 @@
 ser%3E();%0A
-            
+%09%09
 String s
@@ -1049,53 +1049,43 @@
 ();%0A
-            try %7B%0A                FileReader 
+%09%09FileReader fr = null;%0A%09%09try %7B%0A%09%09%09
 fr =
@@ -1111,32 +1111,19 @@
 eName);%0A
-                
+%09%09%09
 Buffered
@@ -1162,41 +1162,11 @@
 r);%0A
-                %0A                
+%09%09%09
 s = 
@@ -1176,36 +1176,26 @@
 readLine();%0A
-            
+%09%09
 %7D catch (Fil
@@ -1218,63 +1218,169 @@
 on e
-x
 ) %7B%0A
-                ex.printStackTrace();%0A            
+%09%09%09throw new RuntimeException(e);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D finally %7B%0A%09%09%09if(fr!=null)%0A%09%09%09%09try %7B%0A%09%09%09%09%09fr.close();%0A%09%09%09%09
 %7D ca
@@ -1401,77 +1401,100 @@
 on e
-x
 ) %7B%0A
-                ex.printStackTrace();%0A            %7D%0A            
+%09%09%09%09%09//bug swallowed original exception%0A%09%09%09%09%09throw new RuntimeException(e);%0A%09%09%09%09%7D%0A%09%09%7D%0A%09%09
 retu
@@ -1503,19 +1503,11 @@
  s;%0A
-        
+%09
 %7D%0A
-%09
 %0A%09pu
@@ -1548,16 +1548,17 @@
 ileName)
+ 
 %7B%0A%09%09Arra
@@ -1749,32 +1749,11 @@
  s;%0A
-                        
+%09%09%09
 Stri
@@ -1774,16 +1774,17 @@
 %09%09%09while
+ 
 ((s = bu
@@ -1820,90 +1820,43 @@
 ull)
+ 
 %7B%0A
-                            splited = s.split(%22,%22);%0A                            
+%09%09%09%09splited = s.split(%22,%22);%0A%09%09%09%09
 user
@@ -1885,16 +1885,17 @@
 ited%5B0%5D,
+ 
 splited%5B
@@ -1897,16 +1897,17 @@
 ited%5B1%5D,
+ 
 splited%5B

fix exporter that surprise us.