Methods Summary |
---|
public void | addRequestProperty(java.lang.String field, java.lang.String newValue)Adds the given property to the request header. Existing properties with
the same name will not be overwritten by this method.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
if (field == null) {
throw new NullPointerException(Msg.getString("KA007")); //$NON-NLS-1$
}
|
public abstract void | connect()Establishes the connection to the earlier configured resource. The
connection can only be set up before this method has been called.
|
public boolean | getAllowUserInteraction()Gets the option value which indicates whether user interaction is allowed
on this {@code URLConnection}.
return allowUserInteraction;
|
public int | getConnectTimeout()Gets the configured connecting timeout.
return connectTimeout;
|
public java.lang.Object | getContent()Gets an object representing the content of the resource this {@code
URLConnection} is connected to. First, it attempts to get the content
type from the method {@code getContentType()} which looks at the response
header field "Content-Type". If none is found it will guess the content
type from the filename extension. If that fails the stream itself will be
used to guess the content type.
if (!connected) {
connect();
}
if ((contentType = getContentType()) == null) {
if ((contentType = guessContentTypeFromName(url.getFile())) == null) {
contentType = guessContentTypeFromStream(getInputStream());
}
}
if (contentType != null) {
return getContentHandler(contentType).getContent(this);
}
return null;
|
public java.lang.Object | getContent(java.lang.Class[] types)Gets an object representing the content of the resource this {@code
URLConnection} is connected to. First, it attempts to get the content
type from the method {@code getContentType()} which looks at the response
header field "Content-Type". If none is found it will guess the content
type from the filename extension. If that fails the stream itself will be
used to guess the content type. The content type must match with one of
the list {@code types}.
if (!connected) {
connect();
}
if ((contentType = getContentType()) == null) {
if ((contentType = guessContentTypeFromName(url.getFile())) == null) {
contentType = guessContentTypeFromStream(getInputStream());
}
}
if (contentType != null) {
return getContentHandler(contentType).getContent(this, types);
}
return null;
|
public java.lang.String | getContentEncoding()Gets the content encoding type specified by the response header field
{@code content-encoding} or {@code null} if this field is not set.
return getHeaderField("Content-Encoding"); //$NON-NLS-1$
|
private java.net.ContentHandler | getContentHandler(java.lang.String type)Returns the specific ContentHandler that will handle the type {@code
contentType}.
// Replace all non-alphanumeric character by '_'
final String typeString = parseTypeString(type.replace('/", '."));
// if there's a cached content handler, use it
Object cHandler = contentHandlers.get(type);
if (cHandler != null) {
return (ContentHandler) cHandler;
}
if (contentHandlerFactory != null) {
cHandler = contentHandlerFactory.createContentHandler(type);
if (!(cHandler instanceof ContentHandler)) {
throw new UnknownServiceException();
}
contentHandlers.put(type, cHandler);
return (ContentHandler) cHandler;
}
// search through the package list for the right class for the Content
// Type
String packageList = AccessController
.doPrivileged(new PriviAction<String>(
"java.content.handler.pkgs")); //$NON-NLS-1$
if (packageList != null) {
final StringTokenizer st = new StringTokenizer(packageList, "|"); //$NON-NLS-1$
while (st.countTokens() > 0) {
try {
Class<?> cl = Class.forName(st.nextToken() + "." //$NON-NLS-1$
+ typeString, true, ClassLoader
.getSystemClassLoader());
cHandler = cl.newInstance();
} catch (ClassNotFoundException e) {
} catch (IllegalAccessException e) {
} catch (InstantiationException e) {
}
}
}
if (cHandler == null) {
cHandler = AccessController
.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
String className = "org.apache.harmony.luni.internal.net.www.content." //$NON-NLS-1$
+ typeString;
return Class.forName(className).newInstance();
} catch (ClassNotFoundException e) {
} catch (IllegalAccessException e) {
} catch (InstantiationException e) {
}
return null;
}
});
}
if (cHandler != null) {
if (!(cHandler instanceof ContentHandler)) {
throw new UnknownServiceException();
}
contentHandlers.put(type, cHandler); // if we got the handler,
// cache it for next time
return (ContentHandler) cHandler;
}
return defaultHandler;
|
public int | getContentLength()Gets the content length in bytes specified by the response header field
{@code content-length} or {@code -1} if this field is not set.
return getHeaderFieldInt("Content-Length", -1); //$NON-NLS-1$
|
public java.lang.String | getContentType()Gets the MIME-type of the content specified by the response header field
{@code content-type} or {@code null} if type is unknown.
return getHeaderField("Content-Type"); //$NON-NLS-1$
|
public long | getDate()Gets the timestamp when this response has been sent as a date in
milliseconds since January 1, 1970 GMT or {@code 0} if this timestamp is
unknown.
return getHeaderFieldDate("Date", 0); //$NON-NLS-1$
|
public static boolean | getDefaultAllowUserInteraction()Gets the default setting whether this connection allows user interaction.
return defaultAllowUserInteraction;
|
public static java.lang.String | getDefaultRequestProperty(java.lang.String field)Gets the default value for the specified request {@code field} or {@code
null} if the field could not be found. The current implementation of this
method returns always {@code null}.
return null;
|
public boolean | getDefaultUseCaches()Gets the default setting whether this connection allows using caches.
return defaultUseCaches;
|
public boolean | getDoInput()Gets the value of the option {@code doInput} which specifies whether this
connection allows to receive data.
return doInput;
|
public boolean | getDoOutput()Gets the value of the option {@code doOutput} which specifies whether
this connection allows to send data.
return doOutput;
|
public long | getExpiration()Gets the timestamp when this response will be expired in milliseconds
since January 1, 1970 GMT or {@code 0} if this timestamp is unknown.
return getHeaderFieldDate("Expires", 0); //$NON-NLS-1$
|
public static java.net.FileNameMap | getFileNameMap()Gets the table which is used by all {@code URLConnection} instances to
determine the MIME-type according to a file extension.
// Must use lazy initialization or there is a bootstrap problem
// trying to load the MimeTable resource from a .jar before
// JarURLConnection has finished initialization.
if (fileNameMap == null) {
fileNameMap = new MimeTable();
}
return fileNameMap;
|
public java.lang.String | getHeaderField(int pos)Gets the header value at the field position {@code pos} or {@code null}
if the header has fewer than {@code pos} fields. The current
implementation of this method returns always {@code null}.
return null;
|
public java.lang.String | getHeaderField(java.lang.String key)Gets the value of the header field specified by {@code key} or {@code
null} if there is no field with this name. The current implementation of
this method returns always {@code null}.
return null;
|
public long | getHeaderFieldDate(java.lang.String field, long defaultValue)Gets the specified header value as a date in milliseconds since January
1, 1970 GMT. Returns the {@code defaultValue} if no such header field
could be found.
String date = getHeaderField(field);
if (date == null) {
return defaultValue;
}
return Util.parseDate(date);
|
public int | getHeaderFieldInt(java.lang.String field, int defaultValue)Gets the specified header value as a number. Returns the {@code
defaultValue} if no such header field could be found or the value could
not be parsed as an {@code Integer}.
try {
return Integer.parseInt(getHeaderField(field));
} catch (NumberFormatException e) {
return defaultValue;
}
|
public java.lang.String | getHeaderFieldKey(int posn)Gets the name of the header field at the given position {@code posn} or
{@code null} if there are fewer than {@code posn} fields. The current
implementation of this method returns always {@code null}.
return null;
|
public java.util.Map | getHeaderFields()Gets an unchangeable map of the response-header fields and values. The
response-header field names are the key values of the map. The map values
are lists of header field values associated with a particular key name.
return Collections.emptyMap();
|
public long | getIfModifiedSince()Gets the point of time since when the data must be modified to be
transmitted. Some protocols transmit data only if it has been modified
more recently than a particular time.
return ifModifiedSince;
|
public java.io.InputStream | getInputStream()Gets an {@code InputStream} for reading data from the resource pointed by
this {@code URLConnection}. It throws an UnknownServiceException by
default. This method must be overridden by its subclasses.
throw new UnknownServiceException(Msg.getString("K004d")); //$NON-NLS-1$
|
public long | getLastModified()Gets the value of the response header field {@code last-modified} or
{@code 0} if this value is not set.
if (lastModified != -1) {
return lastModified;
}
return lastModified = getHeaderFieldDate("Last-Modified", 0); //$NON-NLS-1$
|
public java.io.OutputStream | getOutputStream()Gets an {@code OutputStream} for writing data to this {@code
URLConnection}. It throws an {@code UnknownServiceException} by default.
This method must be overridden by its subclasses.
throw new UnknownServiceException(Msg.getString("K005f")); //$NON-NLS-1$
|
public java.security.Permission | getPermission()Gets a {@code Permission} object representing all needed permissions to
open this connection. The returned permission object depends on the state
of the connection and will be {@code null} if no permissions are
necessary. By default, this method returns {@code AllPermission}.
Subclasses should overwrite this method to return an appropriate
permission object.
return new java.security.AllPermission();
|
public int | getReadTimeout()Gets the configured timeout for reading from the input stream of an
established connection to the resource.
return readTimeout;
|
public java.util.Map | getRequestProperties()Gets an unchangeable map of general request properties used by this
connection. The request property names are the key values of the map. The
map values are lists of property values of the corresponding key name.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
return Collections.emptyMap();
|
public java.lang.String | getRequestProperty(java.lang.String field)Gets the value of the request header property specified by {code field}
or {@code null} if there is no field with this name. The current
implementation of this method returns always {@code null}.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
return null;
|
public java.net.URL | getURL()Gets the URL represented by this {@code URLConnection}.
return url;
|
public boolean | getUseCaches()Gets the value of the flag which specifies whether this {@code
URLConnection} allows to use caches.
return useCaches;
|
public static java.lang.String | guessContentTypeFromName(java.lang.String url)Determines the MIME-type of the given resource {@code url} by resolving
the filename extension with the internal FileNameMap. Any fragment
identifier is removed before processing.
return getFileNameMap().getContentTypeFor(url);
|
public static java.lang.String | guessContentTypeFromStream(java.io.InputStream is)Determines the MIME-type of the resource represented by the input stream
{@code is} by reading its first few characters.
if (!is.markSupported()) {
return null;
}
is.mark(4);
char[] chars = new char[4];
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) is.read();
}
is.reset();
if ((chars[0] == 'P") && (chars[1] == 'K")) {
return "application/zip"; //$NON-NLS-1$
}
if ((chars[0] == 'G") && (chars[1] == 'I")) {
return "image/gif"; //$NON-NLS-1$
}
if (new String(chars).trim().startsWith("<")) { //$NON-NLS-1$
return "text/html"; //$NON-NLS-1$
}
return null;
|
private java.lang.String | parseTypeString(java.lang.String typeString)Performs any necessary string parsing on the input string such as
converting non-alphanumeric character into underscore.
StringBuffer typeStringBuffer = new StringBuffer(typeString);
for (int i = 0; i < typeStringBuffer.length(); i++) {
// if non-alphanumeric, replace it with '_'
char c = typeStringBuffer.charAt(i);
if (!(Character.isLetter(c) || Character.isDigit(c) || c == '.")) {
typeStringBuffer.setCharAt(i, '_");
}
}
return typeStringBuffer.toString();
|
public void | setAllowUserInteraction(boolean newValue)Sets the flag indicating whether this connection allows user interaction
or not. This method can only be called prior to the connection
establishment.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
this.allowUserInteraction = newValue;
|
public void | setConnectTimeout(int timeout)Sets the timeout value in milliseconds for establishing the connection to
the resource pointed by this {@code URLConnection} instance. A {@code
SocketTimeoutException} is thrown if the connection could not be
established in this time. Default is {@code 0} which stands for an
infinite timeout.
if (0 > timeout) {
throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
}
this.connectTimeout = timeout;
|
public static synchronized void | setContentHandlerFactory(java.net.ContentHandlerFactory contentFactory)Sets the internally used content handler factory. The content factory can
only be set if it is allowed by the security manager and only once during
the lifetime of the application.
if (contentHandlerFactory != null) {
throw new Error(Msg.getString("K004e")); //$NON-NLS-1$
}
SecurityManager sManager = System.getSecurityManager();
if (sManager != null) {
sManager.checkSetFactory();
}
contentHandlerFactory = contentFactory;
|
public static void | setDefaultAllowUserInteraction(boolean allows)Sets the default value for the flag indicating whether this connection
allows user interaction or not. Existing {@code URLConnection}s are
unaffected.
defaultAllowUserInteraction = allows;
|
public static void | setDefaultRequestProperty(java.lang.String field, java.lang.String value)Sets the default value of the specified request header field. This value
will be used for the specific field of every newly created connection.
The current implementation of this method does nothing.
|
public void | setDefaultUseCaches(boolean newValue)Sets the default value for the flag indicating whether this connection
allows to use caches. Existing {@code URLConnection}s are unaffected.
// BEGIN android-removed
// Setting the default doesn't concern the current connection.
// if (connected) {
// throw new IllegalAccessError(Msg.getString("K0037")); //$NON-NLS-1$
// }
// END android-removed
defaultUseCaches = newValue;
|
public void | setDoInput(boolean newValue)Sets the flag indicating whether this {@code URLConnection} allows input.
It cannot be set after the connection is established.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
this.doInput = newValue;
|
public void | setDoOutput(boolean newValue)Sets the flag indicating whether this {@code URLConnection} allows
output. It cannot be set after the connection is established.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
this.doOutput = newValue;
|
public static void | setFileNameMap(java.net.FileNameMap map)Sets the internal map which is used by all {@code URLConnection}
instances to determine the MIME-type according to a filename extension.
SecurityManager manager = System.getSecurityManager();
if (manager != null) {
manager.checkSetFactory();
}
fileNameMap = map;
|
public void | setIfModifiedSince(long newValue)Sets the point of time since when the data must be modified to be
transmitted. Some protocols transmit data only if it has been modified
more recently than a particular time. The data will be transmitted
regardless of its timestamp if this option is set to {@code 0}.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
this.ifModifiedSince = newValue;
|
public void | setReadTimeout(int timeout)Sets the timeout value in milliseconds for reading from the input stream
of an established connection to the resource. A {@code
SocketTimeoutException} is thrown if the connection could not be
established in this time. Default is {@code 0} which stands for an
infinite timeout.
if (0 > timeout) {
throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
}
this.readTimeout = timeout;
|
public void | setRequestProperty(java.lang.String field, java.lang.String newValue)Sets the value of the specified request header field. The value will only
be used by the current {@code URLConnection} instance. This method can
only be called before the connection is established.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
if (field == null) {
throw new NullPointerException(Msg.getString("KA007")); //$NON-NLS-1$
}
|
public void | setUseCaches(boolean newValue)Sets the flag indicating whether this connection allows to use caches or
not. This method can only be called prior to the connection
establishment.
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
this.useCaches = newValue;
|
public java.lang.String | toString()Returns the string representation containing the name of this class and
the URL.
return getClass().getName() + ":" + url.toString(); //$NON-NLS-1$
|