Exemplo n.º 1
0
  /** Accepts submission from the configuration page. */
  @RequirePOST
  public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException, FormException {
    checkPermission(CONFIGURE);

    description = req.getParameter("description");

    keepDependencies = req.getParameter("keepDependencies") != null;

    try {
      JSONObject json = req.getSubmittedForm();

      setDisplayName(json.optString("displayNameOrNull"));

      if (req.getParameter("logrotate") != null)
        logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
      else logRotator = null;

      DescribableList<JobProperty<?>, JobPropertyDescriptor> t =
          new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP, getAllProperties());
      t.rebuild(
          req,
          json.optJSONObject("properties"),
          JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
      properties.clear();
      for (JobProperty p : t) {
        p.setOwner(this);
        properties.add(p);
      }

      submit(req, rsp);

      save();
      ItemListener.fireOnUpdated(this);

      String newName = req.getParameter("name");
      final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy();
      if (newName != null && !newName.equals(name)) {
        // check this error early to avoid HTTP response splitting.
        Jenkins.checkGoodName(newName);
        namingStrategy.checkName(newName);
        rsp.sendRedirect("rename?newName=" + URLEncoder.encode(newName, "UTF-8"));
      } else {
        if (namingStrategy.isForceExistingJobs()) {
          namingStrategy.checkName(name);
        }
        FormApply.success(".").generateResponse(req, rsp, null);
      }
    } catch (JSONException e) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      pw.println("Failed to parse form data. Please report this problem as a bug");
      pw.println("JSON=" + req.getSubmittedForm());
      pw.println();
      e.printStackTrace(pw);

      rsp.setStatus(SC_BAD_REQUEST);
      sendError(sw.toString(), req, rsp, true);
    }
  }
Exemplo n.º 2
0
 public void totalExport() {
   File expf = new File("export");
   if (expf.exists()) rmrf(expf);
   expf.mkdirs();
   for (int sto = 0; sto < storeLocs.size(); sto++) {
     try {
       String sl =
           storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-");
       File estore = new File(expf, sl);
       estore.mkdir();
       File log = new File(estore, LIBRARY_NAME);
       PrintWriter pw = new PrintWriter(log);
       for (int i = 0; i < store.getRowCount(); i++)
         if (store.curStore(i) == sto) {
           File enc = store.locate(i);
           File dec = sec.prepareMainFile(enc, estore, false);
           pw.println(dec.getName());
           pw.println(store.getValueAt(i, Storage.COL_DATE));
           pw.println(store.getValueAt(i, Storage.COL_TAGS));
           synchronized (jobs) {
             jobs.addLast(expJob(enc, dec));
           }
         }
       pw.close();
     } catch (IOException exc) {
       exc.printStackTrace();
       JOptionPane.showMessageDialog(frm, "Exporting Failed");
       return;
     }
   }
   JOptionPane.showMessageDialog(frm, "Exporting to:\n   " + expf.getAbsolutePath());
 }
Exemplo n.º 3
0
  public void updateFile() {
    // writes highscore, coins and updates eveything else
    try {
      outFile = new PrintWriter(new BufferedWriter(new FileWriter("stats.txt")));
      outFile.println("" + (money + coins));
      outFile.println("" + powerUps.size());
      for (int i = 0; i < powerUps.size(); i++) {
        outFile.println("" + powerUps.get(i)); // writes the highscore in the file
      }
      outFile.println("" + chars.size());
      for (int i = 0; i < chars.size(); i++) {
        outFile.println("" + chars.get(i));
      }
      if (Integer.parseInt(stats.get(stats.size() - 3)) < score) {
        outFile.println(score);
      } else {
        outFile.println(stats.get(stats.size() - 3));
      }
      if (Integer.parseInt(stats.get(stats.size() - 2)) < score) {
        outFile.println(height);
      } else {
        outFile.println(stats.get(stats.size() - 2));
      }
      outFile.println(Integer.parseInt(stats.get(stats.size() - 1)) + height);

      outFile.close();
    } catch (IOException ex) {
      System.out.println("yooo stop noobing out");
    }
  }
Exemplo n.º 4
0
  /**
   * 向服务器发送命令行,给服务器端处理
   *
   * @param lines 命令行
   */
  public static void clientSend(String[] lines) {
    if (lines != null && lines.length <= 0) {
      return;
    }
    Socket socket = null;
    PrintWriter writer = null;
    try {
      socket = new Socket("localhost", port);

      writer =
          new PrintWriter(
              new BufferedWriter(
                  new OutputStreamWriter(
                      socket.getOutputStream(), EncodeConstants.ENCODING_UTF_8)));
      for (int i = 0; i < lines.length; i++) {
        writer.println(lines[i]);
      }

      writer.flush();
    } catch (Exception e) {
      FRContext.getLogger().error(e.getMessage(), e);
    } finally {
      try {
        writer.close();
        socket.close();
      } catch (IOException e) {
        FRContext.getLogger().error(e.getMessage(), e);
      }
    }
  }
  public void connect(String page) {
    bf.status.setText("Connecting to server...");
    try {
      Socket socket = new Socket(server, port);
      // Set the server connect timeout to 5 seconds
      socket.setSoTimeout(5000);
      BufferedReader inputStream =
          new BufferedReader(new InputStreamReader(socket.getInputStream()));
      PrintWriter outputStream =
          new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);

      bf.status.setText("Reading URL...");
      outputStream.println("GET " + page + " HTTP/1.0");
      outputStream.println("Host: " + server);
      outputStream.println();
      String line = "";
      String text = "";
      int count = 0;
      boolean headers = true;
      while ((line = inputStream.readLine()) != null) {
        if (line.equals("")) {
          headers = false;
        }
        if (!headers && !line.equals("")) {
          text = text + parse(line) + "\n";
        }
        if (count != 1) {
          bf.status.setText("Read " + count + " lines");
        } else {
          bf.status.setText("Read " + count + " line");
        }
        count++;
      }
      bf.setText(text);
      bf.status.setText("done");

      socket.close();

    } catch (UnknownHostException e) {
      System.out.println(e);
      bf.setText("Not online");
      bf.status.setText("");
    } catch (SocketException e) {
      System.out.println("Socket Exception " + e);
      bf.setText("Socket exception");
      bf.status.setText("");
    } catch (InterruptedIOException e) {
      System.out.println("Read to server timed out " + e);
      bf.setText("Server connect timed out");
      bf.status.setText("");
    } catch (IOException e) {
      bf.setText("IO exception");
      bf.status.setText("");
      System.out.println("IOException " + e);
    }
  }
Exemplo n.º 6
0
  private void onOK() {
    // add your code here
    try {
      PrintWriter pw = new PrintWriter("data\\out.txt");
      pw.println(textField1.getText());
      pw.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 7
0
  // メッセージをサーバーに送信する
  public void sendMessage(String msg) {
    try {
      OutputStream output = socket.getOutputStream();
      PrintWriter writer = new PrintWriter(output);

      writer.println(msg);
      writer.flush();
    } catch (Exception err) {
      msgTextArea.append("ERROR>" + err + "\n");
    }
  }
Exemplo n.º 8
0
 java.util.List<Double> getHistory(String comp, int count) {
   int cmdID = commID++;
   // connect(user.getName(),user.getPassword());
   try {
     out.println(cmdID + ";" + "getch:" + comp + ":" + Integer.toString(count));
     out.flush();
     return (java.util.List<Double>) receiveReply(cmdID);
   } catch (Exception r) {
     r.printStackTrace();
   }
   return null;
 }
Exemplo n.º 9
0
 String cancelShares(String user, String pass, int id, int sellid) {
   int cmdID = commID++;
   connect(user, pass);
   try {
     out.println(cmdID + ";cancel:" + id + ":" + sellid);
     out.flush();
     return (String) receiveReply(cmdID);
   } catch (Exception r) {
     r.printStackTrace();
   }
   return null;
 }
Exemplo n.º 10
0
 String getChatHistory(String user, String pass) {
   int cmdID = commID++;
   connect(user, pass);
   try {
     out.println(cmdID + ";chath");
     out.flush();
     return (String) receiveReply(cmdID);
   } catch (Exception r) {
     r.printStackTrace();
   }
   return null;
 }
Exemplo n.º 11
0
 String sendChat(String s, String user, String pass) {
   int cmdID = commID++;
   connect(user, pass);
   try {
     out.println(cmdID + ";chat:" + s.trim());
     out.flush();
     return (String) receiveReply(cmdID);
   } catch (Exception r) {
     r.printStackTrace();
   }
   return null;
 }
 public void actionPerformed(ActionEvent event) {
   try {
     FileWriter fw = new FileWriter("gui21dataOut.txt");
     PrintWriter pw = new PrintWriter(fw);
     String nameList = txtAreaRight.getText();
     pw.write(nameList);
     pw.close();
     JOptionPane.showMessageDialog(null, "File created:\n\n" + nameList);
   } catch (IOException e) {
     System.out.println("file output error");
   }
 }
Exemplo n.º 13
0
 public void disconnect() {
   int cmdID = commID++;
   this.connected = false;
   try {
     out.println(cmdID + ";logout");
     out.flush();
     in.close();
     out.close();
     socket.close();
   } catch (IOException ex) {
     System.err.println("Server stop failed.");
   }
 }
Exemplo n.º 14
0
 void placeOrder(final User user, String cmd, Company comp, int qty, int id) {
   int cmdID = commID++;
   connect(user.getName(), user.getPassword());
   try {
     out.println(cmdID + ";" + cmd + ":" + comp.name + ":" + Integer.toString(qty) + ":" + id);
     out.flush();
     Shares pen = (Shares) receiveReply(cmdID);
     user.getPendingShares().add(pen);
     user.dataChanged();
   } catch (Exception r) {
     r.printStackTrace();
   }
 }
Exemplo n.º 15
0
  @Override
  public void doCopy() {
    StringWriter writer = new StringWriter();
    PrintWriter pwriter = new PrintWriter(writer);

    for (String tip : treesPanel.getSelectedTips()) {
      pwriter.println(tip);
    }

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection selection = new StringSelection(writer.toString());
    clipboard.setContents(selection, selection);
  }
Exemplo n.º 16
0
  private void clearSaved() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");
      writer.println("Items:");
      results.setText("Config.txt has been cleared.");
    } catch (FileNotFoundException | UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
Exemplo n.º 17
0
 String login(String domain, String user, String pass) {
   int cmdID = commID++;
   this.domain = domain;
   connect(user, pass);
   try {
     out.println(cmdID + ";login:"******":" + pass);
     out.flush();
     String rep = (String) receiveReply(cmdID);
     return rep.split(":")[0];
   } catch (Exception r) {
     r.printStackTrace();
   }
   return null;
 }
Exemplo n.º 18
0
 User getUserDetails(String user, String pass) {
   int cmdID = commID++;
   connect(user, pass);
   try {
     usrD = 1;
     out.println(cmdID + ";gud");
     out.flush();
     User vv = (User) receiveReply(cmdID);
     usrD = 0;
     return vv;
   } catch (Exception r) {
     r.printStackTrace();
   }
   return null;
 }
Exemplo n.º 19
0
  // Cleanup for disconnect
  private static void cleanUp() {
    try {
      if (hostServer != null) {
        hostServer.close();
        hostServer = null;
      }
    } catch (IOException e) {
      hostServer = null;
    }

    try {
      if (socket != null) {
        socket.close();
        socket = null;
      }
    } catch (IOException e) {
      socket = null;
    }

    try {
      if (in != null) {
        in.close();
        in = null;
      }
    } catch (IOException e) {
      in = null;
    }

    if (out != null) {
      out.close();
      out = null;
    }
  }
Exemplo n.º 20
0
  // Write the output in Uintah format
  private void writeUintah(File outputFile) {

    // Create filewriter and printwriter
    try {
      FileWriter fw = new FileWriter(outputFile);
      PrintWriter pw = new PrintWriter(fw);

      uintahInputPanel.writeUintah(pw);

      pw.close();
      fw.close();

    } catch (Exception event) {
      System.out.println("Could not write to file " + outputFile.getName());
    }
  }
Exemplo n.º 21
0
  // **********************************************************************************
  //
  // Theoretically, you shouldn't have to alter anything below this point in this file
  //      unless you want to change the color of your agent
  //
  // **********************************************************************************
  public void getConnected(String args[]) {
    try {
      // initial connection
      int port = 3000 + Integer.parseInt(args[1]);
      s = new Socket(args[0], port);
      sout = new PrintWriter(s.getOutputStream(), true);
      sin = new BufferedReader(new InputStreamReader(s.getInputStream()));

      // read in the map of the world
      numNodes = Integer.parseInt(sin.readLine());
      int i, j;
      for (i = 0; i < numNodes; i++) {
        world[i] = new node();
        String[] buf = sin.readLine().split(" ");
        world[i].posx = Double.valueOf(buf[0]);
        world[i].posy = Double.valueOf(buf[1]);
        world[i].numLinks = Integer.parseInt(buf[2]);
        // System.out.println(world[i].posx + ", " + world[i].posy);
        for (j = 0; j < 4; j++) {
          if (j < world[i].numLinks) {
            world[i].links[j] = Integer.parseInt(buf[3 + j]);
            // System.out.println("Linked to: " + world[i].links[j]);
          } else world[i].links[j] = -1;
        }
      }
      currentNode = Integer.parseInt(sin.readLine());

      String myinfo =
          args[2] + "\n" + "0.7 0.45 0.45\n"; // name + rgb values; i think this is color is pink
      // send the agents name and color
      sout.println(myinfo);
    } catch (IOException e) {
      System.out.println(e);
    }
  }
Exemplo n.º 22
0
  /** Write file with position and size of the login box */
  public static void writePersistence() {

    Messages.postDebug("LoginBox", "LoginBox.writePersistence");
    // If the panel has not been created, don't try to write a file
    if (position == null) return;

    String filepath = FileUtil.savePath("USER/PERSISTENCE/LoginPanel");

    FileWriter fw;
    PrintWriter os;
    try {
      File file = new File(filepath);
      fw = new FileWriter(file);
      os = new PrintWriter(fw);
      os.println("Login Panel");

      os.println(height);
      os.println(width);
      double xd = position.getX();
      int xi = (int) xd;
      os.println(xi);
      double yd = position.getY();
      int yi = (int) yd;
      os.println(yi);

      os.close();
    } catch (Exception er) {
      Messages.postError("Problem creating  " + filepath);
      Messages.writeStackTrace(er);
    }
  }
Exemplo n.º 23
0
 public String getAlbumName() {
   if (albumName != null) {
     return albumName;
   }
   // from text file "pm_album_name.txt"
   if (homeBilder == null) {
     return "not-found";
   }
   // File Album-name nicht vorhanden
   if (albumName == null) {
     homeFileAlbumName = new File(getMetaRootDir() + File.separator + FILE_ALBUM_NAME);
     if (!homeFileAlbumName.exists()) {
       try {
         homeFileAlbumName.createNewFile();
         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(homeFileAlbumName)));
         out.println(homeBilder.getName());
         out.close();
         // read it now ...
       } catch (IOException e) {
         albumName = "cannot-create";
         return albumName;
       }
     }
     // File exist. Read it.
     try {
       BufferedReader in = new BufferedReader(new FileReader(homeFileAlbumName));
       while (true) {
         String line = in.readLine().trim();
         if (line.startsWith("#")) {
           continue;
         }
         albumName = line.trim();
         break;
       }
       in.close();
     } catch (IOException e) {
       albumName = "cannot-create";
       return albumName;
     }
   }
   return albumName;
 }
Exemplo n.º 24
0
  /**
   * Function: printXMLNode Pre: Takes a PrintWriter fout defining the file to send XML printing out
   * to and a boolean is_animation stating whether we are printing an animated node or simple a
   * graph-node MOOF - add boolean for jump vs slide here in the future Post: Prints out this node
   * to the file appropriately
   */
  public void printXMLNode(PrintWriter fout, boolean is_animation) {
    // First, check if the node is activated.
    // If not, hide the node (if shown) & leave for animations
    if (!activated)
      if (idExists && is_animation) // remove now-inactivated visibles!
      {
        fout.println("\t<removevertex id = \"" + cindex + "\" />");
        idExists = false;
      } else ;

    // Otherwise, if the ID already exists and it's an animation...
    else if (idExists && is_animation) {
      // If the position has changed, do a jump
      if (isChanged)
        fout.println("\t<jump id = \"" + cindex + "\" x = \"" + x + "\" y = \"" + y + "\" />");

      // If the color has changed, adjust the color
      if (isColorChanged)
        fout.println("\t<colorvertex id = \"" + cindex + "\" color = \"" + color + "\" />");
    }
    // Otherwise, the node doesn't exist and must be added
    else {
      // If this is an animation, we actually need to add the node if
      //   we get to this point
      if (is_animation) fout.print("\t<addvertex>\n\t");

      // No matter what, we need to define the vertex appropriately
      fout.print(
          "\t<vertex id = \""
              + cindex
              + "\" x = \""
              + x
              + "\" y = \""
              + y
              + "\" color = \""
              + color
              + "\" highlight = \"");
      if (highlighted) fout.println("true\" />");
      else fout.println("false\" />");

      // Make sure that idExists is true, the ID is certainly out there!
      idExists = true;

      // If this is an animation, we need to output the end-addvertex tag
      if (is_animation) fout.println("\t</addvertex>");
    } // End checking for changes only

    // Finally... we know these variables are accounted for now
    isChanged = false;
    isColorChanged = false;
  }
Exemplo n.º 25
0
  // You shouldn't need to modify this function
  public void act() {
    int a = selectAction();

    // visit the node if it has positive utility
    String buf;
    int destination = world[currentNode].links[a];
    if (currentUtilitiesforVisitingNodes[destination] > 0) buf = a + " Y\n";
    else buf = a + " N\n";

    System.out.print("Sent: " + buf);
    sout.println(buf);
  }
Exemplo n.º 26
0
 /**
  * *******************************************************************\ FILE IO METHODS *
  *
  * @param p * \********************************************************************
  */
 public void writeSite(PrintWriter p) {
   p.println(
       "SITE "
           + this.getIndex()
           + " : "
           + this.location
           + " : Initial State '"
           + initialState
           + "'");
   p.print("          ");
   this.getType().writeType(p);
   p.println(
       "          "
           + "x "
           + IOHelp.DF[3].format(getX())
           + " y "
           + IOHelp.DF[3].format(getY())
           + " z "
           + IOHelp.DF[3].format(getZ())
           + " ");
 }
Exemplo n.º 27
0
  /**
   * Perform the action of the plugin.
   *
   * @param document the current document.
   */
  public boolean perform(Document document) throws IOException {
    // Interact with the user to get the layer tag/

    Tag layerTag = getLayerTagFromUser(document);
    if (layerTag == null) return false; // User cancled.
    Tag endTag = new Tag(layerTag.getName(), false);
    // Get the output stream to hold the new document text.
    PrintWriter out = new PrintWriter(document.getOutput());
    // Create a lexical stream to tokenize the old document text.
    LexicalStream in = new LexicalStream(new SelectedHTMLReader(document.getInput(), out));
    for (; ; ) {
      // Get the next token of the document.
      Token token = in.next();
      if (token == null) break; //  Null means we've finished the document.
      else if (token instanceof Comment) {
        Comment comment = (Comment) token;
        if (comment.isSelectionStart()) {
          out.print(layerTag);
        } else if (comment.isSelectionEnd()) {
          out.print(comment);
          out.print(endTag);
          continue; // So comment isn't printed twice.
        }
      }
      out.print(token);
    }
    out.close();
    return true;
  }
Exemplo n.º 28
0
 /**
  * Writes the figures to the specified output stream.
  * This method applies the specified drawingTransform to the drawing, and draws
  * it on an image of the specified getChildCount.
  * 
  * All other write methods delegate their work to here.
  */
 public void write(OutputStream out, java.util.List<Figure> figures,
         AffineTransform drawingTransform, Dimension imageSize) throws IOException {
     
     this.drawingTransform = (drawingTransform == null) ? new AffineTransform() : drawingTransform;
     this.bounds = (imageSize == null) ? 
         new Rectangle(0,0,Integer.MAX_VALUE,Integer.MAX_VALUE) :
         new Rectangle(0, 0, imageSize.width, imageSize.height);
     
     XMLElement document = new XMLElement("map");
     
     // Note: Image map elements need to be written from front to back
     for (Figure f: new ReversedList<Figure>(figures)) {
         writeElement(document, f);
     }
     
     // Strip AREA elements with "nohref" attributes from the end of the
     // map
     if (! isIncludeNohref) {
         for (int i=document.getChildrenCount() - 1; i >= 0; i--) {
             XMLElement child = (XMLElement) document.getChildAtIndex(i);
             if (child.hasAttribute("nohref")) {
                 document.removeChildAtIndex(i);
             }
         }
     }
     
     
     // Write XML content
     PrintWriter writer = new PrintWriter(
             new OutputStreamWriter(out, "UTF-8")
             );
     //new XMLWriter(writer).write(document);
     for (Object o : document.getChildren()) {
         XMLElement child = (XMLElement) o;
         new XMLWriter(writer).write(child);
     }
     
     // Flush writer
     writer.flush();
 }
Exemplo n.º 29
0
  private void saveCurrent() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");

      for (String s : Main.getEmails()) {
        writer.println(s);
      }

      writer.println("Items:");

      for (Item s : Main.getItems()) {
        writer.println(s.getName() + "," + s.getWebsite());
      }

      results.setText("Current settings have been saved sucessfully.");
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
Exemplo n.º 30
-1
  private void saveItem() {

    File f = new File("config.txt");

    if (f.exists() && !f.isDirectory()) {

      try (PrintWriter out =
          new PrintWriter(new BufferedWriter(new FileWriter("config.txt", true)))) {
        if (!searchName.getText().equals("") && !item.getText().equals("")) {

          out.println(
              searchName.getText()
                  + ","
                  + "http://www.reddit.com/r/hardwareswap/search?q="
                  + item.getText()
                  + "&sort=new&restrict_sr=on");
          addItem();

        } else {

          results.setText("Please provide all info for Search Name and Item");
        }

      } catch (IOException e1) {
        results.append("Error saving to file.");
      }

    } else {
      Main.checkFiles();
    }
  }