public static void writeFile(String[] lines, File file) { writeFile(Arrays.asList(lines), file); }
private static void listRecursively(File fdir, int depth, Set<File> dirs) { if (fdir.isDirectory() && (depth < 10)) { dirs.add(fdir); for (File f : fdir.listFiles()) { // Go over each file/subdirectory. listRecursively(f, depth + 1, dirs); } } }
public static List<String> readMetaInfResource(Class<?> context, String filepath) { return Arrays.asList(FileUtils.read(context.getResourceAsStream("/META-INF/" + filepath))); } }
public static void writeFile(List<String> lines, OutputStream stream) { BufferedWriter bw = null; try { bw = new BufferedWriter(new OutputStreamWriter(stream)); for (String line : lines) { bw.write(line + "\n"); } } catch (IOException e) { throw new RuntimeException(e); } finally { close(bw); } }
private String getFileProperty(String name, InputStream in){ try { Properties p = new Properties(); p.load(in); Object v = p.get(name); if(v == null){ return null; } return v.toString(); } catch (IOException e) { // user might want to know about this throw new RuntimeException(e); } finally { FileUtils.close(in); } } private File getUserHome() {
public static void writeFile(String line, File file) { writeFile(Arrays.asList(new String[] { line }), file); }
public static final EntityManagerFactory createFactory(String persistenceUnitName) { Properties p = new Properties(); String filePath = SystemProperties.createDefault().get(JPA_PROPERTIES_FILE); if (filePath == null || "".equals(filePath)) { throw JPA201_PROP_FILEPATH_MISSING(JPA_PROPERTIES_FILE); } FileInputStream in = null; try { in = new FileInputStream(new File(filePath)); p.load(in); } catch (IOException e) { throw new RuntimeException(e); } finally { FileUtils.close(in); } return Persistence.createEntityManagerFactory(persistenceUnitName, p); }
public static Set<File> findFiles(File rootdir, FileFilter filter) { Set<File> matches = new HashSet<File>(); Set<File> dirs = new HashSet<File>(); listRecursively(rootdir, 0, dirs); for (File dir : dirs) { File[] files = dir.listFiles(filter); matches.addAll(Arrays.asList(files)); } return matches; }
public void write(File file) { List<String> contents = new ArrayList<String>(); contents.add(PROVIDER + "=" + provider); contents.add(URL + "=" + url); contents.add(DRIVER + "=" + driver); contents.add(USER + "=" + username); contents.add(PASSWORD + "=" + password); contents.add(TRANSACTION_TYPE + "=" + transactionType); for (String key : providerSpecific.keySet()) { contents.add(key + "=" + providerSpecific.get(key)); } FileUtils.writeFile(contents, file); } }
public static Set<File> findFiles(File rootdir, FilenameFilter filter) { Set<File> matches = new HashSet<File>(); Set<File> dirs = new HashSet<File>(); listRecursively(rootdir, 0, dirs); for (File dir : dirs) { File[] files = dir.listFiles(filter); matches.addAll(Arrays.asList(files)); } return matches; }
public static void writeFile(List<String> lines, File file) { try { File parent = file.getParentFile(); if ((parent != null) && parent.isDirectory() && !parent.exists()) { parent.mkdirs(); } } catch (Exception e) { throw new RuntimeException( "Unxpected exception when trying to create parent folders for file [" + file.getAbsolutePath() + "]."); } try { writeFile(lines, new FileOutputStream(file)); } catch (IOException e) { throw new IllegalArgumentException("File [" + file.getAbsolutePath() + "] cant write to file.", e); } }