Tabman's answer might possibly be what you're looking for -- but the more general answer I'd give would be:
"You can't, and you generally don't need to. What are you really trying to do?" Most of the times that people think they want to abort waiting IO, that's really not what they need. It's usually sufficient to indicate that the loop that was processing the data that its job is done. Aborting actual IO calls is an iffy thing on all platforms I've ever used. (Note I'm talking about real-world behavior here; some APIs do document a well-defined abort operation). I've done all manner of asynchronous and threaded IO over many decades, but very, very seldom have I needed to abort a pending IO operation. In fact, I may never have encountered a need to do so. Timeouts are often important, but aborting a pending I/O operation implies you don't really care whether it succeeded or failed (as that's a race condition), and yet you have a need for terminating the I/O operation too urgent for a timeout. The need for urgent cancellation I have a hard time justifying. On Jan 7, 12:48 pm, ivan <istas...@gmail.com> wrote: > Tabman, > > I think that's the best idea yet, but I'm surprised the Apache classes > don't offer some mechanism for "manually" interrupting the I/O > blocks. After all, we can set timeouts on all of the I/O operations, > which will interrupt the blocks with socket timeout exceptions etc. > > Thanks. > > On Jan 7, 1:31 pm, Tabman <tabishfay...@gmail.com> wrote: > > > > > > > > > I think you can extend the InputStream class and override its read > > method and inside read you can cancel/stop the read loop operation > > whenever you want to. > > > Here is the source for > > InputStream.javahttp://www.docjar.com/html/api/java/io/InputStream.java.html > > > Let me know if this solves your problem. > > > On Jan 7, 7:07 pm, ivan <istas...@gmail.com> wrote: > > > > I'm wondering what the currently suggested method is for interrupting > > > a read operation of a socket input stream? > > > > I know that traditionally the read could be interrupted by closing the > > > socket from another thread and catching an IOException, but I'm not > > > quite sure how to get at the socket from the apache classes. > > > > Maybe I should use some sort of interruptible channel instead ... ? > > > > Any links or help is greatly appreciated. > > > > My code looks like this -- minus most of the error handling: > > > > org.apache.http.impl.client.DefaultHttpClient > > > org.apache.http.client.methods.HttpGet > > > org.apache.http.HttpResponse > > > > DefaultHttpClient client = new DefaultHttpClient(httpParameters); > > > > HttpGet request = new HttpGet(Uri); > > > > HttpResponse response = client.execute(request); > > > > InputStream entityStream = response.getEntity().getContent(); > > > > try > > > { > > > bytesRead = entityStream.read(data);} > > > > catch (IOException ex) > > > { > > > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en