1 26 27 package net.sourceforge.cobertura.ant; 28 29 import java.io.BufferedReader ; 30 import java.io.ByteArrayOutputStream ; 31 import java.io.File ; 32 import java.io.FileNotFoundException ; 33 import java.io.FileReader ; 34 import java.io.IOException ; 35 import java.io.PrintStream ; 36 37 class Util 38 { 39 40 static File createTemporaryTextFile(String prefix) throws IOException 41 { 42 File outputFile; 43 outputFile = File.createTempFile(prefix, ".txt"); 44 outputFile.deleteOnExit(); 45 return outputFile; 46 } 47 48 54 static String getText(File file) throws FileNotFoundException , IOException 55 { 56 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 57 PrintStream ps = new PrintStream (baos); 58 BufferedReader reader = null; 59 try 60 { 61 reader = new BufferedReader (new FileReader (file)); 62 String line; 63 while ((line = reader.readLine()) != null) 64 { 65 ps.println(line); 66 } 67 ps.close(); 68 } 69 finally 70 { 71 ps.close(); 72 if (reader != null) 73 { 74 try 75 { 76 reader.close(); 77 } 78 catch (IOException e) 79 { 80 System.err.println("IOException when closing file " + file.getAbsolutePath()); 81 e.printStackTrace(); 82 } 83 } 84 } 85 86 return baos.toString(); 87 } 88 89 } 90 | Popular Tags |