Example usage for java.io BufferedWriter newLine

List of usage examples for java.io BufferedWriter newLine

Introduction

In this page you can find the example usage for java.io BufferedWriter newLine.

Prototype

public void newLine() throws IOException 

Source Link

Document

Writes a line separator.

Usage

From source file:Interface.MainJFrame.java

private void btnTXTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTXTActionPerformed
    // TODO add your handling code here:

    BufferedWriter output = null;
    try {/* w  ww.  jav a 2 s  .c o m*/
        File file = new File("output.txt");
        output = new BufferedWriter(new FileWriter(file));
        output.write("Name:" + txtFullName.getText());
        output.newLine();
        output.write("ID:" + txtEmployeeID.getText());
        output.newLine();
        output.write("Phone:" + txtPhoneNumber.getText());
        output.newLine();
        output.write("Address:" + txtAddress.getText());
        output.newLine();
        output.write("Employee Type:" + txtEmployeeType.getText());
        output.newLine();
        output.write("PayCategory:" + txtPayCategory.getText());
        output.newLine();
        output.write("Salary:" + txtSalary.getText());
        output.newLine();
        output.write("Hours:" + txtHours.getText());
        output.newLine();
        output.write("Bonus:" + txtBonuses.getText());
        output.newLine();
        output.write("Total:" + txtTotal.getText());
        output.newLine();

        output.flush();
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:de.tudarmstadt.ukp.dkpro.core.io.ditop.DiTopWriter.java

private void writeConfigFile() throws IOException {
    File configFile = new File(targetLocation, CONFIG_FILE);
    Map<String, Set<Integer>> corpora; // holds all corpus names mapped to (multiple) topic
                                       // numbers
    Set<Integer> currentCorpusTopicNumbers; // entry for the current, new topic

    if (appendConfig && configFile.exists()) {
        // read existing entries from config file
        corpora = readConfigFile(configFile);
        currentCorpusTopicNumbers = corpora.containsKey(corpusName) ? corpora.get(corpusName)
                : new HashSet<Integer>();
    } else {//from   www. ja  va  2s.c  o  m
        corpora = new HashMap<>();
        currentCorpusTopicNumbers = new HashSet<>(1, 1);
    }

    currentCorpusTopicNumbers.add(model.getNumTopics());
    corpora.put(corpusName, currentCorpusTopicNumbers);

    getLogger().info(String.format("Writing configuration file '%s'.", configFile.getPath()));
    BufferedWriter configWriter = new BufferedWriter(new FileWriter(configFile));

    for (Entry<String, Set<Integer>> entry : corpora.entrySet()) {
        configWriter.write(entry.getKey());
        for (Integer topicNumber : entry.getValue()) {
            configWriter.write(FIELDSEPARATOR_CONFIGFILE + topicNumber);
        }
        configWriter.newLine();
    }
    configWriter.close();
}

From source file:net.es.netshell.kernel.users.Users.java

private synchronized void writeUserFile() throws IOException {
    File passwordFile = new File(this.passwordFilePath.toString());
    BufferedWriter writer = new BufferedWriter(new FileWriter(passwordFile));
    for (UserProfile p : this.passwords.values()) {
        if (p.getName() != null) {
            writer.write(p.toString());/*from  w w w .  j a  va2  s  . c o m*/
            writer.newLine();
        }
    }
    writer.flush();
    writer.close();
}

From source file:diffhunter.Indexer.java

public void Make_Index(Database hashdb, String file_name, String read_gene_location)
        throws FileNotFoundException, IOException {
    Set_Parameters();/*from w  ww.j a v  a 2s .com*/
    //System.out.print("Sasa");
    ConcurrentHashMap<String, Map<Integer, Integer>> dic_gene_loc_count = new ConcurrentHashMap<>();
    ArrayList<String> lines_from_bed_file = new ArrayList<>();
    BufferedReader br = new BufferedReader(new FileReader(file_name));

    String line = br.readLine();
    List<String> toks = Arrays.asList(line.split("\t"));
    lines_from_bed_file.add(line);
    String last_Seen_chromosome = toks.get(0).replace("chr", "");
    line = br.readLine();
    lines_from_bed_file.add(line);
    toks = Arrays.asList(line.split("\t"));
    String new_chromosome = toks.get(0).replace("chr", "");

    while (((line = br.readLine()) != null) || lines_from_bed_file.size() > 0) {
        if (line != null) {
            toks = Arrays.asList(line.split("\t"));
            new_chromosome = toks.get(0).replace("chr", "");
        }
        // process the line.
        if (line == null || !new_chromosome.equals(last_Seen_chromosome)) {
            System.out.println("Processing chromosome" + "\t" + last_Seen_chromosome);
            last_Seen_chromosome = new_chromosome;
            lines_from_bed_file.parallelStream().forEach(content -> {

                List<String> inner_toks = Arrays.asList(content.split("\t"));
                //WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING 
                //STRAND column count should be changed. 
                String strand = inner_toks.get(5);
                String chromosome_ = inner_toks.get(0).replace("chr", "");
                if (!dic_Loc_gene.get(strand).containsKey(chromosome_)) {
                    return;
                }
                Integer start_loc = Integer.parseInt(inner_toks.get(1));
                Integer end_loc = Integer.parseInt(inner_toks.get(2));
                List<Interval<String>> res__ = dic_Loc_gene.get(strand).get(chromosome_).getIntervals(start_loc,
                        end_loc);
                //IntervalTree<String> pot_gene_name=new IntervalTree<>(res__);
                //                        for (int z = 0; z < pot_gene_name.Intervals.Count; z++)
                //{
                for (int z = 0; z < res__.size(); z++) {

                    dic_gene_loc_count.putIfAbsent(res__.get(z).getData(), new HashMap<>());
                    String gene_symbol = res__.get(z).getData();
                    Integer temp_gene_start_loc = dic_genes.get(gene_symbol).start_loc;
                    Integer temp_gene_end_loc = dic_genes.get(gene_symbol).end_loc;
                    if (start_loc < temp_gene_start_loc) {
                        start_loc = temp_gene_start_loc;
                    }
                    if (end_loc > temp_gene_end_loc) {
                        end_loc = temp_gene_end_loc;
                    }
                    synchronized (dic_synchrinzer_genes.get(gene_symbol)) {
                        for (int k = start_loc; k <= end_loc; k++) {
                            Integer value_inside = 0;
                            value_inside = dic_gene_loc_count.get(gene_symbol).get(k);
                            dic_gene_loc_count.get(gene_symbol).put(k,
                                    value_inside == null ? 1 : (value_inside + 1));
                        }
                    }
                }
            });
            /*                    List<string> keys_ = dic_gene_loc_count.Keys.ToList();
             List<string> alt_keys = new List<string>();// dic_gene_loc_count.Keys.ToList();
             for (int i = 0; i < keys_.Count; i++)
             {
             Dictionary<int, int> dicccc_ = new Dictionary<int, int>();
             dic_gene_loc_count[keys_[i]] = new Dictionary<int, int>(dic_gene_loc_count[keys_[i]].Where(x => x.Value >= 2).ToDictionary(x => x.Key, x => x.Value));
             if (dic_gene_loc_count[keys_[i]].Count == 0)
             {
                    
             dic_gene_loc_count.TryRemove(keys_[i], out dicccc_);
             continue;
             }
             hashdb.Put(Get_BDB(keys_[i]), Get_BDB_Dictionary(dic_gene_loc_count[keys_[i]]));
             alt_keys.Add(keys_[i]);
             dic_gene_loc_count.TryRemove(keys_[i], out dicccc_);
             }*/
            ArrayList<String> keys_ = new ArrayList<>(dic_gene_loc_count.keySet());
            ArrayList<String> alt_keys = new ArrayList<>();
            for (int i = 0; i < keys_.size(); i++) {

                //LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(dic_gene_loc_count.get(keys_.get(i)));
                LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>();
                /*tmep_map = */
                dic_gene_loc_count.get(keys_.get(i)).entrySet().stream().filter(p -> p.getValue() >= 2)
                        .sorted(Comparator.comparing(E -> E.getKey()))
                        .forEach((entry) -> tmep_map.put(entry.getKey(), entry.getValue()));//.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
                if (tmep_map.isEmpty()) {
                    dic_gene_loc_count.remove(keys_.get(i));
                    continue;
                }

                //Map<Integer, Integer> tmep_map1 = new LinkedHashMap<>();
                //tmep_map1=sortByKey(tmep_map);
                //tmep_map.entrySet().stream().sorted(Comparator.comparing(E -> E.getKey())).forEach((entry) -> tmep_map1.put(entry.getKey(), entry.getValue()));
                //BerkeleyDB_Box box=new BerkeleyDB_Box();
                hashdb.put(null, BerkeleyDB_Box.Get_BDB(keys_.get(i)),
                        BerkeleyDB_Box.Get_BDB_Dictionary(tmep_map));
                alt_keys.add(keys_.get(i));
                dic_gene_loc_count.remove(keys_.get(i));
                //dic_gene_loc_count.put(keys_.get(i),tmep_map);
            }

            hashdb.sync();
            int a = 1111;
            /*                    hashdb.Sync();
             File.AppendAllLines("InputDB\\" + Path.GetFileNameWithoutExtension(file_name) + "_genes.txt", alt_keys);
             //total_lines_processed_till_now += lines_from_bed_file.Count;
             //worker.ReportProgress(total_lines_processed_till_now / count_);
             lines_from_bed_file.Clear();
             if (!reader.EndOfStream)
             {
             lines_from_bed_file.Add(_line_);
             }
             last_Seen_chromosome = new_choromosome;*/
            lines_from_bed_file.clear();
            if (line != null) {
                lines_from_bed_file.add(line);
            }
            Path p = Paths.get(file_name);
            file_name = p.getFileName().toString();

            BufferedWriter output = new BufferedWriter(new FileWriter((Paths
                    .get(read_gene_location, FilenameUtils.removeExtension(file_name) + ".txt").toString()),
                    true));
            for (String alt_key : alt_keys) {
                output.append(alt_key);
                output.newLine();
            }
            output.close();
            /*if (((line = br.readLine()) != null))
            {
            lines_from_bed_file.add(line);
            toks=Arrays.asList(line.split("\t"));
            new_chromosome=toks.get(0).replace("chr", "");
            }*/
            //last_Seen_chromosome=new_chromosome;
        } else if (new_chromosome.equals(last_Seen_chromosome)) {
            lines_from_bed_file.add(line);
        }

    }
    br.close();
    hashdb.sync();
    hashdb.close();

}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.errormining.SpellingErrorFilter.java

private void writeItem(BufferedWriter writer, DatasetItem item) throws AnalysisEngineProcessException {
    try {/*  w ww.  ja v a  2 s  .  com*/
        writer.write(item.toString());
        writer.newLine();
        writer.flush();
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
}

From source file:com.nordicsemi.nrfUARTv2.MainActivity.java

private void generateNoteOnSD(String sFileName, String sBody) {
    File root = new File(Environment.getExternalStorageDirectory(), "Sensors");
    if (!root.exists()) {
        root.mkdirs();//from   www  .  ja  v a  2 s .c  o  m
    }
    File gpxfile = new File(root, sFileName);
    try {
        BufferedWriter bW;
        bW = new BufferedWriter(new FileWriter(gpxfile, true));
        bW.write(sBody);
        bW.newLine();
        bW.flush();
        bW.close();
    } catch (IOException e) {

    }
}

From source file:com.adito.server.jetty.CustomJsseListener.java

protected ServerSocket newServerSocket(InetAddrPort p_address, int p_acceptQueueSize) throws IOException {
    SSLServerSocket serverSocket = (SSLServerSocket) super.newServerSocket(p_address, p_acceptQueueSize);
    if (serverSocket.getNeedClientAuth()) {

        serverSocket.setNeedClientAuth(require);
        setNeedClientAuth(require);/* w  ww.  ja  v  a2 s .c  om*/
        if (!require)
            serverSocket.setWantClientAuth(true);
    }

    String[] ciphers = serverSocket.getSupportedCipherSuites();
    String[] protocols = serverSocket.getSupportedProtocols();

    if (log.isInfoEnabled()) {
        log.info("The following protocols are supported:");
        for (int i = 0; i < protocols.length; i++) {
            log.info("     " + protocols[i]);
        }
    }

    if (createAvailableCipherSuitesList) {
        File f = new File(ContextHolder.getContext().getTempDirectory(), "availableCipherSuites.txt");
        BufferedWriter writer = null;

        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
            if (log.isInfoEnabled())
                log.info("The following cipher suites are supported:");
            for (int i = 0; i < ciphers.length; i++) {
                if (log.isInfoEnabled())
                    log.info("     " + ciphers[i]);
                writer.write(ciphers[i]);
                writer.newLine();
            }
        } catch (Throwable e) {
            log.error("Could not create cipher list!", e);
            configureContext = false;
        } finally {
            if (writer != null)
                writer.close();
        }
        createAvailableCipherSuitesList = false;
    }

    if (configureContext) {

        PropertyList list = ContextHolder.getContext().getConfig()
                .retrievePropertyList(new ContextKey("ssl.supportedProtocols"));

        if (!list.isEmpty()) {
            serverSocket.setEnabledProtocols(list.asArray());
        }

        list = ContextHolder.getContext().getConfig()
                .retrievePropertyList(new ContextKey("ssl.supportedCiphers"));

        if (!list.isEmpty()) {
            serverSocket.setEnabledCipherSuites(list.asArray());
        }
    }

    protocols = serverSocket.getEnabledProtocols();

    if (log.isInfoEnabled()) {
        log.info("The following protocols are enabled:");
        for (int i = 0; i < protocols.length; i++) {
            log.info("     " + protocols[i]);
        }
    }

    ciphers = serverSocket.getEnabledCipherSuites();
    if (log.isInfoEnabled()) {
        log.info("The following cipher suites are enabled:");
        for (int i = 0; i < ciphers.length; i++) {
            log.info("     " + ciphers[i]);
        }
    }

    return serverSocket;
}

From source file:com.itemanalysis.jmetrik.gui.JmetrikPreferencesManager.java

private void createLogProperties(String logHome) {
    //directory should already exist
    //create log4j properties file if it does not exist
    String header = "#DO NOT EDIT - JMETRIK LOG PROPERTIES FILE - DO NOT EDIT";
    String fullPropertiesName = (logHome + "/" + DEFAULT_LOG_PROPERTY_FILE);
    String fullLogFileName = (logHome + "/" + DEFAULT_LOG_NAME);
    String fullScriptLogFileName = (logHome + "/" + DEFAULT_SCRIPT_LOG_NAME);

    File f = new File(fullPropertiesName);
    if (!f.exists()) {
        try {//from ww  w  . ja  v  a  2  s . co m
            createLogHome(logHome);
            f.createNewFile();
            BufferedWriter bw = new BufferedWriter(new FileWriter(f));
            bw.append(header);
            bw.newLine();
            bw.append("log4j.logger.jmetrik-logger=ALL, adminAppender");
            bw.newLine();
            bw.append("log4j.logger.jmetrik-script-logger=INFO, scriptAppender");
            bw.newLine();
            bw.append("log4j.additivity.jmetrik-logger=false");
            bw.newLine();
            bw.append("log4j.additivity.jmetrik-script-logger=false");
            bw.newLine();

            //Main appender processes all levels
            bw.append("log4j.appender.adminAppender=org.apache.log4j.FileAppender");
            bw.newLine();
            bw.append("log4j.appender.adminAppender.layout=org.apache.log4j.PatternLayout");
            bw.newLine();
            bw.append("log4j.appender.adminAppender.File=" + fullLogFileName);
            bw.newLine();
            bw.append("log4j.appender.adminAppender.Append=false");
            bw.newLine();
            bw.append("log4j.appender.adminAppender.layout.ConversionPattern=[%p] %d{DATE} %n%m%n%n");
            bw.newLine();

            //Script appender processes scripts only
            bw.append("log4j.appender.scriptAppender=org.apache.log4j.FileAppender");
            bw.newLine();
            bw.append("log4j.appender.scriptAppender.layout=org.apache.log4j.PatternLayout");
            bw.newLine();
            bw.append("log4j.appender.scriptAppender.File=" + fullScriptLogFileName);
            bw.newLine();
            bw.append("log4j.appender.scriptAppender.Append=false");
            bw.newLine();
            bw.append("log4j.appender.scriptAppender.layout.ConversionPattern=%m%n%n");
            bw.newLine();

            bw.close();
        } catch (IOException ex) {
            firePropertyChange("error", "", "Error - Log properties file could not be created.");
        }
    }
}

From source file:de.dfki.km.perspecting.obie.experiments.PhraseExperiment.java

@Test
public void analysePhraseLength() throws Exception {
    final BufferedWriter bw = new BufferedWriter(
            new FileWriter($SCOOBIE_HOME + "results/token_length_histogram.csv"));
    Connection conn = pool.getConnection();
    ResultSet rs = conn.createStatement().executeQuery(
            "SELECT length(literal), count(*)  FROM index_literals GROUP BY length(literal) ORDER BY length(literal)");
    while (rs.next()) {
        bw.append(rs.getInt(1) + "\t" + rs.getInt(2));
        bw.newLine();
    }//from   w  ww.j  a v  a 2 s  . c o m
    bw.close();
}

From source file:com.ideateam.plugin.Version.java

public void writeLocaleToFile(String fileName, String msg) {

    try {//from  w  ww .j a v a 2s  .  c om
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/UAR2015/" + fileName;

        File file = new File(path);

        if (!file.exists()) {
            File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/UAR2015/");
            f.mkdirs();
            file.createNewFile();

        }

        BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
        buf.append(msg);
        buf.newLine();
        buf.close();
        // callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "writed to file"));
        Log.d(TAG, "..callBackPlugin");
        activity.sendJavascript("UART.system.Helper.callBackPlugin('ok')");

    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }

}