List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:org.openspaces.rest.space.ReplicationRESTController.java
private void deployReplApps(DeployRequest req) { try {//www . j a v a 2 s . c o m int gscCnt = req.maxMemorySize / req.maxVmSize; //launch deployments of repl-service app Map<CloudifyRestEndpoint, String> ids = new HashMap<CloudifyRestEndpoint, String>(); for (CloudifyRestEndpoint endpoint : req.endpoints) { final RestClient restClient = new RestClient( new URL("http://" + endpoint.address + ":" + endpoint.port), "", "", CLOUDIFY_VERSION); restClient.connect(); //upload app File packed = Packager.packApplication( createDslReader(new File(recipePath + File.separator + "repl-service" + File.separator + "cloudify" + File.separator + "repl")).readDslEntity(Application.class), new File(recipePath)); UploadResponse uploadResponse = restClient.upload(null, packed); //upload overrides String appUploadKey = uploadResponse.getUploadKey(); File props = File.createTempFile("repl", "properties"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(props))); writer.write(String.format("containerCount=%d", gscCnt)); writer.newLine(); writer.write(String.format("gscMinSize=\"-Xms%dm\"", req.maxVmSize)); writer.newLine(); writer.write(String.format("gscMaxSize=\"-Xms%dm\"", req.maxVmSize)); writer.newLine(); writer.write(String.format("gscOtherOptions=\"" + " -Dcom.gs.transport_protocol.lrmi.network-mapper=org.openspaces.repl.natmapper.ReplNatMapper" + " -Dcom.gs.transport_protocol.lrmi.network-mapping-file=/tmp/network_mapping.config\"")); writer.newLine(); writer.write(String.format("zones=\"%s-datazone\"", req.tspec.name)); writer.newLine(); writer.close(); uploadResponse = restClient.upload(null, props); props.delete(); //Install InstallApplicationRequest installreq = new InstallApplicationRequest(); installreq.setApplcationFileUploadKey(appUploadKey); installreq.setApplicationOverridesUploadKey(uploadResponse.getUploadKey()); installreq.setApplicationName(req.tspec.name); installreq.setDebugAll(false); installreq.setAuthGroups(""); // for now InstallApplicationResponse response = restClient.installApplication(req.tspec.name, installreq); ids.put(endpoint, response.getDeploymentID()); } } catch (RestClientResponseException re) { log.severe("caught exception installing apps:" + re.getReasonPhrase() + ":" + re.getMessageFormattedText()); log.severe("rolling back and failing"); rollbackApps(req); throw new RuntimeException(re); } catch (Exception e) { log.severe("caught exception installing apps:" + e.getMessage()); log.severe("rolling back and failing"); rollbackApps(req); if (e instanceof RuntimeException) throw (RuntimeException) e; throw new RuntimeException(e); } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveAsm(SpinCADPatch p, String fileName) throws IOException { // automatically overwrite existing ASM files File fileToBeSaved = new File(fileName); if (fileToBeSaved.exists()) { fileToBeSaved.delete();/*from w w w.j a v a2 s. c om*/ } BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true)); writer.write("; " + p.cb.fileName); writer.newLine(); writer.write("; " + p.cb.version); writer.newLine(); writer.write("; " + p.cb.line[0]); writer.newLine(); writer.write("; " + p.cb.line[1]); writer.newLine(); writer.write("; " + p.cb.line[2]); writer.newLine(); writer.write("; " + p.cb.line[3]); writer.newLine(); writer.write("; " + p.cb.line[4]); writer.newLine(); String codeListing = p.patchModel.getRenderBlock().getProgramListing(1); String[] words = codeListing.split("\n"); for (String word : words) { writer.write(word); writer.newLine(); } writer.close(); }
From source file:com.healthmarketscience.jackcess.ExportUtil.java
/** * Copy a table in this database into a new delimited text file. * // w w w. j a v a 2s. co m * @param cursor * Cursor to export * @param out * Writer to export to * @param header * If <code>true</code> the first line contains the column names * @param delim * The column delimiter, <code>null</code> for default (comma) * @param quote * The quote character * @param filter * valid export filter * * @see Builder */ public static void exportWriter(Cursor cursor, BufferedWriter out, boolean header, String delim, char quote, ExportFilter filter) throws IOException { String delimiter = (delim == null) ? DEFAULT_DELIMITER : delim; // create pattern which will indicate whether or not a value needs to be // quoted or not (contains delimiter, separator, or newline) Pattern needsQuotePattern = Pattern.compile("(?:" + "x" + ")|(?:" + "x" + ")|(?:[\n\r])"); //Pattern needsQuotePattern = Pattern.compile( //"(?:" + Pattern.quote(delimiter) + ")|(?:" + //Pattern.quote("" + quote) + ")|(?:[\n\r])"); List<Column> origCols = cursor.getTable().getColumns(); List<Column> columns = new ArrayList<Column>(origCols); columns = filter.filterColumns(columns); Collection<String> columnNames = null; if (!origCols.equals(columns)) { // columns have been filtered columnNames = new HashSet<String>(); for (Column c : columns) { columnNames.add(c.getName()); } } // print the header row (if desired) if (header) { for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { writeValue(out, iter.next().getName(), quote, needsQuotePattern); if (iter.hasNext()) { out.write(delimiter); } } out.newLine(); } // print the data rows Map<String, Object> row; Object[] unfilteredRowData = new Object[columns.size()]; while ((row = cursor.getNextRow(columnNames)) != null) { // fill raw row data in array for (int i = 0; i < columns.size(); i++) { unfilteredRowData[i] = columns.get(i).getRowValue(row); } // apply filter Object[] rowData = filter.filterRow(unfilteredRowData); if (rowData == null) { continue; } // print row for (int i = 0; i < columns.size(); i++) { Object obj = rowData[i]; if (obj != null) { String value = null; if (obj instanceof byte[]) { value = ByteUtil.toHexString((byte[]) obj); } else { value = String.valueOf(rowData[i]); } writeValue(out, value, quote, needsQuotePattern); } if (i < columns.size() - 1) { out.write(delimiter); } } out.newLine(); } out.flush(); }
From source file:netdecoder.NetDecoder.java
public static void saveCCSMatrix(Map<String, Map<String, Double>> ccsMatrix, String file) throws IOException { File f = new File(file); if (!f.exists()) { f.createNewFile();/*from w w w. j a v a 2 s. c o m*/ } FileWriter fw = new FileWriter(f.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); int i = 0; bw.write("gene"); for (String gene : ccsMatrix.keySet()) { Map<String, Double> ccs = ccsMatrix.get(gene); if (i == 0) { for (String matrix : ccs.keySet()) { bw.write("\t" + matrix); //bw.write(edge.getSymbol() + "\t"); } bw.newLine(); i = 1; } //bw.write(state.getSymbol() + "\t"); bw.write(gene); for (String matrix : ccs.keySet()) { bw.write("\t" + ccs.get(matrix)); } bw.newLine(); } bw.close(); }
From source file:gui.QTLResultsPanel.java
void saveTXTFile(File file) { Trait trait = currentTrait;/*from w w w .ja v a2s.c om*/ try { BufferedWriter out = new BufferedWriter(new FileWriter(file)); for (int i = 0; i < trait.getPositions().size(); i++) { out.write(trait.getPositions().get(i) + ", " + trait.getLODs().get(i)); if (trait.getLODs2() != null) { out.write(", " + trait.getLODs2().get(i)); } out.newLine(); } out.close(); } catch (Exception e) { doe.MsgBox.msg("TetraploidMap could not save the chart due to the " + "following error:\n" + e, doe.MsgBox.ERR); } }
From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.InferMLNetworkFromSequences.java
public List<Tuple<Network, Double>> inferNetwork(String[] gtTaxa, List<char[][]> sequences, Map<String, String> allele2species, RateModel gtrsm, double theta, int maxReticulations, int numSol) { if (_optimalNetworks == null) { _optimalNetworks = new Network[numSol]; _optimalScores = new double[numSol]; Arrays.fill(_optimalScores, Double.NEGATIVE_INFINITY); }// w ww. j a v a 2 s .co m List<Tuple<char[], Integer>> distinctSequences = summarizeSquences(sequences); String startingNetwork = _startNetwork.toString(); for (int i = 0; i < _numRuns; i++) { System.out.println("Run #" + i); DirectedGraphToGraphAdapter<String, PhyloEdge<String>> speciesNetwork = makeNetwork(startingNetwork); NetworkNeighbourhoodRandomWalkGenerator<DirectedGraphToGraphAdapter<String, PhyloEdge<String>>, String, PhyloEdge<String>> allNeighboursStrategy = new NetworkNeighbourhoodRandomWalkGenerator<DirectedGraphToGraphAdapter<String, PhyloEdge<String>>, String, PhyloEdge<String>>( _operationWeight, makeNode, makeEdge, _seed); AllNeighboursHillClimberFirstBetter<DirectedGraphToGraphAdapter<String, PhyloEdge<String>>, String, PhyloEdge<String>, Double> searcher = new AllNeighboursHillClimberFirstBetter<DirectedGraphToGraphAdapter<String, PhyloEdge<String>>, String, PhyloEdge<String>, Double>( allNeighboursStrategy); Func1<DirectedGraphToGraphAdapter<String, PhyloEdge<String>>, Double> scorer = getScoreFunction(gtTaxa, allele2species, distinctSequences, gtrsm, theta); Comparator<Double> comparator = getDoubleScoreComparator(); HillClimbResult<DirectedGraphToGraphAdapter<String, PhyloEdge<String>>, Double> result = searcher .search(speciesNetwork, scorer, comparator, _maxExaminations, maxReticulations, _maxFailure, _diameterLimit); // search starts here if (resultFile != null) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(resultFile, true)); bw.append("Run #" + i + "\n"); for (int j = 0; j < _optimalNetworks.length; j++) { bw.append(_optimalScores[j] + ": " + _optimalNetworks[j].toString() + "\n"); } bw.newLine(); bw.close(); } catch (Exception e) { System.err.println(e.getMessage()); e.getStackTrace(); } } } List<Tuple<Network, Double>> resultList = new ArrayList<Tuple<Network, Double>>(); for (int i = 0; i < numSol; i++) { if (_optimalNetworks[i] != null) resultList.add(new Tuple<Network, Double>(_optimalNetworks[i], _optimalScores[i])); } //System.out.println("\n #Networks " + result.ExaminationsCount); return resultList; }
From source file:json_csv.JSON2CSV.java
public void printCuisineToCSV(Recipe recipe, BufferedWriter cbw) { BufferedWriter newCBW = cbw;// w w w . j a va 2s . c om Recipe newRecipe = recipe; Cuisine newCuisine = null; StringBuffer oneLine = null; try { System.out.println(newRecipe.getExtendedIngredients().size()); for (int i = 0; i < newRecipe.getCuisine().size(); i++) { newCuisine = newRecipe.getCuisine().get(i); oneLine = new StringBuffer(); oneLine.append(newCuisine.getCuisineType()); oneLine.append(CSV_SEPARATOR); oneLine.append(newCuisine.getRecipeID()); oneLine.append(CSV_SEPARATOR); cbw.write(oneLine.toString()); cbw.newLine(); } } catch (UnsupportedEncodingException e) { } catch (FileNotFoundException e) { } catch (IOException e) { } }
From source file:edu.du.penrose.systems.fedoraApp.tests.UtilModsToFileTest.java
void writeModsToFile(String outputDirName, File inputFile, int fileCount) { BufferedReader br = null;/*from w w w.ja v a2 s .c o m*/ BufferedWriter bw = null; try { File outFile = null; FileInputStream fis = new FileInputStream(inputFile); FileOutputStream fos = null; DataInputStream in = new DataInputStream(fis); br = new BufferedReader(new InputStreamReader(in)); String doucmentType = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; String oneLine = null; while (br.ready()) { oneLine = br.readLine(); if (oneLine.contains("<mods:mods")) { outFile = new File(outputDirName + "\\mods_" + fileCount + ".xml"); fos = new FileOutputStream(outFile); bw = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); bw.write(doucmentType); bw.newLine(); while (!oneLine.contains("</mods:mods")) { // null pointer on premature end of file. bw.write(oneLine); bw.newLine(); oneLine = br.readLine(); } bw.write(oneLine); bw.newLine(); bw.close(); fileCount++; } } // while } catch (Exception e) { String errorMsg = "Exception:" + e; System.out.println(errorMsg); } finally { try { br.close(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.baomidou.mybatisplus.generator.AutoGenerator.java
/** * ?//from w w w. j a v a 2s .co m * * @param bw * @param text * @return * @throws IOException */ protected BufferedWriter buildClassComment(BufferedWriter bw, String text) throws IOException { bw.newLine(); bw.write("/**"); bw.newLine(); bw.write(" *"); bw.newLine(); bw.write(" * " + text); bw.newLine(); bw.write(" *"); bw.newLine(); bw.write(" */"); return bw; }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
private static void printJSONObject(JSONObject jsonObject, String indentation, BufferedWriter buff) { try {// w w w . ja v a2 s . c om @SuppressWarnings("unchecked") Iterator<String> keys = (Iterator<String>) jsonObject.keys(); TreeSet<String> orderedKeysSet = new TreeSet<String>(); while (keys.hasNext()) { orderedKeysSet.add(keys.next()); } Iterator<String> orderedKeys = orderedKeysSet.iterator(); while (orderedKeys.hasNext()) { String key = orderedKeys.next(); try { Object value = jsonObject.get(key); if (value instanceof JSONObject) { if (buff != null) { buff.write(indentation + " " + key + " : "); buff.newLine(); } // Log.i(AnkiDroidApp.TAG, " " + indentation + key + " : "); printJSONObject((JSONObject) value, indentation + "-", buff); } else { if (buff != null) { buff.write(indentation + " " + key + " = " + jsonObject.get(key).toString()); buff.newLine(); } // Log.i(AnkiDroidApp.TAG, " " + indentation + key + " = " + jsonObject.get(key).toString()); } } catch (JSONException e) { Log.e(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); } } } catch (IOException e1) { Log.e(AnkiDroidApp.TAG, "IOException = " + e1.getMessage()); } }