/** * Write contents of List list to File file. Output is written with each * element of list on a new line. * * @param list * A List to write to file. * @param file * A File to write list to. * @throws IOException * if output cannot be written to. */ private static void writeSubscriptions(List<String> list, File file) throws IOException { writeSubscriptions(list, new BufferedWriter( new OutputStreamWriter(new SecureFileOutputStream(file), "UTF-8"))); }
/** * Sets output file to mode 600 */ public SecureFileOutputStream(File file) throws FileNotFoundException { super(file); setPerms(file); }
/** * Tries to set the permissions to 600, * ignores errors */ public static void setPerms(File f) { if (!canSetPerms()) return; try { f.setReadable(false, false); f.setReadable(true, true); f.setWritable(false, false); f.setWritable(true, true); } catch (Throwable t) { // NoSuchMethodException or NoSuchMethodError if we somehow got the // version detection wrong or the JVM doesn't support it } } }
fos = new SecureFileOutputStream(keyFile); SigType stype = PREFERRED_SIGTYPE; String st = _config.getProperty(OPT_SIG_TYPE); File backup = new File(backupDir, name); if (FileUtil.copy(keyFile, backup, false, true)) { SecureFileOutputStream.setPerms(backup); log("Private key backup saved to " + backup.getAbsolutePath());
out = new SecureFileOutputStream(altFile); d.writeBytes(out); priv.writeBytes(out); File backup = new File(backupDir, name); if (FileUtil.copy(altFile, backup, false, true)) { SecureFileOutputStream.setPerms(backup); log("Alternate private key backup saved to " + backup.getAbsolutePath());
/** * File will be gzipped. * Not sorted, includes hidden. * See Comment.toPersistentString() for format. * Sets isModified() to false. */ public void save(File file) throws IOException { PrintWriter out = null; try { out = new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new SecureFileOutputStream(file)), "UTF-8")); for (List<Comment> l : map.values()) { for (Comment c : l) { out.println(c.toPersistentString()); } } if (out.checkError()) throw new IOException("Failed write to " + file); modified = false; } finally { if (out != null) out.close(); } }
/** * Sets output file to mode 600 only if append = false * (otherwise it is presumed to be 600 already) */ public SecureFileOutputStream(File file, boolean append) throws FileNotFoundException { super(file, append); //if (!append) setPerms(file); }
/** * Tries to set the permissions to 700, * ignores errors */ protected void setPerms() { if (!SecureFileOutputStream.canSetPerms()) return; try { setReadable(false, false); setReadable(true, true); setWritable(false, false); setWritable(true, true); if (isNotWindows) { setExecutable(false, false); setExecutable(true, true); } } catch (Throwable t) { // NoSuchMethodException or NoSuchMethodError if we somehow got the // version detection wrong or the JVM doesn't support it } } }
public static final void writeSeed(byte buf[]) { File f = new File(I2PAppContext.getGlobalContext().getConfigDir(), SEEDFILE); FileOutputStream fos = null; try { fos = new SecureFileOutputStream(f); fos.write(buf); } catch (IOException ioe) { // ignore } finally { if (fos != null) try { fos.close(); } catch (IOException ioe) {} } }
/** * Sets file to mode 600 when the file is created */ public static File createTempFile(String prefix, String suffix) throws IOException { File rv = File.createTempFile(prefix, suffix); // same thing as below but static SecureFileOutputStream.setPerms(rv); return rv; }
/** * Tries to set the permissions to 600, * ignores errors */ @Override protected void setPerms() { if (!SecureFileOutputStream.canSetPerms()) return; try { setReadable(false, false); setReadable(true, true); setWritable(false, false); setWritable(true, true); if (isNotWindows && isDirectory()) { setExecutable(false, false); setExecutable(true, true); } } catch (Throwable t) { // NoSuchMethodException or NoSuchMethodError if we somehow got the // version detection wrong or the JVM doesn't support it } } }
/** * Write contents of Map map to the File file. Output is written * with one key, value pair on each line, in the format: key=value. * Write to a temp file in the same directory and then rename, to not corrupt * simultaneous accesses by the router. Except on Windows where renameTo() * will fail if the target exists. * * @param map * A Map to write to file. * @param file * A File to write the Map to. * @throws IOException * if file cannot be written to. */ public static void write(Map<String, String> map, File file) throws IOException { boolean success = false; if (!isWindows) { File tmp = SecureFile.createTempFile("temp-", ".tmp", file.getAbsoluteFile().getParentFile()); write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(tmp), "UTF-8"))); success = tmp.renameTo(file); if (!success) { tmp.delete(); //System.out.println("Warning: addressbook rename fail from " + tmp + " to " + file); } } if (!success) { // hmm, that didn't work, try it the old way write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "UTF-8"))); } }
/** * Sets file to mode 600 when the file is created */ public static File createTempFile(String prefix, String suffix, File directory) throws IOException { File rv = File.createTempFile(prefix, suffix, directory); // same thing as below but static SecureFileOutputStream.setPerms(rv); return rv; }
/** * Write contents of Map map to the File file. Output is written * with one key, value pair on each line, in the format: key=value. * Write to a temp file in the same directory and then rename, to not corrupt * simultaneous accesses by the router. Except on Windows where renameTo() * will fail if the target exists. * * @param map * A Map to write to file. * @param file * A File to write the Map to. * @throws IOException * if file cannot be written to. */ public static void write(Map<String, HostTxtEntry> map, File file) throws IOException { boolean success = false; if (!isWindows) { File tmp = SecureFile.createTempFile("temp-", ".tmp", file.getAbsoluteFile().getParentFile()); write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(tmp), "UTF-8"))); success = tmp.renameTo(file); if (!success) { tmp.delete(); //System.out.println("Warning: addressbook rename fail from " + tmp + " to " + file); } } if (!success) { // hmm, that didn't work, try it the old way write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "UTF-8"))); } }
/** * Sets output file to mode 600 */ public SecureFileOutputStream(String file) throws FileNotFoundException { super(file); setPerms(new File(file)); }
/** classpath and stopargs not supported */ public static void writeClientAppConfig(RouterContext ctx, List<ClientAppConfig> apps) { File cfgFile = configFile(ctx); FileOutputStream fos = null; try { fos = new SecureFileOutputStream(cfgFile); StringBuilder buf = new StringBuilder(2048); for(int i = 0; i < apps.size(); i++) { ClientAppConfig app = apps.get(i); buf.append(PREFIX).append(i).append(".main=").append(app.className).append("\n"); buf.append(PREFIX).append(i).append(".name=").append(app.clientName).append("\n"); if (app.args != null) buf.append(PREFIX).append(i).append(".args=").append(app.args).append("\n"); buf.append(PREFIX).append(i).append(".delay=").append(app.delay / 1000).append("\n"); buf.append(PREFIX).append(i).append(".startOnLoad=").append(!app.disabled).append("\n"); } fos.write(buf.toString().getBytes("UTF-8")); } catch (IOException ioe) { } finally { if (fos != null) try { fos.close(); } catch (IOException ioe) {} } } }
/** * Sets output file to mode 600 whether append = true or false */ public SecureFileOutputStream(String file, boolean append) throws FileNotFoundException { super(file, append); //if (!append) setPerms(new File(file)); }
try { in = new FileInputStream(oldFile); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(newFile), "UTF-8"))); String s = null; while ((s = DataHelper.readLine(in)) != null) {
SecureFileOutputStream.setPerms(ks); info("Created self-signed certificate for " + cname + " in keystore: " + ks.getAbsolutePath()); } else {
fos = new SecureFileOutputStream(ksFile); ks.store(fos, pwchars); } finally {