Exemple #1
0
 public void copy(InputStream is, File dest) {
   FileOutputStream os = null;
   try {
     os = new FileOutputStream(dest);
     copy(is, os);
   } catch (Throwable e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(is);
     closeQuietly(os);
   }
 }
 public void saveJSONData(
     File reportDir,
     String data,
     List<ScriptCoverageCount> unloadJSData,
     UriFileTranslator uriFileTranslator) {
   try {
     lockOnReportDir(reportDir);
     reportDir.mkdirs();
     File jsonFile = new File(reportDir, "jscoverage.json");
     SortedMap<String, FileData> dataMap = new TreeMap<String, FileData>();
     if (jsonFile.exists()) {
       logger.info("Saving/merging JSON with existing JSON");
       String existingJSON = ioUtils.toString(jsonFile);
       if (uriFileTranslator.mutates()) {
         translateUris(data, uriFileTranslator, dataMap);
         dataMap =
             jsonDataMerger.mergeJSONCoverageMaps(dataMap, jsonDataMerger.jsonToMap(existingJSON));
       } else dataMap.putAll(jsonDataMerger.mergeJSONCoverageStrings(existingJSON, data));
       ioUtils.copy(jsonDataMerger.toJSON(dataMap), jsonFile);
     } else if (unloadJSData != null) {
       logger.info("Saving/merging JSON with unloaded JavaScript JSON");
       // Only scan for unloaded JS if JSON not saved before
       dataMap.putAll(jsonDataMerger.createEmptyJSON(unloadJSData));
       if (uriFileTranslator.mutates()) translateUris(data, uriFileTranslator, dataMap);
       else dataMap.putAll(jsonDataMerger.jsonToMap(data));
       ioUtils.copy(jsonDataMerger.toJSON(dataMap), jsonFile);
     } else {
       logger.info("Saving JSON");
       if (uriFileTranslator.mutates()) {
         translateUris(data, uriFileTranslator, dataMap);
         ioUtils.copy(jsonDataMerger.toJSON(dataMap), jsonFile);
       } else ioUtils.copy(data, jsonFile);
     }
   } finally {
     unlockOnReportDir(reportDir);
   }
 }
Exemple #3
0
 public void copy(File src, File dest) {
   logger.log(
       Level.FINEST, "Copying ''{0}'' to ''{1}''", new Object[] {src.getPath(), dest.getPath()});
   dest.getParentFile().mkdirs();
   FileInputStream is = null;
   FileOutputStream os = null;
   try {
     is = new FileInputStream(src);
     os = new FileOutputStream(dest);
     copy(is, os);
   } catch (Throwable e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(is);
     closeQuietly(os);
   }
 }
 @Before
 public void setUp() {
   src.delete();
   ioUtils.copy("x++;", src);
 }
Exemple #5
0
 public void copyDir(File src, File dest) {
   if (src.isDirectory())
     for (String file : src.list()) copyDir(new File(src, file), new File(dest, file));
   else ioUtils.copy(src, dest);
 }
Exemple #6
0
 public void copy(String string, File dest) {
   dest.getParentFile().mkdirs();
   ByteArrayInputStream bais = new ByteArrayInputStream(string.getBytes(charSet));
   copy(new InputStreamReader(bais, charSet), dest);
 }