Pausing the output stream?

Ahh! Sorry bout that... stupid friend.
Anyway. I have a question. Is there a way to pause the output in a series of System.out.println commands?
Like I'm making a game with a friend and its all text based using the java console and... It would be very confusing if all this text popped up at once!
Something like...
System.out.println("Hello!")
//pauses
System.out.println("Nice to meet you!")
or perhaps a way to wait for the user to press a key to continue. That would actually be better :3
I tried searching in the java api but got lost XD. I'm new to java. thanks for reading and helping me if you can.
Edited by: Xanotros on Aug 2, 2008 11:46 AM

if you want to wait for user input you can use a method like this to pring to the console:
String printAndWait(String output) {
     System.out.println(output);
     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     try {
          return in.readLine();
     catch (Exception e) {
          return null;
}you can also try to get the current running thread and make it go to sleep, but i dont think that its a good idea.

Similar Messages

  • Error flushing the output stream in Sun One server

    Hi All,
    I was running my servlet code in iPlanet 6.0 version and it was working fine. I upgraded my web server to new Sun One server (Oracle-iPlanet-Web-Server-7.0.9). With the new web server almost 90% of my application works fine, but there is a features in my application to download an Excel sheet by clicking a button. This feature is failing in new Sun One web server.
    Below are my piece of code and the error log I m getting. Can anyone tell me how I can fix this error, I mean is there any web server specific change or configuration parameter need to be set.
    Please ask for any information regarding my server configuration settings if needed for finding a solution for this
    Code:
    byte abyte0[] = new byte[1024];
    BufferedInputStream bufferedinputstream=null;
    BufferedOutputStream bufferedoutputstream=null;
    java.io.InputStream inputstream = httpurlconnection.getInputStream();
    bufferedinputstream = new BufferedInputStream(inputstream);
    bufferedoutputstream = new BufferedOutputStream(httpservletresponse.getOutputStream());
    int j;
    long byteCount=0;
    while((j = bufferedinputstream.read(abyte0, 0, 1024)) != -1)
    byteCount=byteCount+j;
    if(logger != null && logger.traceOn())
    logger.log("total"+byteCount);
    logger.log("Read bytes:"+j);
    bufferedoutputstream.write(abyte0, 0, j);
    if(logger != null && logger.traceOn())
    logger.log("Wrote bytes:"+j);
    bufferedoutputstream.flush(); // <<<<<< ERROR POINT >>>>>>
    Error Log :
    ClientAbortException: java.io.IOException: WEB8004: Error flushing the output stream
    at org.apache.coyote.tomcat5.OutputBuffer.doFlush(OutputBuffer.java:343)
    at org.apache.coyote.tomcat5.OutputBuffer.flush(OutputBuffer.java:313)
    at org.apache.coyote.tomcat5.CoyoteOutputStream.flush(CoyoteOutputStream.java:147)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
    at com.reuters.bdec.as.ASRequestHandler.processResponse(ASRequestHandler.java:285)
    at com.reuters.bdec.as.ASRequestHandler.initiateGetRequest(ASRequestHandler.java:89)
    at com.reuters.bdec.as.ASRequestHandler.proceedToDestination(ASRequestHandler.java:220)
    at com.reuters.bdec.as.ASExtension.authorisationCheck(ASExtension.java:84)
    at com.reuters.bdec.as.ASExtension.doGet(ASExtension.java:114)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:794)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:915)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:398)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:255)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
    at com.sun.webserver.connector.nsapi.NSAPIProcessor.service(NSAPIProcessor.java:160)
    Caused by: java.io.IOException: WEB8004: Error flushing the output stream
    at com.sun.webserver.connector.nsapi.NSAPIProcessor.action(NSAPIProcessor.java:243)
    at org.apache.coyote.Response.action(Response.java:197)
    at org.apache.coyote.tomcat5.OutputBuffer.doFlush(OutputBuffer.java:339)
    ... 20 more

    Don't flush it yourself. The servlet container will automatically flush for you once its send buffer is full. You can change the size of the send buffer though.

  • Exception writing binary data to the output stream to client -Broken pipe

    Hi,
    I am trying to use the drag & drop feature using Contributor mode of Webcenter sites. Single Image Page Attribute is working properly where as Multiple Image Page Attribute throws the following error:
    [ERROR] [.kernel.Default (self-tuning)'] [logging.cs.satellite.request] Exception writing binary data to the output stream to client 10.191.117.106
    java.net.SocketException: Broken pipe
         at java.net.SocketOutputStream.socketWrite0(Native Method)
         at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
         at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
         at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:568)
         at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:539)
         at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:427)
         at weblogic.servlet.internal.ChunkOutput$2.checkForFlush(ChunkOutput.java:648)
         at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:333)
         at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:148)
         at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:148)
         at COM.FutureTense.Servlet.ServletRequest$OutputOutputStream.write(ServletRequest.java:80)
         at COM.FutureTense.Servlet.ServletRequest.write(ServletRequest.java:1633)
         at com.openmarket.Satellite.RequestContext.write(RequestContext.java:1123)
         at com.openmarket.Satellite.BytePiece.stream(DataPiece.java:253)
         at com.openmarket.Satellite.CacheObjectImpl.stream(CacheObjectImpl.java:651)
         at com.openmarket.Satellite.Http11Responder.respondForWrapper(Http11Responder.java:142)
         at com.openmarket.Satellite.WrapperAwareResponder.respond(WrapperAwareResponder.java:36)
         at com.openmarket.Satellite.SatelliteServer.execute(SatelliteServer.java:85)
         at com.openmarket.Satellite.servlet.BaseServlet.doGet(BaseServlet.java:118)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at com.fatwire.wem.sso.cas.filter.CASFilter.doFilter(CASFilter.java:557)
         at com.fatwire.wem.sso.SSOFilter.doFilter(SSOFilter.java:51)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
    Thanks
    KarthiK

    Thank u very much,
         FileOutputStream opGif = new FileOutputStream(destFile, false);
    I have changed above line with the following line:
         PrintWriter opGif = new PrintWriter ( new FileWriter(destFile, false));
    and now this code is working very fine.
    Thanks once again...

  • Compress the output stream..

    Hello every body..
    I have aproject that use the java applet to transmit a vedio and audio over the internet network to do a video conference application with other applet at another computer at the network..
    I want to support the application so that the user that enter the conference can select the bandwidth of the internet he/she use and then accordin to choice i control the quality of the stream transmitted..
    So i want any one can help me with any way can be used to reduce the quality( or resolution) of the output stream so the user can be comfortable with the output..
    please any one can help me reply to me as fast as can..
    I there is no method can be used also reply and say this..
    Thanks...

    Hi,
    For audio use GSM codec. It just takes 12kbps of your bandwidth.
    For video, if you need "ok" quality with low bandwidth, use H.263 codec and for good quality, but higher bandwidth use JPEG codec. below are complete functions on how to reduce qualities for both codecs (or at least try to). But before you have to create a video Processor (see AVTransmit3.java and AVReceive3.java examples on the net).
    private void setReducedJPEGQuality(Processor videoProcessor) {
       Control cs[] = videoProcessor.getControls();
       QualityControl qc = null;
       VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
       // Loop through the controls to find the Quality control for
       // the JPEG encoder.
       for (int i = 0; i < cs.length; i++) {
          if (cs[i] instanceof QualityControl && cs[i] instanceof Owned) {
             Object owner = ((Owned)cs).getOwner();
    // Check to see if the owner is a Codec.
    // Then check for the output format.
    if (owner instanceof Codec) {
    Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
    for (int j = 0; j < fmts.length; j++) {                    
    if (fmts[j].matches(jpegFmt)) {               
    qc = (QualityControl)cs[i];          
    qc.setQuality(0.5f);               
    break;
    if (qc != null) {
    break;
    This will reduce your JPEG bandwith to an average of 150kbps, with still a good quality.
               private void setReducedH263Quality(Processor videoProcessor) {
             Control cs[] = videoProcessor.getControls();
              QualityControl qc = null;
              BitRateControl brc = null;
              FrameRateControl frc = null;
              boolean done = false;
              //try with bit rate first
              for (int i = 0; i < cs.length; i++) {
                  if(cs[i] instanceof Owned) {
                      if(cs[i] instanceof BitRateControl) {
                           brc = (BitRateControl)cs;
                   if(brc.getBitRate()>0) {
                        brc.setBitRate(30000);               done = true;
                   brc = null;
              if(done) {
                   return ;
              //then look for quality control
              for (int i = 0; i < cs.length; i++) {
              if(cs[i] instanceof Owned) {
              if(cs[i] instanceof QualityControl) {
                   qc = (QualityControl)cs[i];
                   if(qc.getQuality()>0.0f) {
                        qc.setQuality(0.5f);
                        done = true;
                   qc = null;
              if(done) {
                   return ;
              //if that did not work, try setting frame rate
              for (int i = 0; i < cs.length; i++) {
              if(cs[i] instanceof Owned) {
              if(cs[i] instanceof FrameRateControl) {
                   frc = (FrameRateControl)cs[i];
                   frc.setFrameRate(6.0f);
                   frc = null;
    This will reduce your H.263 codec's bit rate to 80kbps. You cannot set less than that. I tried with many webcams and that's the least I could go.
    Good luck.

  • Challenge: Controlling the output stream of includes within iterative tags

    Problem:
    How can you control the output stream of an iterative tag that is making an include on each iteration (either by using the jsp include tag or by a custom tag that does an pageContext.include(). Example of the first of such a case could be:
    <wf:iterator name="...">
    <div>
    <jsp:include page="test.jsp" flush="true"/>
    </div>
    <wf:iterator>
    I now want to see the following output:
    <div>
    ..content of jsp file 1
    </div>
    <div>
    ...content of jsp file 2
    </div>
    etc....
    However what I AM seeing is that the jsp content is flushed to the output stream before the divs like this:
    ...content of jsp file 1
    ...content of jsp file 2
    <div>
    </div>
    <div>
    </div>
    See!? How is that and what can I do to control the output stream??
    Thanks
    Alf Johannessen
    Ariol

    This is a stab in the dark, but have you tried writing your div tags out using the JSP directive:
    out.println("<div>");
    or
    <%="<div>"%>
    It looks like a bug in the iterator. I'd suggest you try setting flush to be false, but I know that's not supported yet (unless you've updated your libraries) ...

  • Getting the Output Stream of  a Process without exec()ing it first.

    Hi there,
    I am writing a java application which needs to open another application "gnuplot". Now my operating system is windows and I open pgnuplot .
    Also I want to send input to the above gnuplot (say plot sin(x) ) via the outputStream. The following is what I do :-
         String gnuplot_cmd = "plot sin(x)\n" ;
              Process p = Runtime.getRuntime().exec("C:/gnuplot/gnuplot4/bin/pgnuplot.exe");
              PrintWriter gp = new PrintWriter(p.getOutputStream());
              gp.print(gnuplot_cmd);
              gp.close();
    But the above doesn't work fully , in that only the blank wgnuplot terminal window pops up however I am unable to direct input to the gnuplot application.
    The reason being that , pgnuplot checks for
    its stdin being redirected the moment it's started. If, at that time,
    the "PrintWriter" is not yet connected to the OutputStream of the
    process, that check will fail, and pgnuplot will revert to just executing
    wgnuplot, without any command line redirection.
    I am facing a problem of how to attach a OutputStream to the process, without getting exec()ing the process.
    Is there anyway at all, i can get a process without starting it, so that I can attach an output Stream to it before it gets executed?
    I am open to work arounds, anything that will automate the process of writing to the gnuplot terminal.
    thanks!
    nandita.

    The reason being that , pgnuplot checks for
    its stdin being redirected the moment it's started.
    If, at that time,
    the "PrintWriter" is not yet connected to the
    OutputStream of the
    process, that check will fail, and pgnuplot will
    revert to just executing
    wgnuplot, without any command line redirection. I'm not convinced this analysis is correct. gnuplot doesn't need to know that there's a PrintWriter there, and it probably can't know. It just needs to know whether its standard input is coming from console or not. The Java library code that can invoke processes probably handles the redirect right away, and that's why there's the OutputStream available even before you create the PrintWriter.
    exec can be tricky. I think the problem may be that you're not dealing with standard output or standard error. Read this:
    When Runtime Exec Won't
    If that still doesn't help, there may be options to gnuplot to tell it exactly where its input is coming from.

  • WEB8004: Error flushing the output stream

    This error has been posted many time in this forum but so far no positive reply.
    My application uses Java 1.5 and iPlanet SUN Web Server 6.1
    When user make multiple click on any request page this error occurs. Based on my investigation I got this exception occured when server response does not able to find its request page.
    Could any one have some idea how to supress this error? Or is it bug in iPlanet 6.1?
    Any help is appreciated.
    Thanks,
    Jude

    The problem has been resolved by removing flush=true from all the JSP pages

  • Not able to flush the data output stream in n/w prg.

    Hi,
    I am trying to send and receive the data using TCP/IP channel using socket programming.
    Following is the server side code I have
    Socket socket = server_socket.accept();
    OutputStream output = socket.getOutputStream();
    BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String inputMessage = (String) input.readLine();
    System.out.println(inputMessage);
    output.write("Message from server");
    output.flush();I am able to receive the message from the client and as per the code the message is getting printed in the console. But I am unable to send the message back to the Client inspite of flushing the output stream.
    I am sure that the problem is because of the flush method which is not acutally flushing the data. If I use the "println" method instead of the write & flush method, everything seems to be working fine. I do not want to use the "println" method because I get an extra new line character in the msg I send to the Client.
    Any help on this is appreciated!

    No. I am not using BufferedReader to listen for the server response. Given below is my client side code.
    Socket socket = new Socket(<ip>, <port>);
    InputStream input = socket.getInputStream();
    PrintWriter output = new PrintWriter(socket.getOutputStream(),true);
    output.println("Request from the client");
    System.out.println("Waiting for the server response...");
    byte buffer[] = new byte[2000];
    input.read(buffer);
    System.out.println(new String(byte));I am not receiving the message from server, it hangs on "Waiting for the server response..".

  • Oracle BLOB Writes the Bytes Twice to Output Stream

    Hi,
    I have a very strange problem when working with oracle.sql.BLOB; I cannot figure out what it's causing my BLOB stream output to double the amount of data inserted into the Oracle database. I have a table that contains two BLOB objects(image files) and the goal is to insert two images into each row by BLOB stream.
    For example, if the image_bin size is 800k and image_thumbnail size is 100k, this code actually writes 1600k (double) and 200k (double) the amount of bytes to each BLOB column, respectively. The print method in insertBlob() indicates a correct number of bytes being written to the output stream (800k and 100k).
    I know for the fact the retrieval method (not mentioned here) doesn't duplicate the bytes when it's read because I have written another test program that does not utilize oracle.sql.BLOB but instead uses PreparedStatement's setBinaryStream(index, InputStream, size_of_file) and it accurately writes the exact image size (no double sizing) to the database -- but not with BLOB. Here's a snippet of my code, note that the actual writing occurs in insertBlob():
    private void insertBlob(java.sql.Blob lobImage, String imgName)
    throws SQLException, IOException {
    File imgFile = null;
    FileInputStream imgOnDisk = null;
    OutputStream imgToDB = null;
    int bufferSize = 0;
    oracle.sql.BLOB blobImage = (oracle.sql.BLOB) lobImage;
    try {
    int bytesRead = 0;
    long bytesWritten = 0L;
    byte[] byteBuffer = null;
    bufferSize = blobImage.getBufferSize();
    byteBuffer = new byte[bufferSize];
    imgFile = new File(imgName);
    // Stream to read the file from the local disk
    imgOnDisk = new FileInputStream(imgFile);
    // Stream to write to the Oracle database
    imgToDB = blobImage.setBinaryStream(imgFile.length());
    // Read from the disk file and write to the database
    while ((bytesRead = imgOnDisk.read(byteBuffer)) != -1 ) {
    imgToDB.write(byteBuffer, 0, bytesRead);
    bytesWritten += bytesRead;
    } // end of while
    System.out.print("Done. " + bytesWritten + "-bytes inserted, buffer size: " +
    bufferSize + "-bytes, chunk size: " +
    blobImage.getChunkSize() + ".\n");
    } catch (SQLException sqlEx) {
    System.out.println("SQLException caught: JDBCOracleLOBBinaryStream.processBlob()");
    connRollback();
    throw sqlEx;
    } catch (IOException ioe) {
    System.out.println("IOException caught: JDBCOracleLOBBinaryStream.processBlob()");
    throw ioe;
    } finally {
    try {
    if (imgOnDisk != null ) {
    imgOnDisk.close();
    if (imgToDB != null ) {
    imgToDB.close();
    } catch (IOException ioeClosing) {
    System.out.println("IOException caught: JDBCOracleLOBBinaryStream.processBlob() " +
    "on closing stream.");
    ioeClosing.printStackTrace();
    } // end of finally
    public void insertImageIntoOracleDB() throws SQLException, IOException {
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rset = null;
    try {
    this.getConnection(_driver, host, port, database, user, _pass);
    pstmt = conn.prepareStatement("INSERT INTO " +
    " gallery_v (picture_id, picture_title, image_bin, image_thumbnail) " +
    " VALUES (?, ?, EMPTY_BLOB(), EMPTY_BLOB())");
    pstmt.setInt(1, picID);
    pstmt.setString(2, picTitle);
    pstmt.executeUpdate();
    stmt = conn.createStatement();
    rset = stmt.executeQuery("SELECT image_bin, image_thumbnail FROM gallery_v " +
    " WHERE picture_id = " + picID + " FOR UPDATE");
    int rsetCount = 0;
    oracle.sql.BLOB imgBlob = null;
    oracle.sql.BLOB imgThumbBlob = null;
    while (rset.next()) {
    imgBlob = ((OracleResultSet) rset).getBLOB("image_bin");
    System.out.print("Inserting " + img + "... ");
    insertBlob(imgBlob, img);
    imgThumbBlob = ((OracleResultSet) rset).getBLOB("image_thumbnail");
    System.out.print("Inserting " + imgThumb + "... ");
    insertBlob(imgThumbBlob, imgThumb);
    rsetCount++;
    System.out.println("\nNumber of rows updated: " + rsetCount);
    conn.commit();
    } catch (SQLException sqlEx) {
    System.out.println("SQLException caught: JDBCOracleLOBBinaryStream.insertImageIntoOracleDB()");
    connRollback();
    throw sqlEx;
    } catch (IOException ioe) {
    throw ioe;
    } finally {
    try {
    if (rset != null) {
    rset.close();
    if (pstmt != null) {
    pstmt.close();
    if (stmt != null) {
    stmt.close();
    closeConnection();
    } catch (SQLException closingSqlEx) {
    System.out.println("SQLException caught: JDBCOracleLOBBinaryStream.insertImageIntoOracleDB() " +
    "on closing ResultSet or PreparedStatement.");
    closingSqlEx.printStackTrace();
    } // end of finally
    }

    Make a lumpy mistake; the new BLOB#setBinaryStream() method takes a position of where the data is read from in the stream given to it. So the following code:
    imgToDB = blobImage.setBinaryStream(imgFile.length());
    Starts off from the end of the file. Now I don't understand how this position would result in the duplicated amount of bytes read from the binary file (an image here) to the output stream! The correct line should be:
    imgToDB = blobImage.setBinaryStream(0L);
    ARGH!!! Now everything works as it expected. I gotta read the API's more carefully as I was expecting the same semantic parameter as PreparedStatement#setBinaryStream() which takes the length of the stream as one of its parameters.

  • Switching my output stream back to the command prompt

    Hi there,
    I was just wondering if anybody could tell me how I can switch back to printing lines in the command prompt after I've set the output stream to a text file.
    jjmclell

    ok, I started by changing the output stream to a text file as follows:
    String path = ("C:/JFiles/Harvest/");
    String filename = path + "Stand_ages.txt";
    System.out.println("Using file: " + filename);
    File file = new File(filename);
    FileOutputStream fos = new FileOutputStream(file);
    PrintStream ps = new PrintStream(fos);
    System.setOut(ps);
    This works fine. However, I'd also like to create other text files for other results from my program. I was able to do this, but what I can't do is get Java to print anything on the screen once I've started to print to text files. All I want is the location of the file to pop up for each of the text files that I create:
    System.out.println("Using file: " + filename);
    I tried this but it didn't work:
    String path2 = ("C:/JFiles/Harvest/");
    String filename2 = path2 + "Harvest_targets.txt";
    PrintStream ps2 = System.out;
    System.setOut(ps2);
    System.out.println("Using file: " + filename2);
    File file2 = new File(filename2);
    FileOutputStream fos2 = new FileOutputStream(file2);
    PrintStream ps3 = new PrintStream(fos2);
    System.setOut(ps3);
    What I wanted to do was briefly switch the output stream back to the command prompt just to print the one line and then switch back to printing to a text file. However, in my code, System.out.println("Using file: " + filename2); is just printing to the text file that I'm creating instead of showing up on the command prompt.
    Any help?
    jjmclell

  • How to get the output of a C prgram to Java to the parent Java program

    Hi,
    Suppose there is a Java Program which calls inside it the C program.The C program outputs as below
    printf("%c%c",c1,c2);
    Now I have to take this output as an input of the Java Program for further processing.How can I do this?
    Tapas

    By reading from the output stream of the C program.
    (if you're not already reading the output stream of the program anyway, you should be - http://java.sun.com/developer/JDCTechTips/2005/tt0727.html#2 )
    The format is a char, a space, a char, so just call read() three times and ignore the second value.

  • Questions about input/output streams

    In the following tutorial:
    http://chortle.ccsu.ctstateu.edu/CS151/Notes/chap85/ch85_10.html
    It mentions that some methods, such as write(), writeByte(), writeBytes(), and writeChar(), return the low eight bits of the argument to the output stream. I am a little unsure of what exactly that means, might somebody be able to clarify for me?
    In addition, I've been encountering the flush() method in some of the byte- and character-streaming objects that deal with buffers. What exactly is the flush() method's purpose, and when might it be used? Thank you.

    flush pushes the data out of the buffer. the write methods write to the buffer, when the buffer is full, it flushes itself (usually), or it could block the write methods (in theory). flush just lets you make sure that it's flushed.
    I'm not sure there's any reason to worry about high and low bytes in Java most of the time. I suppose, like anything, there's times you need to, but I can't think of any offhand.

  • Java - InputStream - Weird Characters in the Output!

    Hi,
    I have a software which outputs lines of numbers one by one. In another java program, I use BufferedReader as follows:
    BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"US-ASCII"));
    where pr is the process which runs the software. For each line in the output stream, I try to check whether the first number in the line is greater than a certain value and if it is, I write to another file.
    The problem is, when I run the software repeatedly (in a linux cluster) like 10 simulations simultaneously, one of them have got @^@^.... characters followed by some huge numbers. So, I tried eliminating that line alone by using String.matches command but now, it seems even after that I get the error - so, I think it might mean that it is actually during the writing process that the problem occurs. I use BufferedWriter like the following to write it: (I do flush it after writing.)
    BufferedWriter out=new BufferedWriter(new FileWriter(tmp_file));
    I would greatly appreciate if someone can help. This thing really seems to be a huge bottleneck!
    Thanks,
    Senthil

    Hi ejp! Thanks - here is the code!
    import java.io.BufferedReader;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.io.*;
    import java.util.*;
    //call the class file with the input xml file to simulate
    public class RunSim {
    public static void main(String[] args) {
    String[] xmlFiles = new String[] { "/home/senthil/Simulator/Dessa1.4/" args[0]};
    Scanner input=null;
    FileWriter ofw=null;
    PrintWriter out=null;
    for(String file:xmlFiles) {
    try {
    String[] command = {"java","Test",file, "10000"};
    Process pr = Runtime.getRuntime().exec(command); // run the command
    input = new Scanner(new InputStreamReader(pr.getInputStream()));
    String line=null;
    ofw=new FileWriter(file"_out.txt");
    out=new PrintWriter(ofw);
    while(input.hasNextLine()) {
    line=input.nextLine();
    System.out.println(line);
    if(line.matches("[0-9.\\s]*")) { // I included this as I didn't want the '@^' character - but still, it is being produced.
    out.println(line);
    out.flush();
    String[] str = line.split(" ");
    if(!line.equals("Badly formatted XML file")){
    if((Float.parseFloat(str[0]) >= 196)) //this is the limit upto which the process has to be run
    pr.destroy();
    else
    continue;
    out.close();
    int exitVal = pr.waitFor();
    System.out.println("Exited with error code "+exitVal);
    } catch(Exception e) {
    System.out.println(e.toString());
    e.printStackTrace();
    }

  • Capturing the output of a JSP page as HTML

    Hi,
    Can anyone tell me if this is possible. I have a JSP page that contains
    information about an order that was just entered (Essentially a
    confirmation page). What I want to do is somehow intercept the output
    stream inside the JSP page and write it to a file, as plain html, which
    I
    will later attach to an email and send to someone.
    Thanks,
    Jordi
    Jordi Pinyol Essi Projects
    Ingeniero de Desarrollo
    [email protected] t +34 977 221 182
    http://www.essiprojects.com f +34 977 230 170

    You won't be able to "intercept" the output since it is the JSP page itself that is doing the writing.
    Will the file that you write the output to reside on the client side or the server side? It sounds like you want to receive the HTML output not as something to view on the browser, but a file you can save and send and use later. If this is the case, one technique that might work is to take advantage of the servlet name mapping feature that is available for registered JSP pages.
    Assuming your JSP pages are registered, you would map your JSP page like:
    <servlet>
    <servlet-name>confirmation</servlet-name>
    <jsp-file>confirmation.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
    <servlet-name>confirmation</servlet-name>
    <url-pattern>/confirmation.out</url-pattern>
    </servlet-mapping>
    What happens is that a request for the URL /NASApp/myapp/confirmation.out gets mapped to the confirmation.jsp JSP page. If you set your MIME type correctly in the JSP page, the HTML output from the JSP page is not properly recognized by the browser causing it to prompt you to save the file.
    I have used this technique to generated CSV files from a JSP page. The browser is completely fooled.
    JC
    Jordi Pi?ol wrote:
    >
    Hi,
    Can anyone tell me if this is possible. I have a JSP page that contains
    information about an order that was just entered (Essentially a
    confirmation page). What I want to do is somehow intercept the output
    stream inside the JSP page and write it to a file, as plain html, which
    I
    will later attach to an email and send to someone.
    Thanks,
    Jordi
    Jordi Pinyol Essi Projects
    Ingeniero de Desarrollo
    [email protected] t +34 977 221 182
    http://www.essiprojects.com f +34 977 230 170

  • Is there a general purpose output stream class like in java?

    Hi, I sometimes create tools (abap OO classes) which output characters, that I would like to store in any media (frontend file, server file, string variable, ftp, clipboard, etc.) This is easily done in java via the output stream classes.
    Do you know if this kind of class exists? I saw some classes like that, but they are specialized, for example XML, SOAP. I look for non-specialized classes like in java.
    Same question for input streams! (normally, we should deduct the input stream classes from the output stream classes)
    Or did you develop yourself such input stream or output stream classes that you'd accept to share?
    Thx a lot
    sandra
    Thx a lot!
    Edited by: Matt on Nov 20, 2008 9:50 AM - Fixed the posting

    Yes it exists, but in release 7.10 only. [ABAP Keyword Documentation u2192  ABAP - By Theme u2192  Process External Data u2192  Streaming|http://help.sap.com/abapdocu/en/ABENSTREAMING.htm]

Maybe you are looking for

  • Error while executing the interface

    Hi, I have created an interface where i have mapped 2 tables of one source database(using joins) to a table of target database. Now when i am executing this and checking the results this error is coming- 997 : 42000 : java.sql.SQLException: ORA-00997

  • Magic Mouse won't scroll in mail

    MAGIC MOUSE WON'T SCROLL IN MAIL IT WORKS FINE EVERYWHERE ELSE.

  • Things That Make Me Wonder...

    I sort of understand how vinegar is made... but I don't understand how Balsamic Vinegerette is made out of Balsa wood? The book said women are from Venus and men are from Mars... so why am I not from the planet Uranus when my wife tells me I'm acting

  • Userid in forms after query

    I have a form that allows a supervisor to do an automatic query in a form by selecting a "job number". Once the supervisor selects that number, the fields of the form are populated with the existing data in the database. I currently have a trigger th

  • Power saver Utility does not run on new OS

    Hello there, I have reinstalled win XP pro Hun SP2 ED.4 codename:Simplicity on my freshly bought toshiba laptop A110-253. My question is the following: How can I install the Power Saver Utility on it? I have downloaded the utility from the official T