예제 #1
0
파일: Installer.java 프로젝트: suever/CTP
 private void setFileText(File file, String text) throws Exception {
   BufferedWriter bw =
       new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
   bw.write(text, 0, text.length());
   bw.flush();
   bw.close();
 }
예제 #2
0
    public static Settings init() throws Exception {
      File f = new File("galaxyviewer.ini");
      if (f.getAbsoluteFile().getParentFile().getName().equals("bin"))
        f = new File("..", "galaxyviewer.ini");
      Settings settings;
      if (f.exists()) {
        settings = new Settings();
        BufferedReader in = new BufferedReader(new FileReader(f));
        while (true) {
          String s = in.readLine();
          if (s == null) break;
          if (s.contains("=") == false) continue;
          String[] el = s.split("=", -1);
          if (el[0].equalsIgnoreCase("PlayerNr"))
            settings.playerNr = Integer.parseInt(el[1].trim()) - 1;
          if (el[0].equalsIgnoreCase("GameName")) settings.gameName = el[1].trim();
          if (el[0].equalsIgnoreCase("GameDir")) settings.directory = el[1].trim();
        }
        in.close();
      } else settings = new Settings();

      JTextField pNr = new JTextField("" + (settings.playerNr + 1));
      JTextField gName = new JTextField(settings.gameName);
      JTextField dir = new JTextField("" + settings.directory);

      JPanel p = new JPanel();
      p.setLayout(new GridLayout(3, 2));
      p.add(new JLabel("Player nr"));
      p.add(pNr);
      p.add(new JLabel("Game name"));
      p.add(gName);
      p.add(new JLabel("Game directory"));
      p.add(dir);
      gName.setToolTipText("Do not include file extensions");
      String[] el = {"Ok", "Cancel"};
      int ok =
          JOptionPane.showOptionDialog(
              null,
              p,
              "Choose settings",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              el,
              el[0]);
      if (ok != 0) System.exit(0);
      settings.playerNr = Integer.parseInt(pNr.getText().trim()) - 1;
      settings.directory = dir.getText().trim();
      settings.gameName = gName.getText().trim();
      BufferedWriter out = new BufferedWriter(new FileWriter(f));
      out.write("PlayerNr=" + (settings.playerNr + 1) + "\n");
      out.write("GameName=" + settings.gameName + "\n");
      out.write("GameDir=" + settings.directory + "\n");
      out.flush();
      out.close();
      return settings;
    }
예제 #3
0
 /**
  * Writes the error model into the options file so that they can be read by the generator at a
  * later time
  */
 public void storeModelPreference(String model) {
   try {
     FileWriter x = new FileWriter("options", true);
     BufferedWriter optionWriter = new BufferedWriter(x);
     String data = "<IpErrorModel> " + model + " </IpErrorModel>\n";
     optionWriter.write(data, 0, data.length());
     optionWriter.flush();
     optionWriter.close();
   } catch (Exception e) {
     System.out.println("Error while writing to options file in ipModelsMenu.java");
   }
 }
예제 #4
0
 // ------------------------------------
 // Send RTSP Response
 // ------------------------------------
 private void send_RTSP_response() {
   try {
     RTSPBufferedWriter.write("RTSP/1.0 200 OK" + CRLF);
     RTSPBufferedWriter.write("CSeq: " + RTSPSeqNb + CRLF);
     RTSPBufferedWriter.write("Session: " + RTSP_ID + CRLF);
     RTSPBufferedWriter.flush();
     // System.out.println("RTSP Server - Sent response to Client.");
   } catch (Exception ex) {
     System.out.println("Exception caught: " + ex);
     System.exit(0);
   }
 }
예제 #5
0
파일: Vue.java 프로젝트: exidhor/Bejeweled
  public void ecrireFichier(String chemin, Vector<Integer> highScore) {
    try {
      FileWriter fw = new FileWriter(chemin, false);

      BufferedWriter output = new BufferedWriter(fw);

      for (int i = 0; i < highScore.size(); i++) {
        output.write(highScore.get(i).toString());
        output.newLine();
      }

      output.flush();

      output.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #6
0
    public void run() {
      try {
        BufferedReader br =
            new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
        if (outputFile != null) {
          bw =
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), charset));
        }
        String line;
        while ((line = br.readLine()) != null) {
          filePosition += line.length() + 2;
          line = line.trim();
          if (!line.startsWith("#")) {
            String[] sides = split(line);
            if ((sides != null) && !sides[0].equals("key")) {

              if (searchPHI) {
                // Search the decrypted PHI for the searchText
                sides[0] = decrypt(sides[0]);
                if (sides[0].indexOf(searchText) != -1) {
                  output(sides[0] + " = " + sides[1] + "\n");
                }
              } else {
                // Search the trial ID for the searchText
                if (sides[1].indexOf(searchText) != -1) {
                  sides[0] = decrypt(sides[0]);
                  output(sides[0] + " = " + sides[1] + "\n");
                }
              }
            }
          }
        }
        br.close();
        if (bw != null) {
          bw.flush();
          bw.close();
        }
      } catch (Exception e) {
        append("\n\n" + e.getClass().getName() + ": " + e.getMessage() + "\n");
      }
      append("\nDone.\n");
      setMessage("Ready...");
    }