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.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
/** * We don't handle this scenario//ww w . j a v a 2 s . c o m * * @throws Exception */ @Test public void testLegacyPasswordBase64IsplaintextNotSet() throws Exception { final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_base64_notset.properties"); final File configFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test3"); filesToDelete.add(configFile); configFile.deleteOnExit(); FileUtils.copyFile(sourceConfigFile, configFile); final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath()); List<String> updatedLines = null; if (cf.isInNeedOfUpdate()) { updatedLines = cf.saveWithEncryptedPasswords(); } // This warning has been disabled to avoid calling isBase64, which // causes problems for RGT // System.out.println("There should be 3 warnings in the log about possibly-base64-encoded passwords"); assertTrue(updatedLines.size() > 0); final Iterator<String> updatedLinesIter = updatedLines.iterator(); while (updatedLinesIter.hasNext()) { String updatedLine = updatedLinesIter.next(); // make sure obsolete properties have been removed 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 (updatedLine.startsWith("cc.password=")) { // There's not much point in checking the value of password, // since it is wrong updatedLine = updatedLinesIter.next(); assertEquals("cc.password.isencrypted=true", updatedLine); } else if (updatedLine.startsWith("protex.password=")) { // There's not much point in checking the value of password, // since it is wrong updatedLine = updatedLinesIter.next(); assertEquals("protex.password.isencrypted=true", updatedLine); } else if (updatedLine.startsWith("connector.0.password=")) { // There's not much point in checking the value of password, // since it is wrong updatedLine = updatedLinesIter.next(); assertEquals("connector.0.password.isencrypted=true", updatedLine); } } final File testGeneratedUpdatedFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test3_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:de.aeb.sqlscriptformater.SqlScriptFormater.java
private boolean writeListToFile(File newFile, List<String> lines) { boolean bOk = true; if (newFile != null) { try {/*w w w .ja v a2 s. c o m*/ FileUtils.writeLines(newFile, lines); } catch (IOException ex) { _errors.add("Failed to write to File: " + ex.getMessage()); return false; } } else { bOk = false; } return bOk; }
From source file:edu.cmu.cs.lti.discoursedb.annotation.brat.io.BratService.java
/** * Imports a thread in Brat stand-off format into discoursedb. * /*from w w w .ja v a 2 s . com*/ * @param inputFolder folder with the brat annotation and meta data * @param baseFileName the base filename for the current thread to be imported * @return an info object containing lists of ids of annotations and featured to be deleted after the import * @throws IOException if any exception occurs while reading the brat annotations or meta data */ @Transactional(value = "coreTransactionManager", propagation = Propagation.REQUIRED, readOnly = false) private CleanupInfo importThreadFromBrat(String inputFolder, String baseFileName) throws IOException { Assert.hasText(inputFolder, "inputFolder parameter cannot be empty [importThread(" + inputFolder + ", " + baseFileName + ")]"); Assert.hasText(baseFileName, "baseFileName parameter cannot be empty [importThread(" + inputFolder + ", " + baseFileName + ")]"); File annFile = new File(inputFolder, baseFileName + ".ann"); File offsetFile = new File(inputFolder, baseFileName + ".offsets"); File versionsFile = new File(inputFolder, baseFileName + ".versions"); // get mapping from entity to offset TreeMap<Integer, OffsetInfo> offsetToOffsetInfo = getOffsetToOffsetInfoMap(offsetFile); // keep track of versions of orginally exported annotations and features Map<String, VersionInfo> annotationBratIdToVersionInfo = getBratIdToDdbIdMap(versionsFile, AnnotationSourceType.DDB_ANNOTATION); Map<String, VersionInfo> featureBratIdToVersionInfo = getBratIdToDdbIdMap(versionsFile, AnnotationSourceType.DDB_FEATURE); DiscoursePart dp = dpService .findOne(Long.parseLong(baseFileName.substring(baseFileName.lastIndexOf("_") + 1))).get(); SystemUser sysUser = sysUserService.getSystemUser().get(); //Init ddb annotation stats for deletion handling Set<Long> ddbAnnotationIds = new HashSet<>(); Set<Long> ddbFeatureIds = new HashSet<>(); //extract annotations on Contributions for (AnnotationInstance anno : annoService.findContributionAnnotationsByDiscoursePart(dp)) { ddbAnnotationIds.add(anno.getId()); anno.setAnnotator(sysUser); ; if (anno.getFeatures() != null) { ddbFeatureIds.addAll(anno.getFeatures().stream().map(f -> f.getId()).collect(Collectors.toList())); } } //extract annotations on Content entities for (AnnotationInstance anno : annoService.findCurrentRevisionAnnotationsByDiscoursePart(dp)) { ddbAnnotationIds.add(anno.getId()); anno.setAnnotator(sysUser); if (anno.getFeatures() != null) { ddbFeatureIds.addAll(anno.getFeatures().stream().map(f -> f.getId()).collect(Collectors.toList())); } } log.info(ddbAnnotationIds.size() + " annotations within current thread available in DiscoursDB."); log.info(ddbFeatureIds.size() + " features within current thread available in DiscoursDB."); List<String> bratStandoffEncodedStrings = FileUtils.readLines(annFile); //sorting in reverse order assures that Attribute annotations (A) are imported after text-bound annotations (T) Collections.sort(bratStandoffEncodedStrings, Collections.reverseOrder()); for (String bratStandoffEncodedString : bratStandoffEncodedStrings) { // create BratAnnotation object from Brat-Stand-off-Encoded String // offset correction will be done later BratAnnotation bratAnno = new BratAnnotation(bratStandoffEncodedString); if (bratAnno.getType() == BratAnnotationType.BRAT_TEXT) { Entry<Integer, OffsetInfo> offset = offsetToOffsetInfo.floorEntry(bratAnno.getBeginIndex()); Contribution contrib = contribService.findOne(offset.getValue().getDiscourseDbContributionId()) .get(); Content content = contentService.findOne(offset.getValue().getDiscourseDbContentId()).get(); long separatorStartIndex = offset.getKey(); long separatorEndIndex = separatorStartIndex + BratSeparator.length; long textEndIndex = separatorEndIndex + content.getText().length(); // CONTRIBUTION LABEL: Annotation is completely within a separator if (bratAnno.getBeginIndex() >= separatorStartIndex && bratAnno.getBeginIndex() <= separatorEndIndex && bratAnno.getEndIndex() >= separatorStartIndex && bratAnno.getEndIndex() <= separatorEndIndex) { // check if annotation already existed before if (annotationBratIdToVersionInfo.keySet().contains(bratAnno.getId())) { VersionInfo entityInfo = annotationBratIdToVersionInfo.get(bratAnno.getId()); ddbAnnotationIds.remove(entityInfo.getDiscourseDBEntityId()); //update deletion stats AnnotationInstance existingAnno = annoService .findOneAnnotationInstance(entityInfo.getDiscourseDBEntityId()).get(); //check if the anno version in the database still matches the anno version we initially exported if (existingAnno.getEntityVersion() == entityInfo.getDiscourseDBEntityVersion()) { existingAnno.setBeginOffset(0); existingAnno.setEndOffset(0); existingAnno.setType(bratAnno.getAnnotationLabel()); } else { log.error( "Entity changed in DiscourseDB since the data was last import but also changed in the exported file. Cannot import annotation."); } } else { // anno is new and didn't exist in ddb before AnnotationInstance newAnno = annoService .createTypedAnnotation(bratAnno.getAnnotationLabel()); annoService.addAnnotation(contrib, newAnno); contribService.save(contrib); //this should happen in addAnnotation. Filed Issue #15 //update version file annotationBratIdToVersionInfo.put(bratAnno.getId(), new VersionInfo(AnnotationSourceType.DDB_ANNOTATION, bratAnno.getId(), newAnno.getId(), newAnno.getEntityVersion())); } } // SPAN ANNOTATION WITHIN CONTRIBUTION TEXT (does neither span over separator nor over multiple contributions) else if (bratAnno.getBeginIndex() > separatorEndIndex && bratAnno.getBeginIndex() <= textEndIndex && bratAnno.getEndIndex() > separatorEndIndex && bratAnno.getEndIndex() <= textEndIndex) { // calculate offset corrected index values for span annotation int offsetCorrectedBeginIdx = bratAnno.getBeginIndex() - offset.getKey() - BratSeparator.length - 1; int offsetCorrectedEndIdx = bratAnno.getEndIndex() - offset.getKey() - BratSeparator.length - 1; // check if annotation already existed before if (annotationBratIdToVersionInfo.keySet().contains(bratAnno.getId())) { VersionInfo entityInfo = annotationBratIdToVersionInfo.get(bratAnno.getId()); ddbAnnotationIds.remove(entityInfo.getDiscourseDBEntityId()); //update deletion stats // Anno already existed. Check for changes. AnnotationInstance existingAnno = annoService .findOneAnnotationInstance(entityInfo.getDiscourseDBEntityId()).get(); //check if the anno version in the database still matches the anno version we initially exported //if so, we can update if (existingAnno.getEntityVersion() == entityInfo.getDiscourseDBEntityVersion()) { existingAnno.setBeginOffset(offsetCorrectedBeginIdx); existingAnno.setEndOffset(offsetCorrectedEndIdx); existingAnno.setType(bratAnno.getAnnotationLabel()); } else { log.error( "Entity changed in DiscourseDB since the data was last import but also changed in the exported file. Cannot import annotation."); } } else { // Anno is new and didn't exist in ddb before. Create it. AnnotationInstance newAnno = annoService .createTypedAnnotation(bratAnno.getAnnotationLabel()); newAnno.setBeginOffset(offsetCorrectedBeginIdx); newAnno.setEndOffset(offsetCorrectedEndIdx); annoService.addAnnotation(content, newAnno); contentService.save(content); //this should happen in addAnnotation. Filed Issue #15 //update version file annotationBratIdToVersionInfo.put(bratAnno.getId(), new VersionInfo(AnnotationSourceType.DDB_ANNOTATION, bratAnno.getId(), newAnno.getId(), newAnno.getEntityVersion())); } } else { log.error( "Annotation extends over contribution separator(s) AND text. You can only annotate within a separator or within a contribution. Skipping this annotation..."); } } else if (bratAnno.getType() == BratAnnotationType.BRAT_NOTE) { VersionInfo entityInfo = featureBratIdToVersionInfo.get(bratAnno.getId()); // check if feature already existed before if (featureBratIdToVersionInfo.keySet().contains(bratAnno.getId())) { ddbFeatureIds.remove(entityInfo.getDiscourseDBEntityId()); //update deletion stats // feature already existed Feature existingFeature = annoService.findOneFeature(entityInfo.getDiscourseDBEntityId()).get(); //check if the feature version in the database still matches the feature version we initially exported if (existingFeature.getEntityVersion() == entityInfo.getDiscourseDBEntityVersion()) { //check for and apply changes if (existingFeature.getValue().equalsIgnoreCase(bratAnno.getAnnotationLabel())) { existingFeature.setValue(bratAnno.getAnnotationLabel()); } } else { log.error( "Entity changed in DiscourseDB since the data was last import but also changed in the exported file. Cannot import feature."); } } else { // feature didn't exist in database yet. Create it. VersionInfo referenceAnnotationInfo = annotationBratIdToVersionInfo .get(bratAnno.getSourceAnnotationId()); if (referenceAnnotationInfo != null) { AnnotationInstance referenceAnno = annoService .findOneAnnotationInstance(referenceAnnotationInfo.getDiscourseDBEntityId()).get(); Feature newFeature = annoService.createTypedFeature(bratAnno.getNoteText(), bratAnno.getType().name()); //update version file featureBratIdToVersionInfo.put(bratAnno.getId(), new VersionInfo(AnnotationSourceType.DDB_FEATURE, bratAnno.getId(), newFeature.getId(), newFeature.getEntityVersion())); annoService.addFeature(referenceAnno, newFeature); annoService.saveFeature(newFeature); //this should happen in addFeature. Filed Issue #15 } else { log.error("Cannot find the annotation this feature applies to."); } } } else { //Implement import capabilities for other Brat Annotation types here log.error("Unsupported Annotation type " + bratAnno.getType() + " Skipping."); } } //Regenerate the version infos updated data from the newly created annotations List<VersionInfo> updatedVersionInfo = new ArrayList<>(); updatedVersionInfo.addAll(annotationBratIdToVersionInfo.values()); updatedVersionInfo.addAll(featureBratIdToVersionInfo.values()); FileUtils.writeLines(versionsFile, updatedVersionInfo); //return info about entities to be deleted return new CleanupInfo(versionsFile, ddbFeatureIds, ddbAnnotationIds); }
From source file:com.taobao.android.builder.tools.multidex.FastMultiDexer.java
public List<String> getMainDexList(Collection<File> files) { GradleVariantConfiguration config = appVariantContext.getVariantConfiguration(); Set<String> mainDexList = new HashSet<String>(); //map/*from w w w . ja v a2 s.com*/ //Map<String, String> classMap = getClassObfMap(config); File manifest = appVariantContext.getVariantData().getOutputs().get(0).manifestProcessorTask .getManifestOutputFile(); String applicationName = ManifestFileUtils.getApplicationName(manifest); ClassPool classPool = new ClassPool(); try { for (File file : files) { if (file.isFile()) { classPool.insertClassPath(file.getAbsolutePath()); } else { classPool.appendClassPath(file.getAbsolutePath()); } } } catch (NotFoundException e) { throw new GradleException(e.getMessage(), e); } TBuildConfig tBuildConfig = appVariantContext.getAtlasExtension().getTBuildConfig(); HashSet handleList = new HashSet<String>(); Set<String> headClasses = new HashSet<>(); headClasses.add(applicationName); headClasses.add("android.taobao.atlas.bridge.BridgeApplicationDelegate"); headClasses.addAll(multiDexConfig.getFirstDexClasses()); String preLaunchStr = tBuildConfig.getPreLaunch(); if (!org.apache.commons.lang3.StringUtils.isEmpty(preLaunchStr)) { String[] launchArray = preLaunchStr.split("\\|"); if (launchArray.length > 0) { for (String launchItem : launchArray) { String[] launchInfo = launchItem.split(":"); String clazzName = launchInfo[0]; headClasses.add(clazzName); } } } for (String headClass : headClasses) { addRefClazz(classPool, headClass, mainDexList, handleList); } //get manifest List<String> maindexListClazz = new ArrayList<String>(); for (String newLine : mainDexList) { newLine = newLine.replaceAll("\\.", "/") + ".class"; maindexListClazz.add(newLine); } try { FileUtils.writeLines(new File(appVariantContext.getProject().getBuildDir(), "outputs/maindexlist.txt"), mainDexList); } catch (IOException e) { e.printStackTrace(); } return maindexListClazz; }
From source file:edu.cmu.cs.lti.discoursedb.annotation.brat.io.BratService.java
/** * Deletes annotations and features identified by a list of ids. * Also updates the versions file./*from ww w .j av a 2 s .co m*/ * * @param featureIds a list of discourse db feature ids * @param annotationIds a list of discoursedb annotation ids */ @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) private void cleanupAfterImport(CleanupInfo cleanupInfo) throws IOException { Assert.notNull(cleanupInfo, "cleanup info cannot be null"); //delete features from DiscourseDB that have been deleted in brat for (Long id : cleanupInfo.getFeaturesToDelete()) { log.info("Delete feature " + id); annoService.deleteFeature(id); } //delete annotations from DiscourseDB that have been deleted in brat for (Long id : cleanupInfo.getAnnotationsToDelete()) { log.info("Delete annotation " + id); annoService.deleteAnnotation(id); } //cleanup versions file - remove deleted entities List<VersionInfo> filteredVersionFile = new ArrayList<>(); for (String line : FileUtils.readLines(cleanupInfo.getVersionsFile())) { VersionInfo info = new VersionInfo(line); if (info.getType() == AnnotationSourceType.DDB_ANNOTATION) { if (!cleanupInfo.getAnnotationsToDelete().contains(info.getDiscourseDBEntityId())) { filteredVersionFile.add(info); } } else if (info.getType() == AnnotationSourceType.DDB_FEATURE) { if (!cleanupInfo.getFeaturesToDelete().contains(info.getDiscourseDBEntityId())) { filteredVersionFile.add(info); } } } FileUtils.writeLines(cleanupInfo.getVersionsFile(), filteredVersionFile); }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
@Test public void testLegacyPasswordBase64IsplaintextFalse() throws Exception { final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_base64_set.properties"); final File configFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test4"); filesToDelete.add(configFile);/*from ww w . ja v a 2 s. c o m*/ configFile.deleteOnExit(); FileUtils.copyFile(sourceConfigFile, configFile); final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath()); List<String> updatedLines = null; if (cf.isInNeedOfUpdate()) { updatedLines = cf.saveWithEncryptedPasswords(); } assertTrue(updatedLines.size() > 0); final Iterator<String> updatedLinesIter = updatedLines.iterator(); while (updatedLinesIter.hasNext()) { 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 (updatedLine.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 (updatedLine.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 (updatedLine.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); } } final File testGeneratedUpdatedFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test4_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.tools.proguard.AtlasProguardHelper.java
@NotNull private static File generateKeepFile(List<AwbBundle> awbBundles, File dir) throws IOException { KeepConverter refClazzContainer = new KeepConverter(); for (AwbBundle awbBundle : awbBundles) { if (null != awbBundle.getKeepProguardFile() && awbBundle.getKeepProguardFile().exists()) { String json = FileUtils.readFileToString(awbBundle.getKeepProguardFile()); Map<String, ClazzRefInfo> refClazzMap = JSON.parseObject(json, new TypeReference<Map<String, ClazzRefInfo>>() { });//from w w w. ja v a2 s. c o m refClazzContainer.addRefClazz(refClazzMap); } else { sLogger.error("missing " + awbBundle.getKeepProguardFile().getAbsolutePath()); } } File maindexkeep = new File(dir, "maindexkeep.cfg"); FileUtils.writeLines(maindexkeep, refClazzContainer.convertToKeeplines()); return maindexkeep; }
From source file:it.drwolf.ridire.index.cwb.scripts.VRTFilesBuilder.java
public void reverseFile(File destDir, File f) throws IOException { List<String> lines = FileUtils.readLines(f); List<String> newLines = new ArrayList<String>(); newLines.add(lines.remove(0));/*from w w w .j ava 2 s.c om*/ newLines.add(lines.remove(0)); String tail = lines.remove(lines.size() - 1); Collections.reverse(lines); for (String l : lines) { newLines.add(l); } newLines.add(tail); File vrtFile = new File(destDir, FilenameUtils.getBaseName(f.getName()) + ".vrt"); FileUtils.writeLines(vrtFile, newLines); }
From source file:edu.isi.pfindr.learn.util.PairsFileIO.java
public void filterPairsThatExist(String inputFilePath1, String inputFilePath2) { //eg. testdata(the data to check), traindata(original data) //Read the files List<String> phenotypeList1 = new ArrayList<String>(); List<String> phenotypeList2 = new ArrayList<String>(); //sure pairs LinkedMap surePairsAdjacencyMap = new LinkedMap(); try {// ww w . j av a2s .c om phenotypeList1 = FileUtils.readLines(new File(inputFilePath1)); phenotypeList2 = FileUtils.readLines(new File(inputFilePath2)); String[] lineArray; List<String> resultList = new ArrayList<String>(); List<String> surePairsMapValue = null; System.out.println(phenotypeList2.size()); //construct a map of phenotype and its neighbors for sure-pairs for (int i = 0; i < phenotypeList2.size(); i++) { lineArray = phenotypeList2.get(i).split("\t"); surePairsMapValue = new ArrayList<String>(); //if the first value is existing in the map, get the second value if (surePairsAdjacencyMap.containsKey(lineArray[0])) { surePairsMapValue = (List<String>) surePairsAdjacencyMap.get(lineArray[0]); } //System.out.println("SurePairsMapValueSize " + surePairsMapValue.size()); //if the value does not already contain the second, add the string and add it back to the map if (!surePairsMapValue.contains(lineArray[1])) surePairsMapValue.add(lineArray[1]); surePairsAdjacencyMap.put(lineArray[0], surePairsMapValue); //In the same manner, update the adjacency of the second string surePairsMapValue = new ArrayList<String>(); if (surePairsAdjacencyMap.containsKey(lineArray[1])) { surePairsMapValue = (List<String>) surePairsAdjacencyMap.get(lineArray[1]); } if (!surePairsMapValue.contains(lineArray[0])) surePairsMapValue.add(lineArray[0]); surePairsAdjacencyMap.put(lineArray[1], surePairsMapValue); } List valueList = null; for (int i = 0; i < surePairsAdjacencyMap.size(); i++) { System.out.println("Key : " + surePairsAdjacencyMap.get(i) + " Value : " + ((List) surePairsAdjacencyMap.get(surePairsAdjacencyMap.get(i))).size()); /*valueList = (List)surePairsAdjacencyMap.get(surePairsAdjacencyMap.get(i)); for(int j =0; j<valueList.size(); j++) System.out.println("Value :" + valueList.get(j) ); //break;*/ } //Now parse the new pairs file, and check if the pairs already exists in the sure pairs map boolean existsSurePairs = false; System.out.println(phenotypeList1.size()); surePairsMapValue = new ArrayList<String>(); for (int j = 0; j < phenotypeList1.size(); j++) { lineArray = phenotypeList1.get(j).split("\t"); if (surePairsAdjacencyMap.containsKey(lineArray[0])) { surePairsMapValue = (List) surePairsAdjacencyMap.get(lineArray[0]); if (surePairsMapValue.contains(lineArray[1])) { existsSurePairs = true; } } else if (surePairsAdjacencyMap.containsKey(lineArray[1])) { surePairsMapValue = (List) surePairsAdjacencyMap.get(lineArray[1]); if (surePairsMapValue.contains(lineArray[0])) { existsSurePairs = true; } } if (!existsSurePairs) //if it does not exist in surepairs, then write to output file resultList.add(String.format("%s\t%s\t%s", lineArray[0], lineArray[1], lineArray[2])); existsSurePairs = false; } String resultFilePath = inputFilePath1.split("\\.")[0] + "_filtered.txt"; FileUtils.writeLines(new File(resultFilePath), resultList); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java
@Test public void testModernPasswordPlainTextIsEncryptedNotSet() throws Exception { final File sourceConfigFile = new File("src/test/resources/psw_encryption/modern_plain_notset.properties"); final File configFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test5"); filesToDelete.add(configFile);// ww w . ja v a2s. co m configFile.deleteOnExit(); FileUtils.copyFile(sourceConfigFile, configFile); final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath()); List<String> updatedLines = null; if (cf.isInNeedOfUpdate()) { updatedLines = cf.saveWithEncryptedPasswords(); } assertTrue(updatedLines.size() > 0); final Iterator<String> updatedLinesIter = updatedLines.iterator(); while (updatedLinesIter.hasNext()) { 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 (updatedLine.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 (updatedLine.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 (updatedLine.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); } } final File testGeneratedUpdatedFile = File.createTempFile( "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test5_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); }