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.");
      }
    }
Exemple #2
1
  public void runImpl() throws Exception {
    // create the URL corresponding to the date

    URL u = new URL(ADDRESS_ + dateFormatter1_.format(date));
    Messages.debug(3, "Rag::runImpl - reading data from URL=%1", u);
    // fetch the page into the buffer
    buffer_ = new char[BUF_SIZE_];
    Reader r = new InputStreamReader(u.openStream());
    int size = 1;
    charsread_ = 0;
    while (charsread_ < BUF_SIZE_ && size > 0) {
      size = r.read(buffer_, 0, BUF_SIZE_ - charsread_);
      if (size != -1) charsread_ += size;
      // Messages.debug(3, "Rag::runImpl - read %1 chars", String.valueOf(size));
      if (!r.ready()) break;
    }
    r.close();
    // Messages.debug(3, "Rag::runImpl - buffer=\"%1\"XXXXXXX", new String(buffer_, 0, charsread_));
    // create the results
    createResults_();
  }
Exemple #3
0
  public int read(char[] theChars, int offset, int length) throws IOException {
    if (log.isDebugEnabled()) {
      log.debug("read called: offset = " + offset + ", length = " + length);
    }
    if (first) {
      if (log.isDebugEnabled()) {
        log.debug(header);
      }
      first = false;
      for (int i = 0; i < header.length(); i++) {
        theChars[i] = header.charAt(i);
      }
      return header.length();
    } else {
      if (last) return -1;

      int cnt = internal.read(theChars, offset, length);
      if (log.isDebugEnabled()) {
        log.debug(theChars);
      }
      if (cnt == -1) {
        for (int i = offset; i < footer.length() + offset; i++) {
          theChars[i] = footer.charAt(i - offset);
        }
        cnt = footer.length();
        last = true;
      }

      return cnt;
    }
  }
Exemple #4
0
 private static void printFromStream(InputStream raw) throws IOException {
   try (InputStream buffer = new BufferedInputStream(raw)) {
     Reader reader = new InputStreamReader(buffer);
     int c;
     while ((c = reader.read()) != -1) {
       System.out.print((char) c);
     }
   }
 }
Exemple #5
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());
              }
            });
      }
    }
Exemple #6
0
  @Override
  public void render(Parameters blockParameters, Writer w, RenderHints hints)
      throws FrameworkException {

    if (decorate) {
      try {
        decorateIntro(hints, w, null);
      } catch (IOException ioe) {
        throw new FrameworkException(ioe);
      }
    }
    String name = getResource();
    ResourceLoader loader = ResourceLoader.Type.valueOf(resourceType.toUpperCase()).get();
    try {
      InputStream is = loader.getResourceAsStream(name);
      if (is == null)
        throw new FrameworkException(
            "No such resource " + loader.getResource(name) + " in " + loader);
      if (xsl == null) {
        Reader r = loader.getReader(is, name);
        char[] buf = new char[1000];
        int c;
        while ((c = r.read(buf, 0, 1000)) > 0) {
          w.write(buf, 0, c);
        }
      } else {
        /// convert using the xsl and spit out that.
        URL x = ResourceLoader.getConfigurationRoot().getResource(xsl);
        Utils.xslTransform(blockParameters, loader.getResource(name), is, w, x);
      }
    } catch (IOException ioe) {
      throw new FrameworkException(ioe);
    } catch (javax.xml.transform.TransformerException te) {
      throw new FrameworkException(te.getMessage(), te);
    } catch (RuntimeException e) {
      log.debug(e.getMessage(), e);
      throw e;
    } finally {
      if (decorate) {
        try {
          decorateOutro(hints, w);
        } catch (IOException ioe) {
          throw new FrameworkException(ioe);
        }
      }
    }
  }
 public static void copyStream(Reader reader, Writer writer) throws IOException {
   int count;
   char[] buffer = new char[1024];
   while ((count = reader.read(buffer)) > 0) writer.write(buffer, 0, count);
 }