• Post Reply Bookmark Topic Watch Topic
  • New Topic

Behaviour of InputStream methods during serial transmission.  RSS feed

 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have to debug a problem where am doing a file transfer to a device connected serially. The problem is that when user unplugs the ethernet / serial connection cable, the progress bar freezes. Am not sure if this is because some exception is thrown or InputStream class's in.read() blocks when the cable is unplugged. Can someone tell me what might be the behaviour of in.read() method when cable is unplugged?

P.S: I do not have the device with me to debug this.

Thanks in advance,
Thejaswini.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It probably blocks until more data is available. However, since the connection has been lost it will probably time out.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how your hardware works, what sort of InputStream you are using, and possibly on what was happening in the stream when the disconnection occurred. But there are two basic possibilities: (a) it will throw some sort of IOException, or (b) read() will block indefinitely. If you are using a socket with timeout, then it will probably block until timeout, at which point you get an exception. Probably you need to handle both possibilities, an exception or blocking.

Hmmm:

[thejaswini ramesh]: Am not sure if this is because some exception is thrown

Why would you not be sure? If an exception is thrown, it should be logged unless you already completely understand the cause of the exception. If it's possible for an unknown exception to be thrown but not logged, this is a serious problem that should be fixed ASAP, regardless of what happens when a cable is disconnected. If there are any catch blocks in the code which catch an exception and don't log it, fix that.
[ March 13, 2008: Message edited by: Jim Yingst ]
 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob and Jim.
I have handled all exceptions and the possiblity of read() blocking now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!