예제 #1
0
  public BoardList() {
    URL url = null;
    HttpURLConnection http_url_connection = null;
    int response_code;
    String response_message;
    InputStreamReader in = null;
    BufferedReader reader = null;
    ParserDelegator pd = null;
    try {
      // httpでhtmlファイルを取得する一連の処理
      url = new URL("http://menu.2ch.net/bbsmenu.html");
      http_url_connection = (HttpURLConnection) url.openConnection();
      http_url_connection.setRequestMethod("GET");
      http_url_connection.setInstanceFollowRedirects(false);
      http_url_connection.setRequestProperty("User-Agent", "Monazilla/1.00");
      response_code = http_url_connection.getResponseCode();
      response_message = http_url_connection.getResponseMessage();
      in = new InputStreamReader(http_url_connection.getInputStream(), "SJIS");
      reader = new BufferedReader(in);

      pd = new ParserDelegator();
      pd.parse(reader, cb, true);
      in.close();
      reader.close();
      http_url_connection.disconnect();
    } catch (IOException e1) {
      e1.printStackTrace();
    }
  }
예제 #2
0
 // Put the text that the user typed into the pipe, so that
 // interested console clients can read the stuff from the in stream.
 private void acceptLine(String aLine) {
   try {
     fromConsoleStream.write(aLine.getBytes());
     fromConsoleStream.flush();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #3
0
 private Socket connectToPeer(String ip, int port) {
   try {
     Socket peer = new Socket(ip, port);
     return peer;
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
예제 #4
0
 public Class<?> findClass(String s) {
   try {
     byte[] bytes = loadClassData(s);
     return defineClass(s, bytes, 0, bytes.length);
   } catch (IOException ioe) {
     try {
       return super.loadClass(s);
     } catch (ClassNotFoundException ignore) {
     }
     ioe.printStackTrace(System.out);
     return null;
   }
 }
예제 #5
0
  public synchronized void runSuite() {
    SikuliIDE ide = SikuliIDE.getInstance();
    if (fRunner != null) {
      fTestResult.stop();
      showIDE(true);
    } else {
      try {
        showIDE(false);
        reset();

        // get the current file's python code, write it to a temp file, and run it
        File tmpFile = null;
        String className = null;
        SikuliCodePane codePane = ide.getCurrentCodePane();
        try {
          className = new File(ide.getCurrentFilename()).getName();
          className = className.substring(0, className.lastIndexOf('.')); // remove extension
          tmpFile = File.createTempFile(className, ".py");
          tmpFile.deleteOnExit();
          BufferedWriter bw =
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF8"));
          codePane.writePython(bw);
          bw.close();
        } catch (IOException e) {
          e.printStackTrace();
          showIDE(true);
        }
        String filename = tmpFile.getAbsolutePath();

        String path = ide.getCurrentBundlePath();
        Test suite = genTestSuite(className, filename, path);
        doRun(suite);
      } catch (IOException e) {
        e.printStackTrace();
        showIDE(true);
      }
    }
  }
예제 #6
0
  public JConsole() {
    super();

    setBackground(new Color(70, 70, 70));
    setForeground(Color.WHITE);
    text = new MyJTextPane();

    text.setAutoscrolls(true);
    final Font lFont = new Font("Monospaced", Font.PLAIN, 15);
    text.setText("");
    text.setFont(lFont);
    text.setMargin(new Insets(5, 3, 5, 3));
    text.addKeyListener(new MyKeyListener());
    setViewportView(text);

    contextMenu = new JPopupMenu();
    final ActionListener lActionListener = new MyActionListener();
    contextMenu.add(new JMenuItem(CMD_CUT)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_COPY)).addActionListener(lActionListener);
    contextMenu.add(new JMenuItem(CMD_PASTE)).addActionListener(lActionListener);
    text.addMouseListener(new MyMouseListener());

    MutableAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.BLACK);

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.WHITE);
    attrOut = attr;

    attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, Color.RED);
    StyleConstants.setItalic(attr, true);
    StyleConstants.setBold(attr, true);
    attrError = attr;

    try {
      fromConsoleStream = new PipedOutputStream();
      in = new PipedInputStream((PipedOutputStream) fromConsoleStream);

      final PipedOutputStream lOutPipe = new PipedOutputStream();
      out = new PrintStream(lOutPipe);

      final PipedOutputStream lErrPipe = new PipedOutputStream();
      err = new PrintStream(lErrPipe);

    } catch (IOException e) {
      e.printStackTrace();
    }
    requestFocus();
  }
예제 #7
0
    // Writes the program to a source file, compiles it, and runs it.
    private void compileAndRun(String fileName, String code) {
      // Exceptions here can pick and choose what font to use, as needed.
      // Exceptions thrown by the program, that cause the Playground to be unstable, should be in
      // blue.

      println("Deleting old temp files...", progErr);
      new File(fileName + ".java").delete();
      new File(fileName + ".class").delete();

      println("Creating source file...", progErr);
      file = new File(fileName + ".java");

      println("Writing code to source file...", progErr);
      try {
        new FileWriter(file).append(code).close();
      } catch (IOException i) {
        println("Had an IO Exception when trying to write the code. Stack trace:", error);
        i.printStackTrace();
        return; // Exit on error
      }

      println("Compiling code...", progErr);
      // This should only ever be called if the JDK isn't installed. How you'd get here, I don't
      // know.
      if (compiler == null) {
        println("Fatal Error: JDK not installed. Go to java.sun.com and install.", error);
        return;
      }

      // Tries to compile. Success code is 0, so if something goes wrong, do stuff.
      int result =
          compiler.run(
              null,
              null,
              null,
              file
                  .getAbsolutePath()); // Possibly add a new outputstream to parse through the
                                       // compiler errors
      if (result != 0) {
        displayLog();
        println("Failed to compile.", error);
        return; // Return on error
      }

      println("Code compiled with 0 errors.", progErr);

      println("Attempting to run code...", progErr);
      run(fileName);
    }
예제 #8
0
    public void run() {
      try {
        final byte[] lBuf = new byte[1024];
        int lBytesRead;

        while (in.read(lBuf, 0, 1) != -1) {
          synchronized (JConsole.this) {
            lBytesRead = in.read(lBuf, 1, 1023) + 1;
            print(new String(lBuf, 0, lBytesRead), attr);

            while (in.available() > 0) {
              lBytesRead = in.read(lBuf);
              print(new String(lBuf, 0, lBytesRead), attr);
            }
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
예제 #9
0
    // Creates a new thread, runs the program in that thread, and reports any errors as needed.
    private void run(String clazz) {
      try {
        // Makes sure the JVM resets if it's already running.
        if (JVMrunning) kill();

        // Some String constants for java path and OS-specific separators.
        String separator = System.getProperty("file.separator");
        String path = System.getProperty("java.home") + separator + "bin" + separator + "java";

        // Tries to run compiled code.
        ProcessBuilder builder = new ProcessBuilder(path, clazz);

        // Should be good now! Everything past this is on you. Don't mess it up.
        println(
            "Build succeeded on " + java.util.Calendar.getInstance().getTime().toString(), progErr);
        println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", progErr);

        JVM = builder.start();

        // Note that as of right now, there is no support for input. Only output.
        Reader errorReader = new InputStreamReader(JVM.getErrorStream());
        Reader outReader = new InputStreamReader(JVM.getInputStream());
        // Writer inReader = new OutputStreamWriter(JVM.getOutputStream());

        redirectErr = redirectIOStream(errorReader, err);
        redirectOut = redirectIOStream(outReader, out);
        // redirectIn = redirectIOStream(null, inReader);

      } catch (IOException e) {
        // JVM = builder.start() can throw this.
        println("IOException when running the JVM.", progErr);
        e.printStackTrace();
        displayLog();
        return;
      }
    }