• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Help on sequential method execution

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am facing problem as below in my java program.
I want to write data from stream into text file & then process that created text file. The data in stream is very big & it creates text file with 600-700 lines. And then I want to process that text file.

I am doing it as below:-
_______________________________________________________________________________________________________
FileOutputStream fos = null;
try {
fos = new FileOutputStream("c:\\pal\\b.txt");
IOStreamConnector output = new IOStreamConnector(session.getInputStream(), fos);
session.getOutputStream().write("*****some big inputstream source here******");
fos.close();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidStateException e) {
e.printStackTrace();
}
FileUtility.readxmluserfile("c:\\pal\\b.txt");
_______________________________________________________________________________________________________

Now here the problem occuring is, before the b.txt file gets written completely with stream data, the method "readxmluserfile" starts executing, which is not desirable.
The method "readxmluserfile" should start executing only after the content from stream gets completely dumped into text file.
I tried one quick solution by placing line "Thread.currentThread().sleep(5000);" before call to method "readxmluserfile" which pauses current thread for 5 seconds then executes "readxmluserfile". However this is not proper way to do that. Can you please suggest me proper way to achieve above?

Many thanks in advance.

--Pras
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Did flush() worked out ?
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No...flush() is not working in it..
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IOStreamConnector, is that the j2ssh class?
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..its j2ssh class...
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pras,

I've never used this library before, but it looks like you need to check that the IOStreamConnector is finished, it looks like you need to add a listener and check that no more data is being transferred before you close it. I'd look for example patterns of use at http://sourceforge.net/projects/sshtools, also try on their forums
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martijn

As per your suggession I tried to add listener as follows:-

output.getState().waitForState(IOStreamConnectorState.CLOSED);

But thread never crossing this line, as this state seems to be never reached.

Do you have any other method for this?

Many thanks again for your help & suggessions.

--Pras
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pras,

Sorry, I simply don't know that library and I couldn't find any quick documentation on this. I see that their forum on Sourceforge is quite active, have you tried there?
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Martijn for your support....
Will check on the forum if I get something there..
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!