public CSFileInputStream(String arg0) throws FileNotFoundException, IOException { super(new CSFile(arg0)); path = arg0; }
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 void addFilesFiltered(String actualDir, String ext, String[] noExt) throws IOException { File f = new CSFile(actualDir); String files[] = f.list(); for (int i = 0; i < files.length; i++) { if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)))) { boolean ok = true; for (String n : noExt) { ok = ok && !files[i].endsWith(n); } if (ok) { addFile(Utilities.path(actualDir, files[i])); } } } }
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 void addFolder(String actualDir, String statedDir, boolean omitIfExists, String noExt) throws IOException { File fd = new CSFile(actualDir); String files[] = fd.list(); for (String f : files) { if (new CSFile(Utilities.path(actualDir, f)).isDirectory()) addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists, noExt); else if (noExt == null || !f.endsWith(noExt)) addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists); } }
public void addFiles(String actualDir, String statedDir, String ext, String noExt) throws FileNotFoundException, IOException { byte data[] = new byte[BUFFER]; statedDir = statedDir.replace("\\", "/"); File f = new CSFile(actualDir); String files[] = f.list(); for (int i = 0; i < files.length; i++) { if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)) && (noExt == null || !files[i].endsWith(noExt)))) { FileInputStream fi = new FileInputStream(actualDir + files[i]); BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); ZipEntry entry = new ZipEntry(statedDir + files[i]); names.add(statedDir + files[i]); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } origin.close(); } } }
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 void addFolder(String actualDir, String statedDir, boolean omitIfExists) throws IOException { File fd = new CSFile(actualDir); String files[] = fd.list(); for (String f : files) { if (new CSFile(Utilities.path(actualDir, f)).isDirectory()) addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists); else addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists); } }
public static byte[] fileToBytes(String srcFile) throws FileNotFoundException, IOException { return streamToBytes(new FileInputStream(new CSFile(srcFile))); }
public void addFilesFiltered(String actualDir, String statedDir, String ext, String[] noExt) throws FileNotFoundException, IOException { byte data[] = new byte[BUFFER]; statedDir = statedDir.replace("\\", "/"); File f = new CSFile(actualDir); String files[] = f.list(); for (int i = 0; i < files.length; i++) { if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)))) { boolean ok = true; for (String n : noExt) { ok = ok && !files[i].endsWith(n); } if (ok) { FileInputStream fi = new FileInputStream(actualDir + files[i]); BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); ZipEntry entry = new ZipEntry(statedDir + files[i]); names.add(statedDir + files[i]); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } origin.close(); } } } }
public void addFolder(String actualDir, String statedDir, boolean omitIfExists, String noExt) throws IOException { File fd = new CSFile(actualDir); String files[] = fd.list(); for (String f : files) { if (new CSFile(Utilities.path(actualDir, f)).isDirectory()) addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists, noExt); else if (noExt == null || !f.endsWith(noExt)) addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists); } }
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 bytesToFile(byte[] bytes, String path) throws IOException { File file = new CSFile(path); OutputStream sw = new FileOutputStream(file); sw.write(bytes); sw.flush(); sw.close(); }
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 void addFilesFiltered(String actualDir, String ext, String[] noExt) throws IOException { File f = new CSFile(actualDir); String files[] = f.list(); for (int i = 0; i < files.length; i++) { if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)))) { boolean ok = true; for (String n : noExt) { ok = ok && !files[i].endsWith(n); } if (ok) { addFile(Utilities.path(actualDir, files[i])); } } } }
public void addFolder(String actualDir, String statedDir, boolean omitIfExists) throws IOException { File fd = new CSFile(actualDir); String files[] = fd.list(); for (String f : files) { if (new CSFile(Utilities.path(actualDir, f)).isDirectory()) addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists); else addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists); } }