1 11 package org.eclipse.update.internal.core.connection; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.URL ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.update.internal.core.IStatusCodes; 20 21 public class OtherResponse extends AbstractResponse { 22 23 protected URL url; 24 protected InputStream in; 25 protected long lastModified; 26 27 protected OtherResponse(URL url) { 28 this.url = url; 29 } 30 31 public InputStream getInputStream() throws IOException { 32 if (in == null && url != null) { 33 if (connection == null) 34 connection = url.openConnection(); 35 in = connection.getInputStream(); 36 this.lastModified = connection.getLastModified(); 37 } 38 return in; 39 } 40 41 public void close() { 42 if( null != in ) { 43 try { 44 in.close(); 45 } catch (IOException e) { 46 } 47 in = null; 48 } 49 } 50 51 54 public InputStream getInputStream(IProgressMonitor monitor) 55 throws IOException , CoreException { 56 if (in == null && url != null) { 57 if (connection == null) 58 connection = url.openConnection(); 59 60 if (monitor != null) { 61 this.in = 62 openStreamWithCancel(connection, monitor); 63 } else { 64 this.in = connection.getInputStream(); 65 } 66 if (in != null) { 67 this.lastModified = connection.getLastModified(); 68 } 69 } 70 return in; 71 } 72 73 public long getContentLength() { 74 if (connection != null) 75 return connection.getContentLength(); 76 return 0; 77 } 78 79 public int getStatusCode() { 80 return IStatusCodes.HTTP_OK; 81 } 82 83 public String getStatusMessage() { 84 return ""; } 86 87 public long getLastModified() { 88 if (lastModified == 0 && connection != null) { 89 lastModified = connection.getLastModified(); 90 } 91 return lastModified; 92 } 93 94 95 } 96 | Popular Tags |