1 22 23 package net.sourceforge.cobertura.reporting.html.files; 24 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 30 public abstract class CopyFiles 31 { 32 33 public static void copy(File destinationDir) throws IOException 34 { 35 File cssOutputDir = new File (destinationDir, "css"); 36 File imagesOutputDir = new File (destinationDir, "images"); 37 File jsOutputDir = new File (destinationDir, "js"); 38 39 destinationDir.mkdirs(); 40 cssOutputDir.mkdir(); 41 imagesOutputDir.mkdir(); 42 jsOutputDir.mkdir(); 43 44 copyResourceFromJar("help.css", cssOutputDir); 45 copyResourceFromJar("main.css", cssOutputDir); 46 copyResourceFromJar("sortabletable.css", cssOutputDir); 47 copyResourceFromJar("source-viewer.css", cssOutputDir); 48 copyResourceFromJar("tooltip.css", cssOutputDir); 49 50 copyResourceFromJar("blank.png", imagesOutputDir); 51 copyResourceFromJar("downsimple.png", imagesOutputDir); 52 copyResourceFromJar("upsimple.png", imagesOutputDir); 53 54 copyResourceFromJar("customsorttypes.js", jsOutputDir); 55 copyResourceFromJar("popup.js", jsOutputDir); 56 copyResourceFromJar("sortabletable.js", jsOutputDir); 57 copyResourceFromJar("stringbuilder.js", jsOutputDir); 58 59 copyResourceFromJar("help.html", destinationDir); 60 copyResourceFromJar("index.html", destinationDir); 61 } 62 63 72 private static void copyResourceFromJar(String resourceName, 73 File directory) throws IOException 74 { 75 int n; 76 byte[] buf = new byte[1024]; 77 78 InputStream in = null; 79 FileOutputStream out = null; 80 directory.mkdirs(); 81 try 82 { 83 in = CopyFiles.class.getResourceAsStream(resourceName); 84 if (in == null) 85 throw new IllegalArgumentException ("Resource " + resourceName 86 + " does not exist in this package."); 87 out = new FileOutputStream (new File (directory, resourceName)); 88 while ((n = in.read(buf, 0, buf.length)) != -1) 89 { 90 out.write(buf, 0, n); 91 } 92 } 93 finally 94 { 95 if (in != null) 96 { 97 try 98 { 99 in.close(); 100 } 101 catch (IOException e) 102 { 103 } 104 } 105 if (out != null) 106 { 107 try 108 { 109 out.close(); 110 } 111 catch (IOException e) 112 { 113 } 114 } 115 } 116 } 117 118 } 119 | Popular Tags |