List of usage examples for java.lang System lineSeparator
String lineSeparator
To view the source code for java.lang System lineSeparator.
Click Source Link
From source file:org.apache.sling.scripting.sightly.compiler.SightlyCompiler.java
private ScriptError getScriptError(String documentFragment, String offendingInput, int lineOffset, int column, String message) {/* ww w. ja va2 s . c o m*/ if (StringUtils.isNotEmpty(offendingInput)) { int offendingInputIndex = documentFragment.indexOf(offendingInput); if (offendingInputIndex > -1) { String textBeforeError = documentFragment.substring(0, offendingInputIndex); int line = 1; int newLine = 0; while (textBeforeError.length() > 0 && newLine != -1) { newLine = textBeforeError.indexOf(System.lineSeparator()); if (newLine != -1) { line++; textBeforeError = textBeforeError.substring(newLine + 1, textBeforeError.length()); } } line = line + lineOffset; column = textBeforeError.length() + column + 1; return new ScriptError(line, column, offendingInput + ": " + message); } } return new ScriptError(lineOffset, column, message); }
From source file:de.fosd.jdime.stats.ASTStats.java
@Override public String toString() { DecimalFormat df = new DecimalFormat("#.0"); StringBuilder sb = new StringBuilder(); if (LOG.isDebugEnabled()) { sb.append("Total nodes: " + nodes + System.lineSeparator()); sb.append("Treedepth: " + treedepth + System.lineSeparator()); sb.append("Maximum children: " + maxchildren + System.lineSeparator()); sb.append("Fragments: " + fragments + System.lineSeparator()); sb.append("Avg. Fragment size: " + df.format(getAvgFragmentSize()) + System.lineSeparator()); }//from w w w. j a v a 2s . co m String[][] absolute = new String[6][7]; String[][] relative = new String[6][7]; String[] csvHead = new String[36]; String[] csv = new String[36]; ; int[] sum = new int[5]; int i = 0; int j = 0; for (String key : new TreeSet<>((diffstats.keySet()))) { StatsElement s = diffstats.get(key); int nodes = s.getElements(); int matched = s.getMatches(); int changed = s.getChanges(); int added = s.getAdded(); int removed = s.getDeleted(); int conflicts = s.getConflicting(); if (i > 0) { sum[0] += nodes; sum[1] += matched; sum[2] += changed; sum[3] += added; sum[4] += removed; } String name = key.toLowerCase(); if (name.endsWith("ss")) { name = name + "es"; } else { name = name + "s"; } absolute[i][0] = name; absolute[i][1] = String.valueOf(nodes); absolute[i][2] = String.valueOf(matched); absolute[i][3] = String.valueOf(changed); absolute[i][4] = String.valueOf(added); absolute[i][5] = String.valueOf(removed); absolute[i][6] = String.valueOf(conflicts); csvHead[j] = name; csv[j++] = String.valueOf(nodes); csvHead[j] = "matched " + name; csv[j++] = String.valueOf(matched); csvHead[j] = "changed " + name; csv[j++] = String.valueOf(changed); csvHead[j] = "added " + name; csv[j++] = String.valueOf(added); csvHead[j] = "removed " + name; csv[j++] = String.valueOf(removed); csvHead[j] = "conflicting " + name; csv[j++] = String.valueOf(conflicts); if (nodes > 0) { relative[i][0] = key.toLowerCase(); relative[i][1] = df.format(100.0); relative[i][2] = df.format(100.0 * matched / nodes); relative[i][3] = df.format(100.0 * changed / nodes); relative[i][4] = df.format(100.0 * added / nodes); relative[i][5] = df.format(100.0 * removed / nodes); relative[i][6] = df.format(100.0 * conflicts / nodes); } else { relative[i][0] = key.toLowerCase(); relative[i][1] = "null"; relative[i][2] = "null"; relative[i][3] = "null"; relative[i][4] = "null"; relative[i][5] = "null"; relative[i][6] = "null"; } i++; } // CSV sb.append(StringUtils.join(csvHead, ';')); sb.append(System.lineSeparator()); sb.append(StringUtils.join(csv, ';')); return sb.toString(); }
From source file:com.netflix.genie.core.jobs.workflow.impl.InitialSetupTask.java
@VisibleForTesting void createCommandEnvironmentVariables(final Writer writer, final Command command) throws GenieException, IOException { final String commandId = command.getId().orElseThrow(() -> new GenieServerException("No command id")); writer.write(JobConstants.EXPORT + JobConstants.GENIE_COMMAND_DIR_ENV_VAR + JobConstants.EQUALS_SYMBOL + JobConstants.DOUBLE_QUOTE_SYMBOL + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}" + JobConstants.FILE_PATH_DELIMITER + JobConstants.GENIE_PATH_VAR + JobConstants.FILE_PATH_DELIMITER + JobConstants.COMMAND_PATH_VAR + JobConstants.FILE_PATH_DELIMITER + commandId + JobConstants.DOUBLE_QUOTE_SYMBOL + LINE_SEPARATOR); // Append new line writer.write(LINE_SEPARATOR);//ww w . j a v a 2 s . co m writer.write(JobConstants.EXPORT + JobConstants.GENIE_COMMAND_ID_ENV_VAR + JobConstants.EQUALS_SYMBOL + JobConstants.DOUBLE_QUOTE_SYMBOL + commandId + JobConstants.DOUBLE_QUOTE_SYMBOL + LINE_SEPARATOR); // Append new line writer.write(System.lineSeparator()); writer.write(JobConstants.EXPORT + JobConstants.GENIE_COMMAND_NAME_ENV_VAR + JobConstants.EQUALS_SYMBOL + JobConstants.DOUBLE_QUOTE_SYMBOL + command.getName() + JobConstants.DOUBLE_QUOTE_SYMBOL + LINE_SEPARATOR); // Append new line writer.write(System.lineSeparator()); writer.write(JobConstants.EXPORT + JobConstants.GENIE_COMMAND_TAGS_ENV_VAR + JobConstants.EQUALS_SYMBOL + JobConstants.DOUBLE_QUOTE_SYMBOL + tagsToString(command.getTags()) + JobConstants.DOUBLE_QUOTE_SYMBOL + LINE_SEPARATOR); // Append new line writer.write(System.lineSeparator()); }
From source file:com.pearson.eidetic.driver.threads.RefreshAwsAccountVolumes.java
private JSONObject getCreateSnapshot(Volume volume, JSONObject eideticParameters) { JSONObject createSnapshot = null;/*from w ww .jav a 2 s . c om*/ try { createSnapshot = (JSONObject) eideticParameters.get("CreateSnapshot"); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + volume.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } return createSnapshot; }
From source file:com.athena.peacock.agent.sample.CommandExecutorSample.java
public static List<Product> parse(String output) { String[] lines = output.split(System.lineSeparator()); List<Product> productList = new ArrayList<Product>(); Product product = null;//from ww w . j a v a 2s. c o m String line = null; int nameIdx = 0, vendorIdx = 0, versionIdx = 0; for (int i = 0; i < lines.length; i++) { line = lines[i]; if (i == 0) { nameIdx = line.indexOf("Name"); vendorIdx = line.indexOf("Vendor"); versionIdx = line.indexOf("Version"); continue; } if (StringUtils.isEmpty(line)) { continue; } product = new Product(); product.setName(line.substring(nameIdx, vendorIdx).trim()); if (!line.substring(vendorIdx, versionIdx).startsWith(" ")) { product.setVendor(line.substring(vendorIdx, versionIdx).trim()); product.setVersion(line.substring(versionIdx).trim()); } else { // in case of vendor info does not exist. product.setVendor(""); product.setVersion(line.substring(vendorIdx).trim()); } productList.add(product); } return productList; }
From source file:io.cloudslang.lang.cli.SlangCli.java
private String printAllCompileErrors(List<CompilationModellingResult> results) { if (results.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (CompilationModellingResult result : results) { printCompileErrors(result.getErrors(), result.getFile(), stringBuilder); stringBuilder.append(System.lineSeparator()); }//from w w w .jav a 2 s. c o m return stringBuilder.toString(); } else { return "No files were found to compile."; } }
From source file:com.glluch.ecf2xmlmaven.Competence.java
public void toXmlSolr(String path) throws IOException { String xml = "<add><doc>" + System.lineSeparator(); xml += "<field name=\"id\""; xml += ">"; xml += this.code; xml += "</field>" + System.lineSeparator(); xml += "<field name=\"type\">competence</field>" + System.lineSeparator(); xml += this.terms2xml("term") + System.lineSeparator(); xml += this.rterms2xml("term") + System.lineSeparator(); xml += "</doc></add>"; //competencesXMLsolr String fileTitle = this.code + "xml"; FileUtils.writeStringToFile(new File(path + fileTitle), xml, "utf8"); }
From source file:edu.odu.cs.cs350.yellow1.ui.cli.Main.java
/** * Main program function. Creates and runs mutants as well as logging and output files * /* w w w.ja va 2 s . c o m*/ * @param srcFolder Source folder for project to be mutated * @param fileToBeMutated Source file for project to be mutated * @param testSuitePath Path for test suite * @param goldOutput Original version output file * @throws BuildFileNotFoundException * @throws IOException */ @SuppressWarnings("static-access") public static void mutate(String srcFolder, String fileToBeMutated, String testSuitePath, String goldOutput) throws BuildFileNotFoundException, IOException { //Step 1: Set up file directory paths for antRunner, jarExecutor, and fileMover logger = LogManager.getLogger(Main.class); mutLog = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs" + File.separator + "mutationsApplied.txt"); aliveLog = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs" + File.separator + "mutationsAlive.txt"); logFolder = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs"); // ok because of the output on jenkins sanitize the logs directory if (logFolder.exists()) if (logFolder.isDirectory()) for (File f : logFolder.listFiles()) f.delete(); //give ant runer the project location ant = new AntRunner(srcFolder); ant.requiresInit(true); //call setup ant.setUp(); a = new JavaFile(); //give the jarUtil the directory where to expect the jar the directory where to put the jar jar = new JarUtil((srcFolder + File.separator + "bin"), (srcFolder + File.separator + "mutantDir")); //get a file object to the original file File goldFile = new File(fileToBeMutated); goldPath = goldFile.toPath(); //get the bytes from it for checking if applying mutation and restore works goldOrgContent = Files.readAllBytes(goldPath); File script = new File(srcFolder + File.separator + "compare.sh"); //build the JarExecutor using the JarExecutor jarExecutor = JarExecutorBuilder.pathToJarDirectory(srcFolder + File.separator + "mutantDir") .pathToCompareScript(script.getAbsolutePath()) .pathToLogDir(srcFolder + File.separator + "mutantDir" + File.separator + "logs") .pathToGold(goldOutput.toString()).withExecutionState(ExecutionState.multiFile) .withTestSuitePath(testSuitePath).create(); File tDir = new File(srcFolder + File.separator + "mutantDir"); if (!tDir.exists()) tDir.mkdir(); //Create a fileMover object give it the directory where mutations will be placed the directory of the original file location fMover = new FileMover(srcFolder + File.separator + "mutantDir", fileToBeMutated); fMover.setNoDelete(true); try { fMover.setUp(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } //Step2: Create and run mutants try { a.readFile(fileToBeMutated); } catch (IOException e) { e.printStackTrace(); } a.executeAll(); int mutantsCreated = a.getMutantCaseVector().getSize(); logger.info("Created " + mutantsCreated + " Mutants"); for (int i = 0; i < a.getMutantCaseVector().getSize(); i++) { a.getMutantCaseOperations(i).writeMutation(srcFolder + File.separator + "mutantDir" + File.separator + "Mutation" + Integer.toString(i + 1) + ".java"); } //get the files into the file mover object fMover.pullFiles(); //check to see if the filemover got all the files //assertEquals(fMover.getFileToBeMovedCount(),mutantsCreated); int moved = 0; int failed = 0; //move through each file moving them one by one while (fMover.hasMoreFiles()) { try { //move next file fMover.moveNextFile(); //build the new executable ant.build(); //move the created jar with correct number corresponding to the mutation created jar.moveJarToDestNumbered(); //clean the project ant.clean(); //check to see if the mutation was applied //assertThat(additionOrgContent, IsNot.not(IsEqual.equalTo(Files.readAllBytes(additionPath)))); } catch (FileMovingException | BuildException | TargetNotFoundException | IOException e) { //build failed if (e instanceof BuildException) { logger.error("Build exception " + e.getMessage()); //restore the file back since compilation was not successful fMover.restorTarget(); //try { // //check to see if the file was restored // assertArrayEquals(goldOrgContent, Files.readAllBytes(goldPath)); //} catch (IOException e1) { // //} //clean the project try { ant.clean(); } catch (BuildException e1) { } catch (TargetNotFoundException e1) { } //indicate compile failure ++failed; } //fail(); } //restore the file back to its original state fMover.restorTarget(); //check to see if the file was restored //try { // assertArrayEquals(goldOrgContent, Files.readAllBytes(goldPath)); //} catch (IOException e) { // //} //increment move count ++moved; //see if the file mover has the correct amount of mutatants still to be moved //assertEquals(fMover.getFileToBeMovedCount(), mutantsCreated - moved); } //set up for execution jarExecutor.setUp(); //start execution of jars jarExecutor.start(); //get the number of successful and failed runs int succesful = jarExecutor.getNumberOfMutantsKilled(); int failurs = jarExecutor.getNumberOfMutantsNotKilled(); int numTests = jarExecutor.getNumberOfTests(); int total = succesful + failurs; String aliveFile = null; String newLine = System.lineSeparator(); //Find any test jars that remain alive and write them to the log file List<ExecutionResults> testResults = jarExecutor.getMutationTestingResults(); for (ExecutionResults result : testResults) { if (!result.isKilled()) { aliveFile = result.getJarName(); FileUtils.writeStringToFile(aliveLog, aliveFile + newLine, true); } } //moved - failed = number of jars actually created moved = moved - failed; //see if the total number of executions equals the total amount of jars created //assertEquals(succesful+failurs,moved); logger.debug("Compilation failurs= " + failed + " total files moved= " + moved); logger.debug("Execution succesful=" + succesful + " Execution failurs= " + failurs); EOL eol = System.getProperty("os.name").toLowerCase().contains("windows") ? EOL.DOS : EOL.NIX; try { a.writeMutationsLog(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs" + File.separator + "mutationsApplied.txt", eol); } catch (Exception e) { logger.error(e.getMessage()); } String finalOutput = "Number of tests: " + numTests + " " + "Number of mutants: " + total + " " + "Mutants killed: " + succesful; FileUtils.writeStringToFile(mutLog, newLine + finalOutput, true); System.out.println(finalOutput + "\n"); }
From source file:org.apache.zeppelin.python.IPythonInterpreter.java
private void setupJVMGateway(int jvmGatewayPort) throws IOException { String serverAddress = PythonUtils.getLocalIP(properties); this.gatewayServer = PythonUtils.createGatewayServer(this, serverAddress, jvmGatewayPort, secret, usePy4JAuth);/*from ww w. j a v a 2 s .c o m*/ gatewayServer.start(); InputStream input = getClass().getClassLoader().getResourceAsStream("grpc/python/zeppelin_python.py"); List<String> lines = IOUtils.readLines(input); ExecuteResponse response = ipythonClient.block_execute(ExecuteRequest.newBuilder() .setCode(StringUtils.join(lines, System.lineSeparator()) .replace("${JVM_GATEWAY_PORT}", jvmGatewayPort + "") .replace("${JVM_GATEWAY_ADDRESS}", serverAddress)) .build()); if (response.getStatus() == ExecuteStatus.ERROR) { throw new IOException("Fail to setup JVMGateway\n" + response.getOutput()); } input = getClass().getClassLoader().getResourceAsStream("python/zeppelin_context.py"); lines = IOUtils.readLines(input); response = ipythonClient.block_execute( ExecuteRequest.newBuilder().setCode(StringUtils.join(lines, System.lineSeparator())).build()); if (response.getStatus() == ExecuteStatus.ERROR) { throw new IOException("Fail to import ZeppelinContext\n" + response.getOutput()); } response = ipythonClient.block_execute(ExecuteRequest.newBuilder() .setCode("z = __zeppelin__ = PyZeppelinContext(intp.getZeppelinContext(), gateway)").build()); if (response.getStatus() == ExecuteStatus.ERROR) { throw new IOException("Fail to setup ZeppelinContext\n" + response.getOutput()); } if (additionalPythonInitFile != null) { input = getClass().getClassLoader().getResourceAsStream(additionalPythonInitFile); lines = IOUtils.readLines(input); response = ipythonClient.block_execute(ExecuteRequest.newBuilder() .setCode(StringUtils.join(lines, System.lineSeparator()) .replace("${JVM_GATEWAY_PORT}", jvmGatewayPort + "") .replace("${JVM_GATEWAY_ADDRESS}", serverAddress)) .build()); if (response.getStatus() == ExecuteStatus.ERROR) { throw new IOException("Fail to run additional Python init file: " + additionalPythonInitFile + "\n" + response.getOutput()); } } }
From source file:com.firewallid.networkanalysis.NetworkAnalysis.java
public void saveNAFileNodes(JavaPairRDD<String, List<Tuple2<String, Long>>> nodes, String prefixFileName) { String docDelimiter = StringEscapeUtils.unescapeJava(firewallConf.get(DOC_DELIMITER)); String naFolder = firewallConf.get(NETWORKANALYSIS_FOLDER); String nameDelimiter = firewallConf.get(NAME_DELIMITER); nodes.mapToPair(node -> new Tuple2<>(node._1(), "id" + docDelimiter + "node" + docDelimiter + "size" + System.lineSeparator() + StreamUtils.zipWithIndex(node._2().parallelStream()).parallel() .map(nodeItem -> nodeItem.getIndex() + docDelimiter + nodeItem.getValue()._1() + docDelimiter + nodeItem.getValue()._2()) .collect(Collectors.joining(System.lineSeparator())))) .foreach(node -> FIFile.writeStringToHDFSFile( FIFile.generateFullPath(naFolder, prefixFileName + nameDelimiter + node._1() + nameDelimiter + "node.csv"), node._2()));//from ww w . j a v a2s. com }