/** * Overwrites the file by the given string. */ public void write(String text) throws IOException { file.getParentFile().mkdirs(); AtomicFileWriter w = new AtomicFileWriter(file); try { w.write(text); w.commit(); } finally { w.abort(); } }
checkPermission(CONFIGURE); XmlFile configXmlFile = getConfigFile(); final AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { XMLUtils.safeTransform(source, new StreamResult(out)); out.close(); } catch (TransformerException | SAXException e) { throw new IOException("Failed to persist config.xml", e); Object o = new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshalNullingOut(this); if (o!=this) { out.commit(); SaveableListener.fireOnChange(this, getConfigFile()); out.abort(); // don't leave anything behind
public boolean rewrite(File f) throws InvalidKeyException, IOException { AtomicFileWriter w = new AtomicFileWriter(f, "UTF-8"); try { w.commit(); w.abort();
private void closeAndDeleteTempFile() throws IOException { // one way or the other, temporary file should be deleted. try { close(); } finally { Files.deleteIfExists(tmpPath); } }
file.getParentFile().mkdirs(); AtomicFileWriter afw = new AtomicFileWriter(file); try { PrintWriter w = new PrintWriter(afw); w.print("</fingerprint>"); w.flush(); afw.commit(); } finally { afw.abort();
public void commit() throws IOException { close(); try {
private void save(File dir) { File f = new File(dir, MAP_FILE); try { AtomicFileWriter w = new AtomicFileWriter(f); try { for (Map.Entry<String,Integer> entry : idToNumber.entrySet()) { w.write(entry.getKey() + ' ' + entry.getValue() + '\n'); } w.commit(); } finally { w.abort(); } } catch (IOException x) { LOGGER.log(WARNING, "could not save changes to " + f, x); } }
checkPermission(CONFIGURE); XmlFile configXmlFile = getConfigFile(); final AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { XMLUtils.safeTransform(source, new StreamResult(out)); out.close(); } catch (TransformerException | SAXException e) { throw new IOException("Failed to persist config.xml", e); Object o = new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(this); if (o!=this) { out.commit(); SaveableListener.fireOnChange(this, getConfigFile()); out.abort(); // don't leave anything behind
public boolean rewrite(File f) throws InvalidKeyException, IOException { AtomicFileWriter w = new AtomicFileWriter(f, "UTF-8"); try { w.commit(); w.abort();
/** * When the write operation failed, call this method to * leave the original file intact and remove the temporary file. * This method can be safely invoked from the "finally" block, even after * the {@link #commit()} is called, to simplify coding. */ public void abort() throws IOException { close(); tmpFile.delete(); }
public void write( Object o ) throws IOException { mkdirs(); AtomicFileWriter w = new AtomicFileWriter(file); try { w.write("<?xml version='1.1' encoding='UTF-8'?>\n"); beingWritten.put(o, null); writing.set(file); try { xs.toXML(o, w); } finally { beingWritten.remove(o); writing.set(null); } w.commit(); } catch(RuntimeException e) { throw new IOException(e); } finally { w.abort(); } }
AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { t.transform(source, new StreamResult(out)); out.close(); } catch (TransformerException e) { throw new IOException2("Failed to persist configuration.xml", e); new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(project); project.onLoad(project.getParent(), project.getRootDir().getName()); Jenkins.getInstance().rebuildDependencyGraph(); out.commit(); return ProjectUtils.findProject(project.getFullName()); } finally { out.abort(); // don't leave anything behind
file.getParentFile().mkdirs(); AtomicFileWriter afw = new AtomicFileWriter(file); try { PrintWriter w = new PrintWriter(afw); w.print("</fingerprint>"); w.flush(); afw.commit(); } finally { afw.abort();
@Override protected void finalize() throws Throwable { // one way or the other, temporary file should be deleted. close(); tmpFile.delete(); }
static void writeSymlink(File cache, String target) throws IOException, InterruptedException { LOGGER.log(Level.FINE, "writeSymlink {0} → {1}", new Object[] {cache, target}); synchronized (symlinks) { symlinks.put(cache, target); } StringWriter w = new StringWriter(); StreamTaskListener listener = new StreamTaskListener(w); Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener); // Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException: if (!exists(cache) || Util.resolveSymlink(cache)==null) { // symlink not supported. use a regular file AtomicFileWriter cw = new AtomicFileWriter(cache); try { cw.write(target); cw.commit(); } finally { cw.abort(); } } }
final String projectName = project.getName(); XmlFile configXmlFile = project.getConfigFile(); final AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { XMLUtils.safeTransform(source, new StreamResult(out)); out.close(); } catch (SAXException | TransformerException e) { throw new IOException("Failed to persist config.xml", e); Object o = new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(project); if (o != project) { out.commit(); } finally { out.abort();
/** * When the write operation failed, call this method to * leave the original file intact and remove the temporary file. * This method can be safely invoked from the "finally" block, even after * the {@link #commit()} is called, to simplify coding. */ public void abort() throws IOException { close(); tmpFile.delete(); }
/** * Overwrites the file by the given string. */ public void write(String text) throws IOException { file.getParentFile().mkdirs(); AtomicFileWriter w = new AtomicFileWriter(file); try { w.write(text); w.commit(); } finally { w.abort(); } }
AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile()); try { try { t.transform(new StreamSource(req.getReader()), new StreamResult(out)); out.close(); } catch (TransformerException e) { throw new IOException2("Failed to persist configuration.xml", e); new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(this); onLoad(getParent(), getRootDir().getName()); out.commit(); } finally { out.abort(); // don't leave anything behind
/** * When the write operation failed, call this method to * leave the original file intact and remove the temporary file. * This method can be safely invoked from the "finally" block, even after * the {@link #commit()} is called, to simplify coding. */ public void abort() throws IOException { close(); tmpFile.delete(); }