Java - output from line read in reverse -


the following routine outputs moves chess engine jtextarea

public void getengineoutputoriginal(process engine)  {     try {                    bufferedreader reader =           new bufferedreader (new inputstreamreader (engine.getinputstream ()), 1);         string lineread = null;         // send engine analysis print method         while ((lineread = reader.readline ()) != null)            application.showengineanalysis (lineread);     }     catch (exception e) {                       e.printstacktrace();     } } 

sample output be

           12     3.49  39/40?  2. b4      (656knps)                         12     3.49  40/40?  2. nd5     (656knps)                         12->   3.51   0.04   2. bxf4 be6 3. be3 qa5 4. nd5 qxd2            13     3.51   1/40?  2. bxf4    (655knps)    

is possible reverse process last line read appears @ top instead of bottom, so:

           13     3.51   1/40?  2. bxf4    (655knps)               12->   3.51   0.04   2. bxf4 be6 3. be3 qa5 4. nd5 qxd2            12     3.49  40/40?  2. nd5     (656knps)                         12     3.49  39/40?  2. b4      (656knps)      

i have researched google , couldn't find solution

sure! 1 option buffer lines arraylist, display them in reverse order @ end:

list<string> lines = new arraylist<string>();  /* add lines file buffer. */ while((lineread = reader.readline()) != null) {     lines.add(lineread); }  /* replay them in reverse order. */ (int = lines.size() - 1; >= 0; i--) {      application.showengineanalysis(lines.get(i)); } 

conceptually speaking, can think of making stack, pushing lines onto stack, popping them off 1 @ time.

hope helps!


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -