java - Size limit on BufferedReader exceeded? -


in java 6 webapp, attempting retrieve large amount of output executed command. i've "borrowed/stolen/based" on javaworld article. problem facing length appears exceed size limit since output lopped off. i've output data file can see size of returned, , 32k (32768). i've experimented changing default size of buffer (see bufferedreader constructor), have not observed change length of data returned no matter value have buffered-size (very small large).

any advice appreciated!

public class streamgobbler extends thread {  private inputstream is; private string type; private list<string> output;  public streamgobbler(inputstream is, string type) {     this.is = is;     this.type = type; }  @override public void run() {     try {         inputstreamreader isr = new inputstreamreader(is);         bufferedreader br = new bufferedreader(isr);         string line = null;         this.output = new arraylist<string>();         while ((line = br.readline()) != null) {             this.getoutput().add(line + "\n");             system.out.println(type + ">" + line);         }         br.close();     } catch (ioexception ioe) {         system.err.println("error: " + ioe.getmessage());     } }  /**  * @return output  */ public list<string> getoutput() {     return output; } 

}

public class jobclassads {  private string condor_history = "condor_history"; private string condor_history_xml = condor_history + " -xml"; private string condor_history_long = condor_history + " -long";  public string gethistory() {     try {         runtime runtime = runtime.getruntime();         string exec = condor_history_long;         process process = runtime.exec(exec);         system.out.println("running " + exec + " ...");          // error message         streamgobbler errgobbler = new streamgobbler(process.geterrorstream(), "error");          // output         streamgobbler outgobbler = new streamgobbler(process.getinputstream(), "output");          thread outthread = new thread(outgobbler);         thread errthread = new thread(errgobbler);          outthread.start();         errthread.start();          outthread.join();         errthread.join();          /*         string line = null;          while ((line = input.readline()) != null) {             system.out.println(line);             content.append(line);         }           *          */          int exitval = process.waitfor();          list<string> output = outgobbler.getoutput();         string inputstring = "";         (string o : output) {             inputstring += o;         }          system.out.println(exec + " exited error code " + exitval);          bufferedwriter out = new bufferedwriter(new filewriter("/tmp/history_result.xml"));         out.write(inputstring);         out.close();         return inputstring;      } catch (exception e) {         system.err.println(e.getmessage());         return null;     } } 

the problem not bufferedreader's buffer size.

i think real cause external command doing. suspect bailing out without flushing stdout stream. note "gobbling" not outputting command's stderr stream. that's may find evidence pointing real cause of problem.


by way, using streamgobbler class in suboptimal fashion. extends thread intended way use is:

    steamgobbler sg = new streamgobbler(...);     sg.start();     sg.join(); 

but doing this:

    steamgobbler sg = new streamgobbler(...);     thread th = new thread(sg);     th.start();     th.join(); 

it works ... because thread is-a runnable.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -