f = new File(base, name); else f = new SecureFile(base, name); if (!f.mkdir() && !f.isDirectory()) throw new IOException("Could not create directory " + f); f = new File(base, name); else f = new SecureFile(base, name);
/** * Caller must synchronize * * @since 0.9.1 */ private void createTemp() throws IOException { //tfile = SecureFile.createTempFile("piece", null, tempDir); // debug tempfile = SecureFile.createTempFile("piece_" + piece.getId() + '_', null, tempDir); //I2PAppContext.getGlobalContext().logManager().getLog(PartialPiece.class).warn("Created " + tempfile); // tfile.deleteOnExit() ??? raf = new RandomAccessFile(tempfile, "rw"); // Do not preallocate the file space. // Not necessary to call setLength(), file is extended when written //traf.setLength(len); }
/** * 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 } } }
/** * Creates a new <code>Folder</code> that handles files with a given extension. * @param storageDir * @param fileExtension */ protected Folder(File storageDir, String fileExtension) { this.storageDir = storageDir; this.fileExtension = fileExtension; if (!storageDir.exists() && !new SecureFile(storageDir.getAbsolutePath()).mkdirs()) log.error("Can't create directory: '" + storageDir + "'"); }
/** * Sets file to mode 600 if the file is created */ @Override public boolean createNewFile() throws IOException { boolean rv = super.createNewFile(); if (rv) setPerms(); return rv; }
public void init(ServletConfig cfg) throws ServletException { super.init(cfg); String rb=getInitParameter("resourceBase"); if (rb!=null) { File f = new SecureFile(rb); setResourceBase(f); } String wb = getInitParameter("warBase"); if (wb != null) setWarBase(wb); }
return false; in = new BufferedReader(new InputStreamReader(new FileInputStream(_file), "UTF-8"), 16*1024); File tmp = SecureFile.createTempFile("temp-", ".tmp", _file.getAbsoluteFile().getParentFile()); out = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(tmp), "UTF-8")); String line = null;
File backupDir = new SecureFile(context.getConfigDir(), TunnelController.KEY_BACKUP_DIR); File to; if (backupDir.isDirectory() || backupDir.mkdir())
/** * 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"))); } }
String b32 = dest.toBase32(); log("Base32: " + b32); File backupDir = new SecureFile(I2PAppContext.getGlobalContext().getConfigDir(), KEY_BACKUP_DIR); if (backupDir.isDirectory() || backupDir.mkdir()) { String name = b32 + '-' + I2PAppContext.getGlobalContext().clock().now() + ".dat";
/** * 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"))); } }
newDir = newDir.trim(); if (newDir.length() > 0) { dir = new SecureFile(newDir); if (!dir.isAbsolute()) { _manager.addMessage(_t("Data directory must be an absolute path") + ": " + dir);
if (_isClosed) return false; File tmp = SecureFile.createTempFile("temp-", ".tmp", _file.getAbsoluteFile().getParentFile()); out = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(tmp), "UTF-8")); if (_file.exists()) {
baseFile = new File(rootDataDir, base); else baseFile = new SecureFile(rootDataDir, base);
try { out = SecureFile.createTempFile("i2psnark", null, _tmpDir); } catch (IOException ioe) { _log.error("temp file error", ioe);
baseFile = new File(rootDataDir, base); else baseFile = new SecureFile(rootDataDir, base);
File tmp = null; try { tmp = SecureFile.createTempFile("addressbook", null, I2PAppContext.getGlobalContext().getTempDir()); EepGet get = new EepGet(I2PAppContext.getGlobalContext(), true, proxyHost, proxyPort, 0, -1l, MAX_SUB_SIZE, tmp.getAbsolutePath(), null,
String b32 = d.toBase32(); log("Base32: " + b32); File backupDir = new SecureFile(I2PAppContext.getGlobalContext().getConfigDir(), KEY_BACKUP_DIR); if (backupDir.isDirectory() || backupDir.mkdir()) { String name = b32 + '-' + I2PAppContext.getGlobalContext().clock().now() + ".dat";
File out = null; try { out = SecureFile.createTempFile("torrentFile", null, _mgr.util().getTempDir()); } catch (IOException ioe) { _log.error("temp file error", ioe);
/** * Saves the configuration to a file. */ public void save() { log.debug("Saving config file <" + configFile.getAbsolutePath() + ">"); try { DataHelper.storeProps(properties, new SecureFile(configFile.getAbsolutePath())); } catch (IOException e) { log.error("Cannot save configuration to file <" + configFile.getAbsolutePath() + ">", e); } }