KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > core > connection > OtherResponse


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.core.connection;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.URL JavaDoc;
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 JavaDoc url;
24     protected InputStream JavaDoc in;
25     protected long lastModified;
26
27     protected OtherResponse(URL JavaDoc url) {
28         this.url = url;
29     }
30
31     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
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 JavaDoc e) {
46                 }
47                 in = null;
48         }
49     }
50     
51     /**
52      * @see IResponse#getInputStream(IProgressMonitor)
53      */

54     public InputStream JavaDoc getInputStream(IProgressMonitor monitor)
55         throws IOException JavaDoc, 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 JavaDoc getStatusMessage() {
84         return ""; //$NON-NLS-1$
85
}
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