Package java.io

Examples of java.io.PrintWriter


    if (AgentServer.getTransaction() instanceof fr.dyade.aaa.util.NullTransaction) {
      // TODO (AF): NullTransaction is not significant.
      String cfgDir = System.getProperty(AgentServer.CFG_DIR_PROPERTY, AgentServer.DEFAULT_CFG_DIR);
      String cfgFile = System.getProperty(AgentServer.CFG_FILE_PROPERTY, AgentServer.DEFAULT_CFG_FILE);
      FileOutputStream fos = new FileOutputStream(new File(cfgDir, cfgFile));
      PrintWriter out = new PrintWriter(fos);
      A3CML.toXML(a3cmlConfig, out);
      out.flush();
      fos.flush();
      fos.getFD().sync();
      out.close();
      fos.close();
    } else {
      a3cmlConfig.save();
    }
  }
View Full Code Here


  /**
   * ���HSQLEngine��״̬��Ϣ
   */
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    PrintWriter out = res.getWriter();
    if(engine==null)
      out.println("HSQLDB Engine initialize failed.");
    else
    if(engine.isRunning())
      out.println("HSQLDB Engine is running...");
    else
      out.println("HSQLDB Engine is stopped.");
  }
View Full Code Here

    // okay, parse the HTML code
    ByteArrayInputStream bis = new ByteArrayInputStream(input.getContent());
    Tidy tidy = new Tidy();
    tidy.setUpperCaseTags(false);
    tidy.setUpperCaseAttrs(false);
    tidy.setErrout(new PrintWriter(new NullWriter()));

    Document doc = tidy.parseDOM(bis,null);

    rewriteDOM(doc,input.getURL());
View Full Code Here

   * string and returns it.
   */
  public String stackTrace( Throwable throwable )
  {
    StringWriter sw   = new StringWriter() ;
    PrintWriter pw    = new PrintWriter( sw ) ;
    throwable.printStackTrace( pw ) ;
    pw.close() ;
    return sw.toString() ;
  } // stackTrace()
View Full Code Here

        if (t == null)
            return null;
        else if (t instanceof ScriptingException)
            return ((ScriptingException) t).getJavaStackTrace();
        StringWriter w = new StringWriter();
        t.printStackTrace(new PrintWriter(w));
        return w.toString();
    }
View Full Code Here

        // get garbage collected.
        try{
           if (file.exists()) {
               readerWriter = new BufferedReader(new FileReader(file));
           } else {
               readerWriter = new PrintWriter(new FileWriter(file));
           }
           return true;
       } catch (IOException e) {
           setError(e);
           return false;
View Full Code Here

        }
        if (! (readerWriter instanceof PrintWriter)) {
            setError(new IllegalStateException("File not opened for writing"));
            return false;
        }
        PrintWriter writer = (PrintWriter) readerWriter;
        if (what != null) {
            writer.print(what.toString());
        }
        // writer.println();
        return true;
    }
View Full Code Here

        }
        if (! (readerWriter instanceof PrintWriter)) {
            setError(new IllegalStateException("File not opened for writing"));
            return false;
        }
        PrintWriter writer = (PrintWriter) readerWriter;
        if (what != null) {
            writer.print(what.toString());
        }
        writer.println();
        return true;
    }
View Full Code Here

   */ 
  public void writeIncremental(Instance inst) throws IOException{
 
      int writeMode = getWriteMode();
      Instances structure = getInstances();
      PrintWriter outW = null;
     
      if(getRetrieval() == BATCH || getRetrieval() == NONE)
          throw new IOException("Batch and incremental saving cannot be mixed.");
      if(getWriter() != null)
          outW = new PrintWriter(getWriter());
         
      if(writeMode == WAIT){
        if(structure == null){
            setWriteMode(CANCEL);
            if(inst != null)
                System.err.println("Structure(Header Information) has to be set in advance");
        }
        else
            setWriteMode(STRUCTURE_READY);
        writeMode = getWriteMode();
      }
      if(writeMode == CANCEL){
          if(outW != null)
              outW.close();
          cancel();
      }
      if(writeMode == STRUCTURE_READY){
          setWriteMode(WRITE);
          //write header
          if(retrieveFile() == null || outW == null){
              // print out attribute names as first row
              for (int i = 0; i < structure.numAttributes(); i++) {
                System.out.print(structure.attribute(i).name());
                if (i < structure.numAttributes()-1) {
                    System.out.print(m_FieldSeparator);
                } else {
                    System.out.println();
                }
              }
          }
          else{
              for (int i = 0; i < structure.numAttributes(); i++) {
                outW.print(structure.attribute(i).name());
                if (i < structure.numAttributes()-1) {
                    outW.print(m_FieldSeparator);
                } else {
                    outW.println();
                }
              }
              outW.flush();
          }
          writeMode = getWriteMode();
      }
      if(writeMode == WRITE){
          if(structure == null)
              throw new IOException("No instances information available.");
          if(inst != null){
          //write instance
              if(retrieveFile() == null || outW == null)
                System.out.println(inst);
              else{
                outW.println(instanceToString(inst));
                //flushes every 100 instances
                m_incrementalCounter++;
                if(m_incrementalCounter > 100){
                    m_incrementalCounter = 0;
                    outW.flush();
                }
              }
          }
          else{
          //close
              if(outW != null){
                outW.flush();
                outW.close();
              }
              m_incrementalCounter = 0;
              resetStructure();
              outW = null;
              resetWriter();
View Full Code Here

            System.out.println(getInstances().instance(i));
        }
        setWriteMode(WAIT);
        return;
      }
      PrintWriter outW = new PrintWriter(getWriter());
      // print out attribute names as first row
      for (int i = 0; i < getInstances().numAttributes(); i++) {
  outW.print(getInstances().attribute(i).name());
  if (i < getInstances().numAttributes()-1) {
    outW.print(m_FieldSeparator);
  } else {
    outW.println();
  }
      }
      for (int i = 0; i < getInstances().numInstances(); i++) {
  outW.println(instanceToString((getInstances().instance(i))));
      }
      outW.flush();
      outW.close();
      setWriteMode(WAIT);
      outW = null;
      resetWriter();
      setWriteMode(CANCEL);
  }
View Full Code Here

TOP

Related Classes of java.io.PrintWriter

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.