List of usage examples for org.apache.commons.io FileUtils openOutputStream
public static FileOutputStream openOutputStream(File file) throws IOException
From source file:org.apache.solr.client.solrj.SolrSchemalessExampleTest.java
@BeforeClass public static void beforeClass() throws Exception { File tempSolrHome = createTempDir().toFile(); // Schemaless renames schema.xml -> schema.xml.bak, and creates + modifies conf/managed-schema, // which violates the test security manager's rules, which disallow writes outside the build dir, // so we copy the example/example-schemaless/solr/ directory to a new temp dir where writes are allowed. FileUtils.copyFileToDirectory(new File(ExternalPaths.SERVER_HOME, "solr.xml"), tempSolrHome); File collection1Dir = new File(tempSolrHome, "collection1"); FileUtils.forceMkdir(collection1Dir); FileUtils.copyDirectoryToDirectory(new File(ExternalPaths.SCHEMALESS_CONFIGSET), collection1Dir); Properties props = new Properties(); props.setProperty("name", "collection1"); OutputStreamWriter writer = null; try {/* w w w . j a v a 2s.c om*/ writer = new OutputStreamWriter(FileUtils.openOutputStream(new File(collection1Dir, "core.properties")), "UTF-8"); props.store(writer, null); } finally { if (writer != null) { try { writer.close(); } catch (Exception ignore) { } } } createJetty(tempSolrHome.getAbsolutePath()); }
From source file:org.apache.solr.SolrJettyTestBase.java
public static String legacyExampleCollection1SolrHome() { String sourceHome = ExternalPaths.SOURCE_HOME; if (sourceHome == null) throw new IllegalStateException( "No source home! Cannot create the legacy example solr home directory."); String legacyExampleSolrHome = null; try {//w w w .j av a 2 s.c o m File tempSolrHome = LuceneTestCase.createTempDir().toFile(); org.apache.commons.io.FileUtils.copyFileToDirectory(new File(sourceHome, "server/solr/solr.xml"), tempSolrHome); File collection1Dir = new File(tempSolrHome, "collection1"); org.apache.commons.io.FileUtils.forceMkdir(collection1Dir); File configSetDir = new File(sourceHome, "server/solr/configsets/sample_techproducts_configs/conf"); org.apache.commons.io.FileUtils.copyDirectoryToDirectory(configSetDir, collection1Dir); Properties props = new Properties(); props.setProperty("name", "collection1"); OutputStreamWriter writer = null; try { writer = new OutputStreamWriter( FileUtils.openOutputStream(new File(collection1Dir, "core.properties")), "UTF-8"); props.store(writer, null); } finally { if (writer != null) { try { writer.close(); } catch (Exception ignore) { } } } legacyExampleSolrHome = tempSolrHome.getAbsolutePath(); } catch (Exception exc) { if (exc instanceof RuntimeException) { throw (RuntimeException) exc; } else { throw new RuntimeException(exc); } } return legacyExampleSolrHome; }
From source file:org.apache.sqoop.test.minicluster.SqoopMiniCluster.java
/** * Prepare temporary directory for starting Sqoop server. * * @throws IOException/*from w w w .ja v a2 s . c o m*/ */ protected void prepareTemporaryPath() throws IOException { File tmpDir = new File(getTemporaryPath()); File configDir = new File(getConfigurationPath()); File logDir = new File(getLogPath()); FileUtils.deleteDirectory(tmpDir); FileUtils.forceMkdir(tmpDir); FileUtils.forceMkdir(configDir); FileUtils.forceMkdir(logDir); // Create configuration files System.setProperty(ConfigurationConstants.SYSPROP_CONFIG_DIR, getConfigurationPath()); // sqoop_bootstrap.properties FileUtils.writeStringToFile(new File(getConfigurationPath() + "sqoop_bootstrap.properties"), "sqoop.config.provider=org.apache.sqoop.core.PropertiesConfigurationProvider"); // sqoop.properties // TODO: This should be generated more dynamically so that user can specify Repository, Submission and Execution engines File f = new File(getConfigurationPath() + "sqoop.properties"); List<String> sqoopProperties = new LinkedList<String>(); mapToProperties(sqoopProperties, getLoggerConfiguration()); mapToProperties(sqoopProperties, getRepositoryConfiguration()); mapToProperties(sqoopProperties, getSubmissionEngineConfiguration()); mapToProperties(sqoopProperties, getExecutionEngineConfiguration()); FileUtils.writeLines(f, sqoopProperties); // Hadoop configuration OutputStream stream = FileUtils.openOutputStream(new File(getConfigurationPath() + "hadoop-site.xml")); configuration.writeXml(stream); stream.close(); }
From source file:org.apache.storm.LocalStateTest.java
@Test public void testEmptyState() throws IOException { TmpPath tmp_dir = new TmpPath(); String dir = tmp_dir.getPath(); LocalState ls = new LocalState(dir); GlobalStreamId gs_a = new GlobalStreamId("a", "a"); FileOutputStream data = FileUtils.openOutputStream(new File(dir, "12345")); FileOutputStream version = FileUtils.openOutputStream(new File(dir, "12345.version")); Assert.assertNull(ls.get("c")); ls.put("a", gs_a); Assert.assertEquals(gs_a, ls.get("a")); }
From source file:org.apache.synapse.config.xml.MultiXMLConfigurationSerializer.java
private void writeToFile(OMElement content, File file) throws Exception { File tempFile = File.createTempFile("syn_mx_", ".xml"); OutputStream out = FileUtils.openOutputStream(tempFile); XMLPrettyPrinter.prettify(content, out); out.flush();/*w ww . j a v a 2s . c om*/ out.close(); FileUtils.copyFile(tempFile, file); FileUtils.deleteQuietly(tempFile); }
From source file:org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.java
protected void writeToFile(OMElement content, String fileName) throws Exception { // this is not good, but I couldn't think of a better design :-( SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration().getArtifactDeploymentStore(); deploymentStore.addRestoredArtifact(fileName); OutputStream out = FileUtils.openOutputStream(new File(fileName)); XMLPrettyPrinter.prettify(content, out); out.flush();/* ww w . java 2 s . c om*/ out.close(); }
From source file:org.apache.sysml.utils.NativeHelper.java
private static boolean loadLibraryHelper(String path) { OutputStream out = null;/*from w w w . ja v a 2s.c o m*/ try (InputStream in = NativeHelper.class.getResourceAsStream("/lib/" + path)) { // This logic is added because Java does not allow to load library from a resource file. if (in != null) { File temp = File.createTempFile(path, ""); temp.deleteOnExit(); out = FileUtils.openOutputStream(temp); IOUtils.copy(in, out); System.load(temp.getAbsolutePath()); return true; } else LOG.warn("No lib available in the jar:" + path); } catch (IOException e) { LOG.warn("Unable to load library " + path + " from resource:" + e.getMessage()); } finally { IOUtilFunctions.closeSilently(out); } return false; }
From source file:org.apromore.service.logfilter.impl.InfrequentBehaviourFilterServiceImpl.java
private static void loadLibWin(String path, String name) { try {/*from w w w. java 2 s. co m*/ // have to use a stream InputStream in = InfrequentBehaviourFilter.class.getResourceAsStream("/" + name); // always write to different location File fileOut = new File(name); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); } catch (Exception e) { throw new RuntimeException("Failed to load required DLL", e); } }
From source file:org.apromore.service.logfilter.impl.InfrequentBehaviourFilterServiceImpl.java
private static void loadLibMac(String path, String name) { try {/*from w w w . j a va 2 s . co m*/ // have to use a stream InputStream in = InfrequentBehaviourFilter.class.getResourceAsStream("/" + name); // always write to different location File fileOut = new File(name); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); } catch (Exception e) { throw new RuntimeException("Failed to load required JNILIB", e); } }
From source file:org.archive.util.Recorder.java
/** * @param tempFile/* w w w.j a v a2s. c o m*/ * @throws IOException */ public void copyContentBodyTo(File tempFile) throws IOException { InputStream inStream = null; OutputStream outStream = null; try { inStream = getContentReplayInputStream(); outStream = FileUtils.openOutputStream(tempFile); IOUtils.copy(inStream, outStream); } finally { IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } }