Reputation: 603
Is there a way to set a Timeout to an InputStream?
My current code looks like that:
public class DownloadFile implements Runnable {
private EventHandler eh;
private String source;
private String destination;
public void run(){
try {
Log.d("Download", "Download... " + source);
URL url = new URL(source);
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(destination + "t");
Upvotes: 0
Views: 2459
Reputation: 15906
I think For you requirement you can use
HttpURLConnection.setReadTimeout()
Mab be these links will helps you.
Upvotes: 3
Reputation: 6159
You could start an AsyncTask or just a separate thread and sleep it for the timeout time and then check if the transaction is ready. Or even better, you could postDelayed a message to a Handler, and then check if your task is ready. You could use a timer too, but I think the Handler solution is the most elegant.
Take a look at this: http://developer.android.com/reference/android/os/Handler.html
Upvotes: 0