List of usage examples for org.apache.commons.io FileUtils writeLines
public static void writeLines(File file, Collection lines) throws IOException
toString()
value of each item in a collection to the specified File
line by line. From source file:com.github.jrh3k5.mojo.flume.AbstractFlumeAgentsMojoTest.java
/** * Test the copying of logging properties. * /*from w w w . ja va 2 s. c om*/ * @throws Exception * If any errors occur during the test run. * @since 2.1.1 */ @Test public void testCopyLoggingProperties() throws Exception { final File unitTestDir = new File(String.format("target/unit-tests/%s/testCopyLoggingProperties/%s", getClass().getSimpleName(), UUID.randomUUID())); final File flumeDirectory = new File(unitTestDir, "flume"); final File loggingProperties = new File(unitTestDir, "logging.properties"); final String loggingPropertiesText = UUID.randomUUID().toString(); FileUtils.writeLines(loggingProperties, Collections.singleton(loggingPropertiesText)); when(agent.getLoggingProperties()).thenReturn(loggingProperties); mojo.copyLoggingProperties(agent, flumeDirectory); // The file should have been copied to conf/log4j.properties beneath the Flume directory final File expectedLoggingProperties = new File(flumeDirectory, "conf/log4j.properties"); assertThat(expectedLoggingProperties).exists(); // Trim, because FileUtils.writeLines() adds newline characters assertThat(FileUtils.readFileToString(expectedLoggingProperties).trim()).isEqualTo(loggingPropertiesText); }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
@Test public void testLegacyPasswordPlainTextIsplaintextNotSet() throws Exception { final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_plain_notset.properties"); final File configFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test1"); filesToDelete.add(configFile);/*from w w w. ja va 2s. co m*/ configFile.deleteOnExit(); FileUtils.copyFile(sourceConfigFile, configFile); final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath()); final List<String> origLines = cf.getLines(); List<String> updatedLines = null; if (cf.isInNeedOfUpdate()) { updatedLines = cf.saveWithEncryptedPasswords(); } assertTrue(updatedLines.size() > 0); final Iterator<String> updatedLinesIter = updatedLines.iterator(); for (final String origLine : origLines) { if (!updatedLinesIter.hasNext()) { fail("Updated file has fewer lines than original"); } String updatedLine = updatedLinesIter.next(); // make sure obsolete properties didn't sneak in somehow assertFalse(updatedLine.matches("^.*\\.password\\.isplaintext=.*$")); // If this is a password, verify that it was encoded, and that the // isencrypted=true was inserted after it if (origLine.startsWith("cc.password=")) { assertEquals( "cc.password=,\\(f9b^6ck-Sr-A2!jWeRlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P", updatedLine); updatedLine = updatedLinesIter.next(); assertEquals("cc.password.isencrypted=true", updatedLine); } else if (origLine.startsWith("protex.password=")) { assertEquals( "protex.password=DQp'L-+/0Fq0jsi2f'\\\\OlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P", updatedLine); updatedLine = updatedLinesIter.next(); assertEquals("protex.password.isencrypted=true", updatedLine); } else if (origLine.startsWith("connector.0.password=")) { assertEquals( "connector.0.password=6'ND2^gdVX/0\\$fYH7TeH04Sh8FAG<\\[lI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P", updatedLine); updatedLine = updatedLinesIter.next(); assertEquals("connector.0.password.isencrypted=true", updatedLine); } else { assertEquals(origLine, updatedLine); } } final File testGeneratedUpdatedFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test1_testGeneratedUpdatedFile"); filesToDelete.add(testGeneratedUpdatedFile); testGeneratedUpdatedFile.deleteOnExit(); FileUtils.writeLines(testGeneratedUpdatedFile, updatedLines); final long csumTestGeneratedFile = FileUtils.checksum(testGeneratedUpdatedFile, new CRC32()).getValue(); final long csumActualFile = FileUtils.checksum(configFile, new CRC32()).getValue(); assertEquals(csumTestGeneratedFile, csumActualFile); }
From source file:com.taobao.android.builder.tasks.helper.AtlasListTask.java
@TaskAction public void executeTask() { Project project = getProject();//from w w w .ja va 2 s . co m AtlasExtension atlasExtension = project.getExtensions().getByType(AtlasExtension.class); List<AtlasConfigField> list = null; try { list = AtlasConfigHelper.readConfig(atlasExtension, "atlas"); } catch (Throwable e) { e.printStackTrace(); return; } List<String> lines = new ArrayList<>(); lines.add(" | ??? | | "); lines.add(" ------------- | ------------- | ------------- | ------------- "); for (AtlasConfigField configField : list) { lines.add(configField.desc + " | " + configField.name + " | " + configField.type + " | " + configField.value); } for (String line : lines) { project.getLogger().error(line); } File file = new File(project.getProjectDir(), "atlasConfigList.MD"); try { FileUtils.writeLines(file, lines); project.getLogger().error(file.getAbsolutePath() + " has generated"); } catch (IOException e) { e.printStackTrace(); } try { FileUtils.write(new File(project.getProjectDir(), "atlasConfigList.json"), JSON.toJSONString(list, true)); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.inmobi.grill.driver.hive.TestRemoteHiveDriver.java
private void createPartitionedTable(String tableName, int partitions) throws Exception { conf.setBoolean(GrillConfConstants.GRILL_ADD_INSERT_OVEWRITE, false); conf.setBoolean(GrillConfConstants.GRILL_PERSISTENT_RESULT_SET, false); QueryContext ctx = new QueryContext("CREATE EXTERNAL TABLE IF NOT EXISTS " + tableName + " (ID STRING) PARTITIONED BY (DT STRING, ET STRING)", null, conf); driver.execute(ctx);// w w w . j ava 2s . c o m Assert.assertEquals(0, driver.getHiveHandleSize()); File dataDir = new File("target/partdata"); dataDir.mkdir(); // Add partitions for (int i = 0; i < partitions; i++) { // Create partition paths File tableDir = new File(dataDir, tableName); tableDir.mkdir(); File partDir = new File(tableDir, "p" + i); partDir.mkdir(); // Create data file File data = new File(partDir, "data.txt"); FileUtils.writeLines(data, Arrays.asList("one", "two", "three", "four", "five")); System.out.println("@@ Adding partition " + i); QueryContext partCtx = new QueryContext("ALTER TABLE " + tableName + " ADD IF NOT EXISTS PARTITION (DT='p" + i + "', ET='1') LOCATION '" + partDir.getPath() + "'", null, conf); driver.execute(partCtx); } }
From source file:com.taobao.android.builder.tasks.app.prepare.PrepareBundleInfoTask.java
private void generateBundleListCfg(AppVariantContext appVariantContext) throws IOException { List<String> bundleLists = AtlasBuildContext.awbBundleMap.values().stream() .filter(awbBundle -> !awbBundle.isMBundle).map(awbBundle -> { return appVariantOutputContext.getAwbPackageOutputFilePath(awbBundle); }).sorted().collect(Collectors.toList()); File outputFile = new File(appVariantContext.getScope().getGlobalScope().getOutputsDir(), "bundleList.cfg"); FileUtils.deleteQuietly(outputFile); outputFile.getParentFile().mkdirs(); FileUtils.writeLines(outputFile, bundleLists); appVariantContext.bundleListCfg = outputFile; //Set the bundle dependencies List<BundleInfo> bundleInfos = new ArrayList<>(); AtlasBuildContext.awbBundleMap.values().stream() .forEach(awbBundle -> bundleInfos.add(awbBundle.bundleInfo)); }
From source file:com.alibaba.jstorm.hdfs.transaction.RocksDbHdfsState.java
@Override public String backup(long batchId) { try {/* w w w.ja v a2s . co m*/ String hdfsCpDir = getRemoteCheckpointPath(batchId); String batchCpPath = getLocalCheckpointPath(batchId); long startTime = System.currentTimeMillis(); // upload sst data files to hdfs Collection<File> sstFiles = FileUtils.listFiles(new File(batchCpPath), new String[] { ROCKSDB_DATA_FILE_EXT }, false); for (File sstFile : sstFiles) { if (!lastCheckpointFiles.contains(sstFile.getName())) { hdfsCache.copyToDfs(batchCpPath + "/" + sstFile.getName(), hdfsDbDir, true); } } // upload sstFile.list, CURRENT, MANIFEST to hdfs Collection<String> sstFileList = getFileList(sstFiles); File cpFileList = new File(batchCpPath + "/" + SST_FILE_LIST); FileUtils.writeLines(cpFileList, sstFileList); if (hdfsCache.exist(hdfsCpDir)) hdfsCache.remove(hdfsCpDir, true); hdfsCache.mkdir(hdfsCpDir); Collection<File> allFiles = FileUtils.listFiles(new File(batchCpPath), null, false); allFiles.removeAll(sstFiles); Collection<File> nonSstFiles = allFiles; for (File nonSstFile : nonSstFiles) { hdfsCache.copyToDfs(batchCpPath + "/" + nonSstFile.getName(), hdfsCpDir, true); } if (JStormMetrics.enabled) hdfsWriteLatency.update(System.currentTimeMillis() - startTime); lastCheckpointFiles = sstFileList; return hdfsCpDir; } catch (IOException e) { LOG.error("Failed to upload checkpoint", e); throw new RuntimeException(e.getMessage()); } }
From source file:com.izforge.izpack.compiler.packager.impl.PackagerBase.java
/** * Write manifest in the install jar.//from w w w. j a v a2 s . c o m * * @throws IOException for any I/O error */ protected void writeManifest() throws IOException { // Add splash screen configuration List<String> lines = IOUtils.readLines(getClass().getResourceAsStream("MANIFEST.MF")); if (splashScreenImage != null) { String destination = String.format("META-INF/%s", splashScreenImage.getName()); mergeManager.addResourceToMerge(splashScreenImage.getAbsolutePath(), destination); lines.add(String.format("SplashScreen-Image: %s", destination)); } lines.add(""); File tempManifest = com.izforge.izpack.util.file.FileUtils.createTempFile("MANIFEST", ".MF"); FileUtils.writeLines(tempManifest, lines); mergeManager.addResourceToMerge(tempManifest.getAbsolutePath(), "META-INF/MANIFEST.MF"); }
From source file:io.seqware.pipeline.plugins.WorkflowSchedulerTest.java
@Test public void testLeftToRightOverrideByCLI() throws IOException { String[] iniFileContents1 = { "min_qual_score=30", "min_percent_bases=90", "cat=dog" }; String[] iniFileContents2 = { "min_qual_score=40", "min_percent_bases=100" }; String[] iniFileContents3 = { "min_qual_score=50" }; File ini1 = File.createTempFile("ini", "ini"); File ini2 = File.createTempFile("ini", "ini"); File ini3 = File.createTempFile("ini", "ini"); ini1.deleteOnExit();// w w w .j av a2 s . c o m ini2.deleteOnExit(); ini3.deleteOnExit(); FileUtils.writeLines(ini1, Arrays.asList(iniFileContents1)); FileUtils.writeLines(ini2, Arrays.asList(iniFileContents2)); FileUtils.writeLines(ini3, Arrays.asList(iniFileContents3)); launchPlugin("--workflow-accession", "2861", "--host", FileTools.getLocalhost(null).hostname, "--ini-files", ini1.getAbsolutePath() + "," + ini2.getAbsolutePath() + "," + ini3.getAbsolutePath(), "--", "--output_dir", "zebra", "--min_qual_score", "0"); String s = getOut(); String firstWorkflowRun = getAndCheckSwid(s); BasicTestDatabaseCreator dbCreator = new BasicTestDatabaseCreator(); List<Object[]> runQuery = dbCreator.runQuery(new ArrayListHandler(), "select r.status, r.workflow_id, r.ini_file from workflow_run r\n" + "WHERE \n" + "r.sw_accession = ?\n" + "; ", Integer.valueOf(firstWorkflowRun)); Assert.assertTrue( "schedule workflow is incorrect " + runQuery.get(0)[0].toString() + " " + runQuery.get(0)[1].toString(), runQuery.get(0)[0].equals(WorkflowRunStatus.submitted.toString()) && runQuery.get(0)[1].equals(16)); WorkflowRun workflowRun = metadata.getWorkflowRun(Integer.valueOf(firstWorkflowRun)); // check that default keys are present Map<String, String> baseMap = MapTools.iniString2Map(workflowRun.getIniFile()); Assert.assertTrue("overridden map is missing variables", baseMap.containsKey("min_qual_score") && baseMap.containsKey("inputs_read_1") && baseMap.containsKey("inputs_read_2") && baseMap.containsKey("cat") && baseMap.containsKey("output_prefix") && baseMap.containsKey("output_dir") && baseMap.containsKey("min_percent_bases")); Assert.assertTrue("overridden map has incorrect values", baseMap.get("min_qual_score").equals("0") && baseMap.get("cat").equals("dog") && baseMap.get("min_percent_bases").equals("100") && baseMap.get("output_dir").equals("zebra")); }
From source file:es.uvigo.ei.sing.adops.operations.running.ExecuteExperimentBySteps.java
private void replaceSequenceNamesAln(File inputFile, File outputFile) throws IOException { final Map<String, String> names = this.experiment.getNames(); final List<String> lines = FileUtils.readLines(inputFile); int maxLength = Integer.MIN_VALUE; for (Map.Entry<String, String> name : names.entrySet()) { maxLength = Math.max(maxLength, name.getValue().length()); }//from w w w . j a v a 2s .c o m for (Map.Entry<String, String> name : names.entrySet()) { String newName = name.getValue(); while (newName.length() < maxLength) { newName += ' '; } name.setValue(newName); } final ListIterator<String> itLines = lines.listIterator(); if (itLines.hasNext()) itLines.next(); // TODO Review parsing while (itLines.hasNext()) { itLines.next(); // White line String line = null; // Sequences while (itLines.hasNext()) { line = itLines.next(); if (line.isEmpty()) break; final String[] lineSplit = line.split("\\s+"); final String name = lineSplit.length == 0 ? "" : lineSplit[0]; if (names.get(name) == null) break; itLines.set(names.get(name) + " " + lineSplit[1]); } // Marks line if (line != null && !line.isEmpty() && line.startsWith(" ")) { String newLine = line; if (maxLength < 13) newLine = newLine.substring(13 - maxLength); else for (int i = 16; i < maxLength + 3; i++) { newLine = ' ' + newLine; } itLines.set(newLine); } } FileUtils.writeLines(outputFile, lines); }
From source file:com.taobao.android.builder.tasks.app.bundle.AwbProguardConfiguration.java
/** * ?proguardconfig//from w w w . j ava2s. c o m * * @param outConfigFile */ public void printConfigFile(File outConfigFile) throws IOException { List<String> configs = Lists.newArrayList(); //awblib??proguardpredex for (AwbTransform awbTransform : awbTransforms) { List<File> inputLibraries = Lists.newArrayList(); String name = awbTransform.getAwbBundle().getName(); File obuscateDir = new File(awbObfuscatedDir, awbTransform.getAwbBundle().getName()); obuscateDir.mkdirs(); // configs.add(); if (null != awbTransform.getInputDir() && awbTransform.getInputDir().exists()) { configs.add(INJARS_OPTION + " " + awbTransform.getInputDir().getAbsolutePath()); File obsJar = new File(obuscateDir, "inputdir_" + OBUSCATED_JAR); inputLibraries.add(obsJar); configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath()); } Set<String> classNames = new HashSet<>(); for (File inputLibrary : awbTransform.getInputLibraries()) { configs.add(INJARS_OPTION + " " + inputLibrary.getAbsolutePath()); String fileName = inputLibrary.getName(); if (classNames.contains(fileName)) { fileName = "a" + classNames.size() + "_" + fileName; } classNames.add(fileName); File obsJar = new File(obuscateDir, fileName); inputLibraries.add(obsJar); configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath()); } // configs.add(); awbTransform.setInputFiles(inputLibraries); awbTransform.setInputDir(null); awbTransform.getInputLibraries().clear(); appVariantOutputContext.getAwbTransformMap().put(name, awbTransform); } FileUtils.writeLines(outConfigFile, configs); }