Beispiel #1
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   Socket socket = null;
   try {
     socket = new Socket(SERVER, PORT);
     socket.setSoTimeout(TIMEOUT);
     OutputStream out = socket.getOutputStream();
     Writer writer = new OutputStreamWriter(out, "UTF-8");
     writer = new BufferedWriter(writer);
     InputStream in = socket.getInputStream();
     BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
     for (String word : args) define(word, writer, reader);
     writer.write("quit\r\n");
     writer.flush();
   } catch (IOException e) {
     // TODO: handle exception
     System.err.println(e);
   } finally {
     if (socket != null) {
       try {
         socket.close();
       } catch (IOException e2) {
         // TODO: handle exception
       }
     }
   }
 }
 public void writeTo(final Writer writer) throws IOException {
   this.writer = writer;
   if (segment instanceof Source) ((Source) segment).fullSequentialParse();
   nextTag = segment.source.findNextTag(segment.begin);
   index = segment.begin;
   writeContent(segment.end, segment.getChildElements(), 0);
   writer.flush();
 }
Beispiel #3
0
    @Override
    @SuppressWarnings("SleepWhileHoldingLock")
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum(doc.getLength());
        status.add(progress);
        status.revalidate();

        // start writing
        Writer out = new FileWriter(f);
        Segment text = new Segment();
        text.setPartialReturn(true);
        int charsLeft = doc.getLength();
        int offset = 0;
        while (charsLeft > 0) {
          doc.getText(offset, Math.min(4096, charsLeft), text);
          out.write(text.array, text.offset, text.count);
          charsLeft -= text.count;
          offset += text.count;
          progress.setValue(offset);
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e);
          }
        }
        out.flush();
        out.close();
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not save file: " + msg,
                    "Error saving file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();
    }
Beispiel #4
0
 static void define(String word, Writer writer, BufferedReader reader)
     throws IOException, UnsupportedEncodingException {
   writer.write("DEFINE fd-eng-lat " + word + "\r\n");
   writer.flush();
   for (String line = reader.readLine(); line != null; line = reader.readLine()) {
     if (line.startsWith("250 ")) return;
     else if (line.startsWith("552")) {
       System.out.println("no definition found for " + word);
       return;
     } else if (line.matches("\\d\\d\\d .*")) continue;
     else if (line.trim().equals(".")) continue;
     else System.out.println(line);
   }
 }