1 11 12 package org.eclipse.update.internal.core.connection; 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.net.URLConnection ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.update.internal.core.UpdateCore; 23 24 28 public abstract class AbstractResponse implements IResponse { 29 30 private static final long POLLING_INTERVAL = 200; 31 protected URLConnection connection; 32 33 protected InputStream openStreamWithCancel(URLConnection urlConnection, IProgressMonitor monitor) throws IOException , CoreException, TooManyOpenConnectionsException { 34 35 ConnectionThreadManager.StreamRunnable runnable = 36 new ConnectionThreadManager.StreamRunnable(urlConnection); 37 Thread t = ConnectionThreadManagerFactory.getConnectionManager().getConnectionThread( 38 runnable); 39 t.start(); 40 InputStream is = null; 41 try { 42 for (;;) { 43 if (monitor.isCanceled()) { 44 runnable.disconnect(); 45 connection = null; 46 break; 47 } 48 if (runnable.getInputStream() != null || !t.isAlive()) { 49 is = runnable.getInputStream(); 50 break; 51 } 52 if (runnable.getIOException() != null) 53 throw runnable.getIOException(); 54 if (runnable.getException() != null) 55 throw new CoreException(new Status(IStatus.ERROR, 56 UpdateCore.getPlugin().getBundle().getSymbolicName(), 57 IStatus.OK, 58 runnable.getException().getMessage(), 59 runnable.getException())); 60 t.join(POLLING_INTERVAL); 61 } 62 } catch (InterruptedException e) { 63 } 64 return is; 65 } 66 67 68 69 } 70 | Popular Tags |