blob: 5f8301477ec0f39a5825297be5e39cf287e4561f [file] [log] [blame]
package org.eclipse.update.internal.core;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.net.URL;
import java.net.URLConnection;
/*
* (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
public class Response {
private URL url;
private InputStream in;
private URLConnection connection;
/**
*
*/
public Response(InputStream in) {
super();
this.in = in;
}
/**
*
*/
public Response(URL url) {
super();
this.url = url;
}
/**
* Method getInputStream.
* @return InputStream
*/
public InputStream getInputStream() throws IOException {
if (in == null && url != null) {
connection = url.openConnection();
this.in = connection.getInputStream();
}
return in;
}
/**
* Method getContentLength.
* @return long
*/
public long getContentLength() {
if (connection != null)
return connection.getContentLength();
return 0;
}
/**
* Method getStatusCode.
* @return int
*/
public int getStatusCode() {
if (connection != null) {
if (connection instanceof HttpURLConnection)
try {
return ((HttpURLConnection) connection).getResponseCode();
} catch (IOException e) {
UpdateCore.warn("", e);
}
}
return IStatusCodes.HTTP_OK;
}
/**
* Method getStatusMessage.
* @return String
*/
public String getStatusMessage() {
if (connection != null) {
if (connection instanceof HttpURLConnection)
try {
return ((HttpURLConnection) connection).getResponseMessage();
} catch (IOException e) {
UpdateCore.warn("", e);
}
}
return "";
}
}