Changeset 50 for java/ecj


Ignore:
Timestamp:
12/10/09 03:59:38 (14 years ago)
Author:
mszubert
Message:

Newline character removed from framstick genotypes.
Reading from input streams refactored (and optimized).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/ecj/framsticks/FramsticksUtils.java

    r49 r50  
    44import java.io.BufferedWriter;
    55import java.io.File;
     6import java.io.FileNotFoundException;
    67import java.io.FileReader;
    78import java.io.FileWriter;
     9import java.io.IOException;
    810import java.io.InputStreamReader;
    911
     
    8385
    8486        private String executeCommand(String command) {
    85                 String line;
    86                 String result = "";
    87                
    8887                if (debug) {
    8988                        System.err.println("Executing command : " + command);
    9089                }
    9190               
     91                String result = new String();
    9292                try {
    9393                        File f = new File(directoryPath);
    9494                        Process p = Runtime.getRuntime().exec(directoryPath + command, null, f);
    9595                        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    96                         while ((line = input.readLine()) != null) {
    97                                 result += (line + '\n');
    98                         }
    99                         input.close();
     96                        result = readInput(input);
    10097                } catch (Exception ex) {
    10198                        ex.printStackTrace();
     
    105102                        System.err.println("Result : " + result);
    106103                }
    107                
     104
    108105                return result;
    109106        }
     
    120117
    121118        private String readFromFile(String filePath) {
    122                 String line;
    123                 String result = "";
     119                String result = new String();
    124120                try {
    125121                        BufferedReader input = new BufferedReader(new FileReader(filePath));
     122                        result = readInput(input);
     123                } catch (FileNotFoundException e) {
     124                        e.printStackTrace();
     125                }
     126                return result;
     127        }
     128       
     129        private String readInput(BufferedReader input) {
     130                StringBuilder result = new StringBuilder();
     131               
     132                try {
     133                        String line;
    126134                        while ((line = input.readLine()) != null) {
    127                                 result += (line + '\n');
     135                                result.append(line + '\n');
    128136                        }
    129137                        input.close();
    130                 } catch (Exception ex) {
     138                } catch (IOException ex) {
    131139                        ex.printStackTrace();
    132140                }
    133141
    134                 return result;
     142                //Delete last newline character
     143                if (result.length() > 0) {
     144                        return result.substring(0, result.length() - 1);
     145                } else {
     146                        return result.toString();
     147                }
    135148        }
    136149
Note: See TracChangeset for help on using the changeset viewer.