// ------------------------------------
 // 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);
   }
 }
  private void saveFile(File file) {
    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter(file));

      for (QuizCard card : cardList) {
        writer.write(card.getQuestion() + "/");
        writer.write(card.getAnswer() + "/n");
      }
    } catch (IOException ex) {
      System.out.println("Couldn't wirite the cardList out");
      ex.printStackTrace();
    }
  }
Esempio n. 3
0
 public void write() {
   filename = "open/" + filename;
   try {
     BufferedWriter br = new BufferedWriter(new FileWriter(new File(filename)));
     br.write(precode);
     for (int i = 0; i < classes.size(); i++) {
       System.out.println("Jooifying " + (i + 1) + " out of " + classes.size() + 1);
       br.write(((Class) classes.get(i)).toString());
     }
     br.close();
     System.out.println("Written file " + filename);
   } catch (Exception e) {
     System.out.println("Exception " + e + " occured");
   }
 }
Esempio n. 4
0
  public void save() {
    BufferedWriter sourceFile = null;

    try {
      String sourceText = sourceArea.getText();

      String cleanText = cleanupSource(sourceText);

      if (cleanText.length() != sourceText.length()) {
        sourceArea.setText(cleanText);

        String message =
            String.format(
                "One or more invalid characters at the end of the source file have been removed.");
        JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE);
      }

      sourceFile = new BufferedWriter(new FileWriter(sourcePath, false));
      sourceFile.write(cleanText);

      setSourceChanged(false);

      setupMenus();
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (sourceFile != null) {
        try {
          sourceFile.close();
        } catch (IOException ignore) {
        }
      }
    }
  }
Esempio n. 5
0
 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();
 }
Esempio n. 6
0
 /**
  * When exiting the game, save the best score to the record file.
  *
  * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
  */
 @Override
 public void windowClosing(WindowEvent arg0) {
   try {
     recordWriter = new BufferedWriter(new FileWriter("res/record"));
     recordWriter.write(String.valueOf(bestScore));
     recordWriter.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 7
0
    private void output(String string) throws Exception {
      if (bw != null) bw.write(string);
      else append(string);

      // Set the fraction done.
      long pct = (filePosition * 100) / fileLength;
      if (pct != percentDone) {
        percentDone = pct;
        setMessage("Working... (" + pct + "%)");
      }
    }
Esempio n. 8
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");
   }
 }
Esempio n. 9
0
    public void actionPerformed(ActionEvent ae) {

      if (ae.getActionCommand().equals("clear")) {
        scriptArea.setText("");
      } else if (ae.getActionCommand().equals("save")) {
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showSaveDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          String cadena1 = scriptArea.getText();
          String cadena2 = cadena1.replace("\r", "\n");
          System.out.println(cadena1);
          try {
            BufferedWriter script =
                new BufferedWriter(new FileWriter(fileChooser.getSelectedFile() + ".txt"));
            script.write(cadena2);
            script.close();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          JOptionPane.showMessageDialog(myWindow, "File: " + file.getName() + " Saved.\n");
        }
        scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
      } else if (ae.getActionCommand().equals("quit")) {
        myWindow.setVisible(false);
      } else if (ae.getActionCommand().equals("load")) {
        // String arreglo[] = new String[100];
        // int i = 0;
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showOpenDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          try {
            BufferedReader script =
                new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
            scriptArea.read(script, null);
            script.close();
            scriptArea.requestFocus();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          myWindow.setTitle(file.getName());
          JOptionPane.showMessageDialog(myWindow, file.getName() + ": File loaded.\n");
          scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
        }
      } else if (ae.getActionCommand().equals("run")) {
        System.out.println("LEL");
      }
    }
Esempio n. 10
0
 public void save(String s, File f) {
   try {
     int saveNumber = 1;
     File file = new File(f.getAbsolutePath() + "/save.adv");
     while (file.exists()) {
       file = new File(f.getAbsolutePath() + "/save" + saveNumber + ".adv");
       saveNumber++;
     }
     file.createNewFile();
     FileWriter fWriter = new FileWriter(file.getAbsoluteFile());
     BufferedWriter bWriter = new BufferedWriter(fWriter);
     bWriter.write(s);
     bWriter.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 11
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Esempio n. 12
0
    public void actionPerformed(ActionEvent e) {
      double payRate, hours, basePay, overtimePay, overtimeHours, netPay;
      String payDate, name, hoursErr, outputStr;

      payDate = (dateTF.getText());
      name = (nameTF.getText());
      payRate = Double.parseDouble(payrateTF.getText().is);
      hours = Double.parseDouble(hoursworkedTF.getText());
      overtimeHours = Double.parseDouble(otworkedTF.getText());
      basePay = payRate * hours;
      overtimePay = (1.5 * payRate) * overtimeHours;
      netPay = basePay + overtimePay;

      // throw error if hours entered is more than 40
      if (hours > 40) {
        hoursErr =
            "Hours worked must be 40 or less. Please enter "
                + "the data again. Any additional time over 40 is considered"
                + " overtime.";

        JOptionPane.showMessageDialog(null, hoursErr, "Error", JOptionPane.ERROR_MESSAGE);
      }

      // or continue with output
      else {

        outputStr =
            "Regular Pay: $"
                + basePay
                + "\n"
                + "Overtime Pay: $"
                + overtimePay
                + "\n"
                + "Total Pay: $"
                + netPay
                + "\n\n"
                + "Summary available in the EmployeePayroll.txt file.";

        JOptionPane.showMessageDialog(
            null, outputStr, "Total Pay for " + name + ".", JOptionPane.INFORMATION_MESSAGE);
      }

      try {
        // Create text file, publish information, and close it.
        FileWriter fstream = new FileWriter("EmployeePayroll.txt", true);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write("***Pay Calculation***\n");
        out.write("Pay Date: " + payDate + "\n");
        out.write("Employee Name: " + name + "\n");
        out.write("Pay Rate: " + payRate + "\n");
        out.write("Regular Hours: " + hours + "\n");
        out.write("Overtime Hours: " + overtimeHours + "\n");
        out.write("Regular Pay: $" + basePay + "\n");
        out.write("Overtime Pay: $" + overtimePay + "\n");
        out.write("Total Pay: $" + netPay + "\n");

        // Close the output stream
        out.close();
      } catch (Exception f) { // Catch exception if any
        System.err.println("Error: " + f.getMessage());
      }
    }