Package java.io

Examples of java.io.PrintWriter


   */ 
  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
          Instances header = new Instances(structure,0);
          if(retrieveFile() == null || outW == null)
              System.out.println(header.toString());
          else{
              outW.print(header.toString());
              outW.print("\n");
              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(inst);
                m_incrementalCounter++;
                //flush every 100 instances
                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()).toString());
          setWriteMode(WAIT);
          return;
      }
     
      PrintWriter outW = new PrintWriter(getWriter());
      Instances data = getInstances();
     
      // header
      Instances header = new Instances(data, 0);
      outW.print(header.toString());
     
      // data
      for (int i = 0; i < data.numInstances(); i++) {
  if (i % 1000 == 0)
    outW.flush();
        outW.println(data.instance(i));
      }
      outW.flush();
      outW.close();
     
      setWriteMode(WAIT);
      outW = null;
      resetWriter();
      setWriteMode(CANCEL);
View Full Code Here

      writer = new StringWriter();
     
      // generate stacktrace
      t = new Throwable();
      t.fillInStackTrace();
      t.printStackTrace(new PrintWriter(writer));

      println(writer.toString());
    }
View Full Code Here

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
       
        FtpServer server = (FtpServer) getServletContext().getAttribute(FtpServerListener.FTPSERVER_CONTEXT_NAME);
       
        PrintWriter wr = resp.getWriter();
       
        wr.print("<html>");
        wr.print("<head>");
        wr.print("<title>FtpServer status servlet</title>");
        wr.print("</head>");
        wr.print("<body>");
        wr.print("<form method='post'>");


        if(server.isStopped()) {
            wr.print("<p>FtpServer is stopped.</p>");
        } else {
            if(server.isSuspended()) {
                wr.print("<p>FtpServer is suspended.</p>");
                wr.print("<p><input type='submit' name='resume' value='Resume'></p>");
                wr.print("<p><input type='submit' name='stop' value='Stop'></p>");
            } else {
                wr.print("<p>FtpServer is running.</p>");
                wr.print("<p><input type='submit' name='suspend' value='Suspend'></p>");
                wr.print("<p><input type='submit' name='stop' value='Stop'></p>");
            }
        }
       
        wr.print("</form>");
        wr.print("</body>");
        wr.print("</html>");
    }
View Full Code Here

        try {
            TraceSystem ts = new TraceSystem(null);
            FileLock lock = new FileLock(ts, "error.lock", 1000);
            lock.lock(FileLock.LOCK_FILE);
            FileWriter fw = new FileWriter("error.txt", true);
            PrintWriter pw = new PrintWriter(fw);
            e.printStackTrace(pw);
            pw.close();
            fw.close();
            lock.unlock();
        } catch (Throwable t) {
            t.printStackTrace();
        }
View Full Code Here

          interceptors.add((MessageInterceptor)Class.forName(interceptorClassName).newInstance());
        } catch(Throwable t) {
          if (logger.isLoggable(BasicLevel.WARN))
            logger.log(BasicLevel.WARN, "addInterceptors", t);
          StringWriter sw = new StringWriter();
          t.printStackTrace(new PrintWriter(sw));
          if (error == null)
            error = "(" + interceptorClassName + " exc=" + sw.toString() + ')';
          else
            error = error + "(" + interceptorClassName + " exc=" + sw.toString() + ')';
        }
View Full Code Here

          removeInterceptor(interceptorClassName, interceptors);
        } catch(Throwable t) {
          if (logger.isLoggable(BasicLevel.WARN))
            logger.log(BasicLevel.WARN, "removeInterceptors", t);
          StringWriter sw = new StringWriter();
          t.printStackTrace(new PrintWriter(sw));
          if (error == null)
            error = "(" + interceptorClassName + " exc=" + sw.toString() + ')';
          else
            error = error + "(" + interceptorClassName + " exc=" + sw.toString() + ')';
        }
View Full Code Here

        return replaced;
      } catch(Throwable t) {
        if (logger.isLoggable(BasicLevel.WARN))
          logger.log(BasicLevel.WARN, "replaceInterceptor", t);
        StringWriter sw = new StringWriter();
        t.printStackTrace(new PrintWriter(sw));
        throw new Exception("(" + newInterceptorClassName + " exc=" + sw.toString() + ')');
      }
    }
    return false;
  }
View Full Code Here

    byte[] bytecode = ctx.getGeneratedBytecode();
   
    if (log.isLogging(LoggerLevelStandard.DEBUG)) {
      ClassReader cr = new ClassReader(bytecode);
      ASMifierClassVisitor asm = new ASMifierClassVisitor(
        new PrintWriter(log.getLoggingWriter(LoggerLevelStandard.DEBUG), true) // log.getLoggingWriter(LoggerLevelStandard.INFO), true)
      );
      cr.accept(asm, 0);
    }
   
    return loader.define(type.getName(), bytecode);
View Full Code Here

      throw new IllegalStateException(
          "getOutputStream() has already been called!");
    }

    stream = createOutputStream();
    writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
    return (writer);
  }
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.