| Method from java.net.URLConnection Detail: |
public void addRequestProperty(String field,
String newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
if (field == null) {
throw new NullPointerException(Messages.getString("luni.95")); //$NON-NLS-1$
}
}
Adds the given property to the request header. Existing properties with
the same name will not be overwritten by this method. |
abstract public void connect() throws IOException
Establishes the connection to the earlier configured resource. The
connection can only be set up before this method has been called. |
public boolean getAllowUserInteraction() {
return allowUserInteraction;
}
Gets the option value which indicates whether user interaction is allowed
on this {@code URLConnection}. |
public int getConnectTimeout() {
return connectTimeout;
}
Gets the configured connecting timeout. |
public Object getContent() throws IOException {
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;
}
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. |
public Object getContent(Class[] types) throws IOException {
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;
}
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}. |
public String getContentEncoding() {
return getHeaderField("Content-Encoding"); //$NON-NLS-1$
}
Gets the content encoding type specified by the response header field
{@code content-encoding} or {@code null} if this field is not set. |
public int getContentLength() {
return getHeaderFieldInt("Content-Length", -1); //$NON-NLS-1$
}
Gets the content length in bytes specified by the response header field
{@code content-length} or {@code -1} if this field is not set. |
public String getContentType() {
return getHeaderField("Content-Type"); //$NON-NLS-1$
}
Gets the MIME-type of the content specified by the response header field
{@code content-type} or {@code null} if type is unknown. |
public long getDate() {
return getHeaderFieldDate("Date", 0); //$NON-NLS-1$
}
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. |
public static boolean getDefaultAllowUserInteraction() {
return defaultAllowUserInteraction;
}
Gets the default setting whether this connection allows user interaction. |
public static String getDefaultRequestProperty(String field) {
return null;
} Deprecated! Use - #getRequestProperty
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}. |
public boolean getDefaultUseCaches() {
return defaultUseCaches;
}
Gets the default setting whether this connection allows using caches. |
public boolean getDoInput() {
return doInput;
}
Gets the value of the option {@code doInput} which specifies whether this
connection allows to receive data. |
public boolean getDoOutput() {
return doOutput;
}
Gets the value of the option {@code doOutput} which specifies whether
this connection allows to send data. |
public long getExpiration() {
return getHeaderFieldDate("Expires", 0); //$NON-NLS-1$
}
Gets the timestamp when this response will be expired in milliseconds
since January 1, 1970 GMT or {@code 0} if this timestamp is unknown. |
public static FileNameMap getFileNameMap() {
// Must use lazy initialization or there is a bootstrap problem
// trying to load the MimeTable resource from a .jar before
// JarURLConnection has finished initialization.
synchronized (URLConnection.class) {
if (fileNameMap == null) {
fileNameMap = new MimeTable();
}
return fileNameMap;
}
}
Gets the table which is used by all {@code URLConnection} instances to
determine the MIME-type according to a file extension. |
public String getHeaderField(int pos) {
return null;
}
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}. |
public String getHeaderField(String key) {
return null;
}
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}. |
public long getHeaderFieldDate(String field,
long defaultValue) {
String date = getHeaderField(field);
if (date == null) {
return defaultValue;
}
try {
return Date.parse(date);
} catch (Exception e) {
return 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. |
public int getHeaderFieldInt(String field,
int defaultValue) {
try {
return Integer.parseInt(getHeaderField(field));
} catch (NumberFormatException e) {
return 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}. |
public String getHeaderFieldKey(int posn) {
return null;
}
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}. |
public Map<String> getHeaderFields() {
return Collections.emptyMap();
}
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. |
public long getIfModifiedSince() {
return ifModifiedSince;
}
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. |
public InputStream getInputStream() throws IOException {
throw new UnknownServiceException(Messages.getString("luni.96")); //$NON-NLS-1$
}
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. |
public long getLastModified() {
if (lastModified != -1) {
return lastModified;
}
return lastModified = getHeaderFieldDate("Last-Modified", 0); //$NON-NLS-1$
}
Gets the value of the response header field {@code last-modified} or
{@code 0} if this value is not set. |
public OutputStream getOutputStream() throws IOException {
throw new UnknownServiceException(Messages.getString("luni.97")); //$NON-NLS-1$
}
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. |
public Permission getPermission() throws IOException {
return new java.security.AllPermission();
}
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. |
public int getReadTimeout() {
return readTimeout;
}
Gets the configured timeout for reading from the input stream of an
established connection to the resource. |
public Map<String> getRequestProperties() {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
return Collections.emptyMap();
}
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. |
public String getRequestProperty(String field) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
return null;
}
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}. |
public URL getURL() {
return url;
}
Gets the URL represented by this {@code URLConnection}. |
public boolean getUseCaches() {
return useCaches;
}
Gets the value of the flag which specifies whether this {@code
URLConnection} allows to use caches. |
public static String guessContentTypeFromName(String url) {
return getFileNameMap().getContentTypeFor(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. |
public static String guessContentTypeFromStream(InputStream is) throws IOException {
if (!is.markSupported()) {
return null;
}
// Look ahead up to 64 bytes for the longest encoded header
is.mark(64);
byte[] bytes = new byte[64];
int length = is.read(bytes);
is.reset();
// Check for Unicode BOM encoding indicators
String encoding = "ASCII";
int start = 0;
if (length > 1) {
if ((bytes[0] == (byte) 0xFF) && (bytes[1] == (byte) 0xFE)) {
encoding = "UTF-16LE";
start = 2;
length -= length & 1;
}
if ((bytes[0] == (byte) 0xFE) && (bytes[1] == (byte) 0xFF)) {
encoding = "UTF-16BE";
start = 2;
length -= length & 1;
}
if (length > 2) {
if ((bytes[0] == (byte) 0xEF) && (bytes[1] == (byte) 0xBB)
&& (bytes[2] == (byte) 0xBF)) {
encoding = "UTF-8";
start = 3;
}
if (length > 3) {
if ((bytes[0] == (byte) 0x00) && (bytes[1] == (byte) 0x00)
&& (bytes[2] == (byte) 0xFE)
&& (bytes[3] == (byte) 0xFF)) {
encoding = "UTF-32BE";
start = 4;
length -= length & 3;
}
if ((bytes[0] == (byte) 0xFF) && (bytes[1] == (byte) 0xFE)
&& (bytes[2] == (byte) 0x00)
&& (bytes[3] == (byte) 0x00)) {
encoding = "UTF-32LE";
start = 4;
length -= length & 3;
}
}
}
}
String header = new String(bytes, start, length - start, encoding);
// Check binary types
if (header.startsWith("PK")) {
return "application/zip";
}
if (header.startsWith("GI")) {
return "image/gif";
}
// Check text types
String textHeader = header.trim().toUpperCase();
if (textHeader.startsWith("< !DOCTYPE HTML") ||
textHeader.startsWith("< HTML") ||
textHeader.startsWith("< HEAD") ||
textHeader.startsWith("< BODY") ||
textHeader.startsWith("< HEAD")) {
return "text/html";
}
if (textHeader.startsWith("< ?XML")) {
return "application/xml";
}
// Give up
return null;
}
Determines the MIME-type of the resource represented by the input stream
{@code is} by reading its first few characters. |
public void setAllowUserInteraction(boolean newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
this.allowUserInteraction = newValue;
}
Sets the flag indicating whether this connection allows user interaction
or not. This method can only be called prior to the connection
establishment. |
public void setConnectTimeout(int timeout) {
if (0 > timeout) {
throw new IllegalArgumentException(Messages.getString("luni.5B")); //$NON-NLS-1$
}
this.connectTimeout = 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. |
public static synchronized void setContentHandlerFactory(ContentHandlerFactory contentFactory) {
if (contentHandlerFactory != null) {
throw new Error(Messages.getString("luni.98")); //$NON-NLS-1$
}
SecurityManager sManager = System.getSecurityManager();
if (sManager != null) {
sManager.checkSetFactory();
}
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. |
public static void setDefaultAllowUserInteraction(boolean allows) {
defaultAllowUserInteraction = allows;
}
Sets the default value for the flag indicating whether this connection
allows user interaction or not. Existing {@code URLConnection}s are
unaffected. |
public static void setDefaultRequestProperty(String field,
String value) {
} Deprecated! Use - #setRequestProperty of an existing {@code
URLConnection} instance.
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) {
if (connected) {
throw new IllegalAccessError(Messages.getString("luni.5E")); //$NON-NLS-1$
}
defaultUseCaches = newValue;
}
Sets the default value for the flag indicating whether this connection
allows to use caches. Existing {@code URLConnection}s are unaffected. |
public void setDoInput(boolean newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
this.doInput = newValue;
}
Sets the flag indicating whether this {@code URLConnection} allows input.
It cannot be set after the connection is established. |
public void setDoOutput(boolean newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
this.doOutput = newValue;
}
Sets the flag indicating whether this {@code URLConnection} allows
output. It cannot be set after the connection is established. |
public static void setFileNameMap(FileNameMap map) {
SecurityManager manager = System.getSecurityManager();
if (manager != null) {
manager.checkSetFactory();
}
synchronized (URLConnection.class) {
fileNameMap = map;
}
}
Sets the internal map which is used by all {@code URLConnection}
instances to determine the MIME-type according to a filename extension. |
public void setIfModifiedSince(long newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
this.ifModifiedSince = 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}. |
public void setReadTimeout(int timeout) {
if (0 > timeout) {
throw new IllegalArgumentException(Messages.getString("luni.5B")); //$NON-NLS-1$
}
this.readTimeout = 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. |
public void setRequestProperty(String field,
String newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
if (field == null) {
throw new NullPointerException(Messages.getString("luni.95")); //$NON-NLS-1$
}
}
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. |
public void setUseCaches(boolean newValue) {
if (connected) {
throw new IllegalStateException(Messages.getString("luni.5E")); //$NON-NLS-1$
}
this.useCaches = 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. |
public String toString() {
return getClass().getName() + ":" + url.toString(); //$NON-NLS-1$
}
Returns the string representation containing the name of this class and
the URL. |