List of usage examples for org.apache.commons.io FileUtils openOutputStream
public static FileOutputStream openOutputStream(File file) throws IOException
From source file:gov.usgs.anss.query.MSOutputer.java
public void makeFile(NSCL nscl, String filename, ArrayList<MiniSeed> blks) throws IOException { MiniSeed ms2 = null;/* w w w . ja v a2s . c om*/ if (options.filemask.equals("%N")) { filename += ".ms"; } filename = filename.replaceAll("[__]", "_"); FileOutputStream out = FileUtils.openOutputStream(new File(filename)); if (!options.nosort) { Collections.sort(blks); } if (options.chkDups) { for (int i = blks.size() - 1; i > 0; i--) { if (blks.get(i).isDuplicate(blks.get(i - 1))) { blks.remove(i); } } } for (int i = 0; i < blks.size(); i++) { ms2 = (MiniSeed) blks.get(i); logger.fine("Out:" + ms2.getSeedName() + " " + ms2.getTimeString() + " ns=" + ms2.getNsamp() + " rt=" + ms2.getRate()); out.write(ms2.getBuf(), 0, ms2.getBlockSize()); } out.close(); }
From source file:com.picklecode.popflix.App.java
private static void loadLib(String name) { try {//from w ww .ja va 2 s . co m if (isWindows()) { name = name.substring("lib".length()); } String ext = getExtension(); name = name + ext; LOG.info(System.getProperty("os.arch")); LOG.info(System.getProperty("os.name")); Path tmp = Files.createTempDirectory("popflix"); setLibraryPath(tmp.toString()); LOG.info(tmp.toString() + "/" + name); File fileOut = new File(tmp.toString() + "/" + name); LOG.info(System.getProperty("java.library.path")); System.out.println("/lib/" + getFolder() + "/" + name); InputStream in = Popflix.class.getResourceAsStream("/lib/" + getFolder() + "/" + name); if (in != null) { OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); } System.load(fileOut.getAbsolutePath());//loading goes here } catch (Exception e) { LOG.error(e.getMessage()); System.exit(-1); } }
From source file:com.haulmont.cuba.desktop.sys.MainWindowProperties.java
public void save() { Properties properties = new Properties(); saveProperties(properties);/* ww w . j ava 2 s. c o m*/ try { File file = new File(AppBeans.get(Configuration.class).getConfig(GlobalConfig.class).getDataDir(), "main-window.properties"); FileOutputStream stream = FileUtils.openOutputStream(file); try { properties.store(stream, "Main window properties"); } finally { IOUtils.closeQuietly(stream); } } catch (IOException e) { log.error("Error saving main window location", e); } }
From source file:edu.scripps.fl.pubchem.app.cids.WriteSDFStage.java
@Override public void process(Object obj) throws StageException { URL url = (URL) obj;// w w w . jav a 2s. c o m try { File outputFile = newOutputFile(counter.incrementAndGet()); logger.info("Writing SDF file: " + outputFile); IOUtils.copy(new GZIPInputStream(url.openStream()), FileUtils.openOutputStream(outputFile)); emit(outputFile); } catch (Exception ex) { throw new StageException(this, ex); } }
From source file:gov.nih.nci.caarray.services.external.v1_0.data.AbstractDataApiUtils.java
/** * {@inheritDoc}/* ww w . j ava2s . c o m*/ */ public void downloadFileContentsToFile(CaArrayEntityReference fileRef, boolean compressed, File toFile) throws InvalidReferenceException, DataTransferException, IOException { OutputStream ostream = FileUtils.openOutputStream(toFile); try { copyFileContentsToOutputStream(fileRef, compressed, ostream); } finally { if (ostream != null) { ostream.close(); } } }
From source file:com.digitalpebble.stormcrawler.parse.filter.DebugParseFilter.java
@SuppressWarnings("rawtypes") @Override//from w w w . j av a 2 s .c o m public void configure(Map stormConf, JsonNode filterParams) { try { File outFile = File.createTempFile("DOMDump", ".xml"); os = FileUtils.openOutputStream(outFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.digitalpebble.storm.crawler.parse.filter.DebugParseFilter.java
@SuppressWarnings("rawtypes") @Override// ww w . j a va2s . c o m public void configure(Map stormConf, JsonNode filterParams) { try { File outFile = File.createTempFile("DOMDump", ".txt"); os = FileUtils.openOutputStream(outFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.github.tddts.jet.util.Util.java
/** * Save given property to given propeorty file. * * @param fileName property file path//from w w w . jav a2 s . c om * @param key property key * @param value property value */ public static void saveProperty(String fileName, String key, String value) { try { File file = new File(fileName); if (!file.exists()) file.createNewFile(); Properties properties = new Properties(); try (InputStream in = FileUtils.openInputStream(file)) { properties.load(in); } properties.setProperty(key, value); try (OutputStream out = FileUtils.openOutputStream(file)) { properties.store(out, ""); } } catch (IOException e) { throw new ApplicationException(e); } }
From source file:de.iritgo.aktario.client.gui.UserLoginHelper.java
/** *//*from ww w . java 2 s. c om*/ public static boolean login(final UserLoginPane loginPane, final String server, final String username, final String password, final boolean remember, final boolean autoLogin) { AppContext.instance().setServerIP(server); connectAndGo(username, password, loginPane); final FlowControl flowControl = Engine.instance().getFlowControl(); flowControl.add(new FrameworkFlowRule("UserLogin", null, null) { @Override public void success() { flowControl.clear(); AktarioGUI gui = (AktarioGUI) Client.instance().getClientGUI(); new Thread(new Runnable() { public void run() { try { InputStream input = new URL("http://" + server + "/autoupdate.jar").openStream(); String workingDirPath = Engine.instance().getSystemDir(); IOUtils.copy(input, FileUtils.openOutputStream(new File( workingDirPath + System.getProperty("file.separator") + "autoupdate.jar"))); } catch (Exception x) { } }; }).start(); gui.show(); gui.setStatusUser(username + "@" + server); Engine.instance().getSystemProperties().setProperty("lastlogin", username + "@" + server); if (loginPane != null) { if (remember) { loginPane.rememberAccount(); } else { loginPane.removeAccount(); } if (autoLogin) { loginPane.rememberAutoLogin(); } } } @Override public void failure(Object arg) { int failure = ((Integer) arg).intValue(); Client.instance().getNetworkService().closeAllChannels(); if (failure == UserLoginFailureAction.USER_ALREADY_ONLINE) { setCompleteState(false); Properties props = new Properties(); props.put("failure", arg); Command cmd = new ShowDialog("AktarioUserLoginFailureDialog"); cmd.setProperties(props); CommandTools.performSimple(cmd); try { Thread.sleep(10000); } catch (Exception x) { } connectAndGo(username, password, loginPane); return; } if (failure == UserLoginFailureAction.LOGIN_NOT_ALLOWED) { setCompleteState(false); Properties props = new Properties(); props.put("failure", arg); Command cmd = new ShowDialog("AktarioUserLoginFailureDialog"); cmd.setProperties(props); CommandTools.performSimple(cmd); return; } if (failure == UserLoginFailureAction.BAD_USERNAME_OR_PASSWORD) { setCompleteState(false); Properties props = new Properties(); props.put("failure", arg); Command cmd = new ShowDialog("AktarioUserLoginFailureDialog"); cmd.setProperties(props); CommandTools.performSimple(cmd); return; } } }); flowControl.add(new FrameworkFlowRule("WrongVersion", null, null) { @Override public void success() { flowControl.clear(); Client.instance().getNetworkService().closeAllChannels(); JOptionPane.showMessageDialog(loginPane != null ? loginPane.getPanel() : null, Engine.instance().getResourceService().getStringWithoutException("wrongClientVersion"), Engine.instance().getResourceService().getStringWithoutException("systemMessage"), JOptionPane.OK_OPTION); try { String workingDirPath = Engine.instance().getSystemDir(); if (workingDirPath.endsWith("\\")) { workingDirPath = workingDirPath.substring(0, workingDirPath.length() - 1); } @SuppressWarnings("unused") Process proc = Runtime.getRuntime() .exec("java" + " -jar \"" + workingDirPath + Engine.instance().getFileSeparator() + "autoupdate.jar\" http://" + AppContext.instance().getServerIP() + "/update.jar" + " \"" + workingDirPath + "\""); } catch (Exception x) { JOptionPane.showMessageDialog(loginPane != null ? loginPane.getPanel() : null, x.toString(), "Iritgo", JOptionPane.OK_OPTION); } System.exit(0); } }); return false; }
From source file:com.carolinarollergirls.scoreboard.xml.AutoSaveScoreBoard.java
public void run() { FileOutputStream fos = null;//from ww w. j a v a2 s. c o m try { int n = AUTOSAVE_FILES; getFile(n).delete(); while (n > 0) { File to = getFile(n); File from = getFile(--n); if (from.exists()) FileUtils.moveFile(from, to); } fos = FileUtils.openOutputStream(getFile(0)); xmlOutputter.output(editor.filterNoSavePI(xmlScoreBoard.getDocument()), fos); } catch (Exception e) { ScoreBoardManager.printMessage("WARNING: Unable to auto-save scoreboard : " + e.getMessage()); } finally { if (null != fos) try { fos.close(); } catch (IOException ioE) { } } }