1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import java.io.*; 25 import java.util.StringTokenizer ; 26 27 31 public class CopySuppFiles 32 { 33 34 public static void main(String [] args) throws Exception 35 { 36 } 37 38 public static void copyFiles(File outDir, String suppFiles) 39 throws ClassNotFoundException , IOException 40 { 41 StringTokenizer st = new StringTokenizer (suppFiles,","); 43 String scriptName = ""; InputStream is = null; while (st.hasMoreTokens()) 46 { 47 scriptName = st.nextToken(); 48 File suppFile = null; 49 String fileName = ""; 50 is = RunTest.loadTestResource(scriptName); 52 if ( is == null ) 53 System.out.println("Could not locate: " + scriptName); 54 else 55 { 56 int index = scriptName.lastIndexOf('/'); 58 fileName = scriptName.substring(index+1); 59 61 try {suppFile = new File((new File(outDir, fileName)).getCanonicalPath());} 64 catch (IOException e) { 65 File f = new File(outDir, fileName); 66 FileWriter fw = new FileWriter(f); 67 fw.close(); 68 suppFile = new File(f.getCanonicalPath()); 69 } 70 if ((fileName.indexOf("sql") > 0) || (fileName.indexOf("txt") > 0) || (fileName.indexOf(".view") > 0) || (fileName.indexOf(".policy") > 0) || (fileName.indexOf(".multi") > 0) || (fileName.indexOf(".properties") > 0)) 73 { 74 BufferedReader inFile = new BufferedReader(new InputStreamReader(is, "UTF-8")); 75 PrintWriter pw = new PrintWriter 76 ( new BufferedWriter(new FileWriter(suppFile), 10000), true ); 77 int c; 78 while ((c = inFile.read()) != -1) 79 pw.write(c); 80 pw.flush(); 81 pw.close(); 82 } 83 else 84 { 85 FileOutputStream fos = new FileOutputStream(suppFile); 86 byte[] data = new byte[4096]; 87 int len; 88 while ((len = is.read(data)) != -1) 89 { 90 fos.write(data, 0, len); 91 } 92 fos.close(); 93 } 94 } 95 } 96 } 97 } 98 | Popular Tags |