public static boolean checkFolder(String dir, List<String> errors) throws IOException { if (!new CSFile(dir).exists()) { errors.add("Unable to find directory "+dir); return false; } else { return true; } }
public static boolean checkFile(String purpose, String dir, String file, List<String> errors) throws IOException { if (!new CSFile(dir+file).exists()) { if (errors != null) errors.add("Unable to find "+purpose+" file "+file+" in "+dir); return false; } else { return true; } }
public static void copyFile(File sourceFile, File destFile) throws IOException { if(!destFile.exists()) { if (!new CSFile(destFile.getParent()).exists()) { createDirectory(destFile.getParent()); } destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if(source != null) { source.close(); } if(destination != null) { destination.close(); } } }
public CSFile(String pathname) throws IOException { super(pathname); // if (exists() && getParent() != null) // { // String n = getName(); // File f = new File(getParent()); // String[] l = f.list(); // boolean ok = false; // for (String n1 : l) { // if (n1.equals(n)) // ok = true; // } // if (!ok) // throw new Error("Case mismatch of file "+ pathname); // } //EK: Original code above looked extremely wasteful: every single //attempt to open a file triggers a directory listing if (exists()) { if(!this.getCanonicalFile().getName().equals(this.getName())) throw new Error("Case mismatch of file "+ pathname+": found "+this.getCanonicalFile().getName()); } }
public static void copyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) throws IOException, FHIRException { CSFile src = new CSFile(sourceFolder); if (!src.exists()) throw new FHIRException("Folder " +sourceFolder+" not found"); createDirectory(destFolder); String[] files = src.list(); for (String f : files) { if (new CSFile(sourceFolder+File.separator+f).isDirectory()) { if (!f.startsWith(".")) // ignore .git files... copyDirectory(sourceFolder+File.separator+f, destFolder+File.separator+f, notifier); } else { if (notifier != null) notifier.copyFile(sourceFolder+File.separator+f, destFolder+File.separator+f); copyFile(new CSFile(sourceFolder+File.separator+f), new CSFile(destFolder+File.separator+f)); } } }
public static boolean checkFolder(String dir, List<String> errors) throws IOException { if (!new CSFile(dir).exists()) { errors.add("Unable to find directory "+dir); return false; } else { return true; } }
public static boolean checkFile(String purpose, String dir, String file, List<String> errors) throws IOException { if (!new CSFile(dir+file).exists()) { if (errors != null) errors.add("Unable to find "+purpose+" file "+file+" in "+dir); return false; } else { return true; } }
public static void copyFile(File sourceFile, File destFile) throws IOException { if(!destFile.exists()) { if (!new CSFile(destFile.getParent()).exists()) { createDirectory(destFile.getParent()); } destFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if(source != null) { source.close(); } if(destination != null) { destination.close(); } } }
public CSFile(String pathname) throws IOException { super(pathname); // if (exists() && getParent() != null) // { // String n = getName(); // File f = new File(getParent()); // String[] l = f.list(); // boolean ok = false; // for (String n1 : l) { // if (n1.equals(n)) // ok = true; // } // if (!ok) // throw new Error("Case mismatch of file "+ pathname); // } //EK: Original code above looked extremely wasteful: every single //attempt to open a file triggers a directory listing if (exists()) { if(!this.getCanonicalFile().getName().equals(this.getName())) throw new Error("Case mismatch of file "+ pathname+": found "+this.getCanonicalFile().getName()); } }
public static void copyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) throws IOException, FHIRException { CSFile src = new CSFile(sourceFolder); if (!src.exists()) throw new FHIRException("Folder " +sourceFolder+" not found"); createDirectory(destFolder); String[] files = src.list(); for (String f : files) { if (new CSFile(sourceFolder+File.separator+f).isDirectory()) { if (!f.startsWith(".")) // ignore .git files... copyDirectory(sourceFolder+File.separator+f, destFolder+File.separator+f, notifier); } else { if (notifier != null) notifier.copyFile(sourceFolder+File.separator+f, destFolder+File.separator+f); copyFile(new CSFile(sourceFolder+File.separator+f), new CSFile(destFolder+File.separator+f)); } } }