1 8 9 package org.jivesoftware.util; 10 11 import java.io.File ; 12 import java.io.BufferedReader ; 13 import java.io.FileReader ; 14 15 24 public class TestUtils { 25 26 30 public static File createTempFile() throws Exception { 31 return createTempFile("test", ".test"); 32 } 33 34 38 public static File createTempFile(String prefix, String suffix) throws Exception { 39 return File.createTempFile(prefix, suffix); 40 } 41 42 45 public static String getAsString(File file) throws Exception { 46 BufferedReader in = new BufferedReader (new FileReader (file)); 47 StringBuffer xml = new StringBuffer (); 48 String lineSeparator = System.getProperty("line.separator"); 49 if (lineSeparator == null) { 50 lineSeparator = "\n"; 51 } 52 String line = null; 53 while ((line=in.readLine()) != null) { 54 xml.append(line).append(lineSeparator); 55 } 56 in.close(); 57 return xml.toString(); 58 } 59 60 public static String prepareFilename(String filename) { 61 return filename.replace('/', File.separatorChar); 62 } 63 } 64 65 | Popular Tags |