public CSFileInputStream(String arg0) throws FileNotFoundException, IOException { super(new CSFile(arg0)); path = arg0; }
public static byte[] fileToBytes(String srcFile) throws FileNotFoundException, IOException { return streamToBytes(new FileInputStream(new CSFile(srcFile))); }
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 stringToFileNoPrefix(String content, String path) throws IOException { File file = new CSFile(path); OutputStreamWriter sw = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); sw.write(content); sw.flush(); sw.close(); }
public static void writeAllLines(String path, List<String> lines) throws IOException { File file = new CSFile(path); FileOutputStream s = new FileOutputStream(file); OutputStreamWriter sw = new OutputStreamWriter(s, "UTF-8"); for( String line : lines ) sw.write(line + "\r\n"); sw.flush(); s.close(); }
public static String fileToString(String src) throws FileNotFoundException, IOException { return streamToString(new FileInputStream(new CSFile(src))); }
public static List<String> readAllLines(String path) throws IOException { List<String> result = new ArrayList<String>(); File file = new CSFile(path); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8")); while( reader.ready() ) result.add(reader.readLine()); reader.close(); return result; }
/** * Helper method to check the existance of a file. * @param the full path and name of the file to be checked. * @return true if file exists, false otherwise. */ private boolean checkFile(String pstrFile) { boolean blnRet = false; File objFile = null; try { objFile = new CSFile(pstrFile); blnRet = (objFile.exists() && objFile.isFile()); } catch (Exception e) { blnRet = false; } finally { if (objFile != null) objFile = null; } return blnRet; }
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 stringToFile(String content, String path) throws IOException { File file = new CSFile(path); stringToFile(content, file); }
public static void stringToFile(String content, String path, boolean bom) throws IOException { File file = new CSFile(path); stringToFile(content, file, bom); }
public static void createDirectory(String path) throws IOException{ new CSFile(path).mkdirs(); }
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 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 Element checkBySchema(String fileToCheck, boolean wantThrow) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException, FHIRException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); factory.setSchema(schema); DocumentBuilder builder = factory.newDocumentBuilder(); MyErrorHandler err = new MyErrorHandler(errors, fileToCheck); builder.setErrorHandler(err); CSFileInputStream f = new CSFileInputStream(new CSFile(fileToCheck)); Document doc = builder.parse(f); if (wantThrow && err.getErrors().size() > 0) throw new FHIRException("File " + fileToCheck + " failed schema validation"); return doc.getDocumentElement(); }
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 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 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); } }