Пример #1
1
    public void run() {
      try {
        // An arbitrary buffer size.
        char[] chbuf = new char[4096];

        while (keepRunning) {
          int numchars = reader.read(chbuf);
          if (numchars == -1) {
            keepRunning = false;
          } else if (keepRunning) {
            writer.write(chbuf, 0, numchars);
            if (!reader.ready()) {
              writer.flush();
            }
          }
        }
      } catch (IOException ex) {
        println("Error when linking JVM output to terminal window input.");
      }
    }
Пример #2
1
 private String getStringFromStreamSource(StreamSource src, int length) throws Exception {
   byte buf[] = null;
   if (src == null) return null;
   InputStream outStr = src.getInputStream();
   if (outStr != null) {
     int len = outStr.available();
     if (outStr.markSupported()) outStr.reset();
     buf = new byte[len];
     outStr.read(buf, 0, len);
     // System.out.println("From inputstream: "+new String(buf));
     return new String(buf);
   } else {
     char buf1[] = new char[length];
     Reader r = src.getReader();
     if (r == null) return null;
     r.reset();
     r.read(buf1);
     // System.out.println("From Reader: "+new String(buf));
     return new String(buf1);
   }
 }
Пример #3
0
    @Override
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not open file: " + msg,
                    "Error opening file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      doc.addUndoableEditListener(undoHandler);
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();

      resetUndoManager();

      if (elementTreePanel != null) {
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                elementTreePanel.setEditor(getEditor());
              }
            });
      }
    }
Пример #4
0
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f2.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f2);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc2.insertString(doc2.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }

        // we are done... get rid of progressbar
        // doc2.addUndoableEditListener(undoHandler);
        status.removeAll();
        status.revalidate();

        // resetUndoManager();
      } catch (IOException e) {
        System.err.println("TextViewer:FileLoader " + e.toString());
      } catch (BadLocationException e) {
        System.err.println("TextViewer:FileLoader " + e.getMessage());
      }
      /* aa
         if (elementTreePanel != null) {
         SwingUtilities.invokeLater(new Runnable() {
         public void run() {
         elementTreePanel.setEditor(getEditor());
         }
         });
         }
      */
    }
Пример #5
0
  private StringBuffer getDataFromReader(Reader br) {
    StringBuffer xferData = null;
    char[] buf = new char[513];
    int charsRead;

    try {
      do {
        charsRead = br.read(buf, 0, 512);
        if (charsRead != -1) {
          JConfig.log().logVerboseDebug("Read: " + charsRead + " characters.");
          if (xferData == null) {
            xferData = new StringBuffer();
          }
          xferData.append(buf, 0, charsRead);
        }
      } while (charsRead != -1);
      br.close();
    } catch (IOException e) {
      JConfig.log().logDebug("Caught an IO Exception trying to read the drag/drop data!");
      return null;
    }

    return xferData;
  }