You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/01/05 15:44:06 UTC
svn commit: r493040 [10/11] - in
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java: java/net/
org/apache/harmony/luni/util/
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java Fri Jan 5 06:44:04 2007
@@ -17,7 +17,6 @@
package java.net;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -30,7 +29,6 @@
import java.util.StringTokenizer;
import org.apache.harmony.luni.internal.net.www.MimeTable;
-
import org.apache.harmony.luni.util.Msg;
import org.apache.harmony.luni.util.PriviAction;
import org.apache.harmony.luni.util.Util;
@@ -41,625 +39,631 @@
* determined by <code>URLStreamHandler.openConnection()</code>.
*/
public abstract class URLConnection {
- protected URL url;
- private String contentType;
+ protected URL url;
+
+ private String contentType;
- private static boolean defaultAllowUserInteraction;
+ private static boolean defaultAllowUserInteraction;
- private static boolean defaultUseCaches = true;
+ private static boolean defaultUseCaches = true;
- ContentHandler defaultHandler = new DefaultContentHandler();
+ ContentHandler defaultHandler = new DefaultContentHandler();
- private long lastModified = -1;
+ private long lastModified = -1;
- protected long ifModifiedSince;
+ protected long ifModifiedSince;
- protected boolean useCaches = defaultUseCaches;
+ protected boolean useCaches = defaultUseCaches;
- protected boolean connected;
+ protected boolean connected;
- protected boolean doOutput;
+ protected boolean doOutput;
- protected boolean doInput = true;
+ protected boolean doInput = true;
- protected boolean allowUserInteraction = defaultAllowUserInteraction;
+ protected boolean allowUserInteraction = defaultAllowUserInteraction;
+
+ private static ContentHandlerFactory contentHandlerFactory;
- private static ContentHandlerFactory contentHandlerFactory;
-
private int readTimeout = 0;
private int connectTimeout = 0;
-
- /**
- * Cache for storing Content handler
- */
- static Hashtable<String,Object> contentHandlers = new Hashtable<String,Object>();
-
- /**
- * A hashtable that maps the filename extension (key) to a MIME-type
- * (element)
- */
-
- private static FileNameMap fileNameMap;
-
- /**
- * Creates a URLConnection pointing to the resource specified by the
- * <code>url</code>
- */
- protected URLConnection(URL url) {
- this.url = url;
- }
-
- /**
- * Establishes the connection to the resource specified by this
- * <code>URL</code> with this <code>method</code>, along with other
- * options that can only be set before this connection is made.
- *
- * @throws IOException
- * If an error occurs while connecting
- *
- * @see java.io.IOException
- * @see URLStreamHandler
- */
- public abstract void connect() throws IOException;
-
- /**
- * Answers the value of <code>allowUserInteraction</code> which indicates
- * if this connection allows user interaction
- *
- * @return the value of the flag
- *
- * @see #getDefaultRequestProperty
- * @see #setDefaultRequestProperty
- * @see #allowUserInteraction
- */
- public boolean getAllowUserInteraction() {
- return allowUserInteraction;
- }
-
- /**
- * Answers the object pointed to by this <code>URL</code>. It first
- * attempts to get the content type from <code>getContentType()</code>,
- * which looks for the response header field "Content-Type". If none is
- * found, it will guess the content type from the filename extension. If
- * that fails, it will guess by inspecting the stream.
- *
- * @return a non-null object
- *
- * @throws IOException
- * if an IO error occurred
- *
- * @see ContentHandler
- * @see ContentHandlerFactory
- * @see IOException
- * @see #setContentHandlerFactory
- *
- */
- public Object getContent() throws java.io.IOException {
- if (!connected) {
+
+ /**
+ * Cache for storing Content handler
+ */
+ static Hashtable<String, Object> contentHandlers = new Hashtable<String, Object>();
+
+ /**
+ * A hashtable that maps the filename extension (key) to a MIME-type
+ * (element)
+ */
+ private static FileNameMap fileNameMap;
+
+ /**
+ * Creates a URLConnection pointing to the resource specified by the
+ * <code>url</code>
+ */
+ protected URLConnection(URL url) {
+ this.url = url;
+ }
+
+ /**
+ * Establishes the connection to the resource specified by this
+ * <code>URL</code> with this <code>method</code>, along with other
+ * options that can only be set before this connection is made.
+ *
+ * @throws IOException
+ * If an error occurs while connecting
+ *
+ * @see java.io.IOException
+ * @see URLStreamHandler
+ */
+ public abstract void connect() throws IOException;
+
+ /**
+ * Answers the value of <code>allowUserInteraction</code> which indicates
+ * if this connection allows user interaction
+ *
+ * @return the value of the flag
+ *
+ * @see #getDefaultRequestProperty
+ * @see #setDefaultRequestProperty
+ * @see #allowUserInteraction
+ */
+ public boolean getAllowUserInteraction() {
+ return allowUserInteraction;
+ }
+
+ /**
+ * Answers the object pointed to by this <code>URL</code>. It first
+ * attempts to get the content type from <code>getContentType()</code>,
+ * which looks for the response header field "Content-Type". If none is
+ * found, it will guess the content type from the filename extension. If
+ * that fails, it will guess by inspecting the stream.
+ *
+ * @return a non-null object
+ *
+ * @throws IOException
+ * if an IO error occurred
+ *
+ * @see ContentHandler
+ * @see ContentHandlerFactory
+ * @see IOException
+ * @see #setContentHandlerFactory
+ */
+ public Object getContent() throws java.io.IOException {
+ if (!connected) {
connect();
}
- if ((contentType = getContentType()) == null) {
+ if ((contentType = getContentType()) == null) {
if ((contentType = guessContentTypeFromName(url.getFile())) == null) {
contentType = guessContentTypeFromStream(getInputStream());
}
}
- if (contentType != null) {
+ if (contentType != null) {
return getContentHandler(contentType).getContent(this);
}
- return null;
- }
+ return null;
+ }
- /**
- * Answers the object pointed to by this <code>URL</code>. It first
- * attempts to get the content type from <code>getContentType()</code>,
- * which looks for the response header field "Content-Type". If none is
- * found, it will guess the content type from the filename extension. If
- * that fails, it will guess by inspecting the stream.
- *
- * @param types
- * The list of acceptable content types
- * @return Object The object of the resource pointed by this URL, or null if
- * the content does not match a specified content type.
- *
- * @throws IOException
- * If an error occurred obtaining the content.
- */
- public Object getContent(Class[] types) throws IOException {
- if (!connected) {
+ /**
+ * Answers the object pointed to by this <code>URL</code>. It first
+ * attempts to get the content type from <code>getContentType()</code>,
+ * which looks for the response header field "Content-Type". If none is
+ * found, it will guess the content type from the filename extension. If
+ * that fails, it will guess by inspecting the stream.
+ *
+ * @param types
+ * The list of acceptable content types
+ * @return Object The object of the resource pointed by this URL, or null if
+ * the content does not match a specified content type.
+ *
+ * @throws IOException
+ * If an error occurred obtaining the content.
+ */
+ // Param is not generic in spec
+ @SuppressWarnings("unchecked")
+ public Object getContent(Class[] types) throws IOException {
+ if (!connected) {
connect();
}
- if ((contentType = getContentType()) == null) {
+ if ((contentType = getContentType()) == null) {
if ((contentType = guessContentTypeFromName(url.getFile())) == null) {
contentType = guessContentTypeFromStream(getInputStream());
}
}
- if (contentType != null) {
+ if (contentType != null) {
return getContentHandler(contentType).getContent(this, types);
}
- return null;
- }
+ return null;
+ }
+
+ /**
+ * Answers the Content encoding type of the response body, null if no such
+ * field is found in the header response.
+ *
+ * @return The content encoding type
+ *
+ * @see #getContentType
+ */
+ public String getContentEncoding() {
+ return getHeaderField("Content-Encoding"); //$NON-NLS-1$
+ }
- /**
- * Answers the Content encoding type of the response body, null if no such
- * field is found in the header response.
- *
- * @return The content encoding type
- *
- * @see #getContentType
- */
- public String getContentEncoding() {
- return getHeaderField("Content-Encoding");
- }
-
- /**
- * Answers the specific ContentHandler that will handle the type
- * <code>contentType</code>
- *
- * @param type
- * The type that needs to be handled
- * @return An instance of the Content Handler
- */
- private ContentHandler getContentHandler(String type) throws IOException {
- // 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) {
+ /**
+ * Answers the specific ContentHandler that will handle the type
+ * <code>contentType</code>
+ *
+ * @param type
+ * The type that needs to be handled
+ * @return An instance of the Content Handler
+ */
+ private ContentHandler getContentHandler(String type) throws IOException {
+ // 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)) {
+ 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"));
- if (packageList != null) {
- final StringTokenizer st = new StringTokenizer(packageList, "|");
- while (st.countTokens() > 0) {
+ 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() + "." + typeString,
- true, ClassLoader.getSystemClassLoader());
+ 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."
- + typeString;
- return Class.forName(className).newInstance();
- } catch (ClassNotFoundException e) {
- } catch (IllegalAccessException e) {
- } catch (InstantiationException e) {
- }
- return null;
- }
- });
- }
- if (cHandler != null) {
- if (!(cHandler instanceof ContentHandler)) {
+ 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;
- }
-
- /**
- * Answers the length of the content or body in the response header in
- * bytes. Answer -1 if <code> Content-Length </code> cannot be found in the
- * response header.
- *
- * @return The length of the content
- *
- * @see #getContentType
- */
- public int getContentLength() {
- return getHeaderFieldInt("Content-Length", -1);
- }
-
- /**
- * Answers the type of the content. Answers <code> null </code> if there's
- * no such field.
- *
- * @return The type of the content
- *
- * @see #guessContentTypeFromName
- * @see #guessContentTypeFromStream
- */
- public String getContentType() {
- return getHeaderField("Content-Type");
- }
-
- /**
- * Answers the date in milliseconds since epoch when this response header
- * was created, or 0 if the field <code>Date</code> is not found in the
- * header.
- *
- * @return Date in millisecond since epoch
- *
- * @see #getExpiration
- * @see #getLastModified
- * @see java.util.Date
- *
- */
- public long getDate() {
- return getHeaderFieldDate("Date", 0);
- }
-
- /**
- * Answers whether this connection allow user interaction by default.
- *
- * @return the value of <code>defaultAllowUserInteraction</code>
- *
- * @see #getAllowUserInteraction
- * @see #setDefaultAllowUserInteraction
- * @see #setAllowUserInteraction
- * @see #allowUserInteraction
- */
- public static boolean getDefaultAllowUserInteraction() {
- return defaultAllowUserInteraction;
- }
-
- /**
- * Answers the default value for the field specified by <code>field</code>,
- * null if there's no such field.
- *
- * @param field
- * the field to get the request property for
- * @return the field to be looked up
- *
- * @deprecated Use getRequestProperty().
- */
- @Deprecated
+ contentHandlers.put(type, cHandler); // if we got the handler,
+ // cache it for next time
+ return (ContentHandler) cHandler;
+ }
+
+ return defaultHandler;
+ }
+
+ /**
+ * Answers the length of the content or body in the response header in
+ * bytes. Answer -1 if <code> Content-Length </code> cannot be found in the
+ * response header.
+ *
+ * @return The length of the content
+ *
+ * @see #getContentType
+ */
+ public int getContentLength() {
+ return getHeaderFieldInt("Content-Length", -1); //$NON-NLS-1$
+ }
+
+ /**
+ * Answers the type of the content. Answers <code> null </code> if there's
+ * no such field.
+ *
+ * @return The type of the content
+ *
+ * @see #guessContentTypeFromName
+ * @see #guessContentTypeFromStream
+ */
+ public String getContentType() {
+ return getHeaderField("Content-Type"); //$NON-NLS-1$
+ }
+
+ /**
+ * Answers the date in milliseconds since epoch when this response header
+ * was created, or 0 if the field <code>Date</code> is not found in the
+ * header.
+ *
+ * @return Date in millisecond since epoch
+ *
+ * @see #getExpiration
+ * @see #getLastModified
+ * @see java.util.Date
+ *
+ */
+ public long getDate() {
+ return getHeaderFieldDate("Date", 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Answers whether this connection allow user interaction by default.
+ *
+ * @return the value of <code>defaultAllowUserInteraction</code>
+ *
+ * @see #getAllowUserInteraction
+ * @see #setDefaultAllowUserInteraction
+ * @see #setAllowUserInteraction
+ * @see #allowUserInteraction
+ */
+ public static boolean getDefaultAllowUserInteraction() {
+ return defaultAllowUserInteraction;
+ }
+
+ /**
+ * Answers the default value for the field specified by <code>field</code>,
+ * null if there's no such field.
+ *
+ * @param field
+ * the field to get the request property for
+ * @return the field to be looked up
+ *
+ * @deprecated Use getRequestProperty().
+ */
+ @Deprecated
public static String getDefaultRequestProperty(String field) {
- return null;
- }
+ return null;
+ }
+
+ /**
+ * Answers whether this connection use caches by default.
+ *
+ * @return true if this connection use caches by default, false otherwise
+ *
+ * @see #getUseCaches
+ * @see #setDefaultUseCaches
+ * @see #setUseCaches
+ * @see #useCaches
+ */
+ public boolean getDefaultUseCaches() {
+ return defaultUseCaches;
+ }
+
+ /**
+ * Answers whether this connection supports input.
+ *
+ * @return true if this connection supports input, false otherwise
+ *
+ * @see #setDoInput
+ * @see #doInput
+ */
+ public boolean getDoInput() {
+ return doInput;
+ }
+
+ /**
+ * Answers whether this connection supports output.
+ *
+ * @return true if this connection supports output, false otherwise
+ *
+ * @see #setDoOutput
+ * @see #doOutput
+ */
+ public boolean getDoOutput() {
+ return doOutput;
+ }
+
+ /**
+ * Answers the date in milliseconds since epoch when this response header
+ * expires or 0 if the field <code>Expires</code> is not found in the
+ * header.
+ *
+ * @return Date in milliseconds since epoch
+ *
+ * @see #getHeaderField(int)
+ * @see #getHeaderField(String)
+ * @see #getHeaderFieldDate(String, long)
+ * @see #getHeaderFieldInt(String, int)
+ * @see #getHeaderFieldKey(int)
+ */
+ public long getExpiration() {
+ return getHeaderFieldDate("Expires", 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Answers the MIME table of this URL connection.
+ *
+ * @return FileNameMap
+ */
+ 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.
+ if (fileNameMap == null) {
+ fileNameMap = new MimeTable();
+ }
+ return fileNameMap;
+ }
+
+ /**
+ * Answers the value of the field at position <code>pos<code>.
+ * Answers <code>null</code> if there are fewer than <code>pos</code> fields
+ * in the response header.
+ *
+ * @param pos the position of the field
+ * @return The value of the field
+ *
+ * @see #getHeaderFieldDate
+ * @see #getHeaderFieldInt
+ * @see #getHeaderFieldKey
+ */
+ public String getHeaderField(int pos) {
+ return null;
+ }
+
+ /**
+ * Provides an unmodifiable map of the connection header values. The map
+ * keys are the String header field names. Each map value is a List of the
+ * header field values associated with that key name.
+ *
+ * @return the mapping of header field names to values
+ *
+ * @since 1.4
+ */
+ public Map<String, List<String>> getHeaderFields() {
+ return Collections.emptyMap();
+ }
- /**
- * Answers whether this connection use caches by default.
- *
- * @return true if this connection use caches by default, false otherwise
- *
- * @see #getUseCaches
- * @see #setDefaultUseCaches
- * @see #setUseCaches
- * @see #useCaches
- */
- public boolean getDefaultUseCaches() {
- return defaultUseCaches;
- }
-
- /**
- * Answers whether this connection supports input.
- *
- * @return true if this connection supports input, false otherwise
- *
- * @see #setDoInput
- * @see #doInput
- */
- public boolean getDoInput() {
- return doInput;
- }
-
- /**
- * Answers whether this connection supports output.
- *
- * @return true if this connection supports output, false otherwise
- *
- * @see #setDoOutput
- * @see #doOutput
- */
- public boolean getDoOutput() {
- return doOutput;
- }
-
- /**
- * Answers the date in milliseconds since epoch when this response header
- * expires or 0 if the field <code>Expires</code> is not found in the
- * header.
- *
- * @return Date in milliseconds since epoch
- *
- * @see #getHeaderField(int)
- * @see #getHeaderField(String)
- * @see #getHeaderFieldDate(String, long)
- * @see #getHeaderFieldInt(String, int)
- * @see #getHeaderFieldKey(int)
- */
- public long getExpiration() {
- return getHeaderFieldDate("Expires", 0);
- }
-
- /**
- * Answers the MIME table of this URL connection.
- *
- * @return FileNameMap
- */
- 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.
- if (fileNameMap == null) {
- fileNameMap = new MimeTable();
- }
- return fileNameMap;
- }
-
- /**
- * Answers the value of the field at position <code>pos<code>.
- * Answers <code>null</code> if there are fewer than <code>pos</code> fields
- * in the response header.
- *
- * @param pos the position of the field
- * @return The value of the field
- *
- * @see #getHeaderFieldDate
- * @see #getHeaderFieldInt
- * @see #getHeaderFieldKey
- */
- public String getHeaderField(int pos) {
- return null;
- }
-
- /**
- * Provides an unmodifiable map of the connection header values. The map
- * keys are the String header field names. Each map value is a List of the
- * header field values associated with that key name.
- *
- * @return the mapping of header field names to values
- *
- * @since 1.4
- */
- public Map<String, List<String>> getHeaderFields() {
- return Collections.emptyMap();
- }
-
- /**
- * Provides an unmodifiable map of the request properties. The map keys are
- * Strings, the map values are each a List of Strings, with each request
- * property name mapped to its corresponding property values.
- *
- * @return the mapping of request property names to values
- *
- * @since 1.4
- */
- public Map<String, List<String>> getRequestProperties() {
+ /**
+ * Provides an unmodifiable map of the request properties. The map keys are
+ * Strings, the map values are each a List of Strings, with each request
+ * property name mapped to its corresponding property values.
+ *
+ * @return the mapping of request property names to values
+ *
+ * @since 1.4
+ */
+ public Map<String, List<String>> getRequestProperties() {
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
- return Collections.emptyMap();
- }
+ return Collections.emptyMap();
+ }
- /**
- * Adds the given request property. Will not overwrite any existing
- * properties associated with the given field name.
- *
- * @param field
- * the request property field name
- * @param newValue
- * the property value
- *
- * @throws IllegalStateException - if connection already established
- * @throws NullPointerException - if field is null
- *
- * @since 1.4
- */
- public void addRequestProperty(String field, String newValue) {
+ /**
+ * Adds the given request property. Will not overwrite any existing
+ * properties associated with the given field name.
+ *
+ * @param field
+ * the request property field name
+ * @param newValue
+ * the property value
+ *
+ * @throws IllegalStateException -
+ * if connection already established
+ * @throws NullPointerException -
+ * if field is null
+ *
+ * @since 1.4
+ */
+ public void addRequestProperty(String field, String newValue) {
if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
if (field == null) {
- throw new NullPointerException(Msg.getString("KA007"));
+ throw new NullPointerException(Msg.getString("KA007")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Answers the value of the field corresponding to the <code>key</code>
+ * Answers <code>null</code> if there is no such field.
+ *
+ * @param key
+ * the name of the header field
+ * @return The value of the header field
+ *
+ * @see #getHeaderFieldDate
+ * @see #getHeaderFieldInt
+ * @see #getHeaderFieldKey
+ */
+ public String getHeaderField(String key) {
+ return null;
+ }
+
+ /**
+ * Answers the date value in the form of milliseconds since epoch
+ * corresponding to the field <code>field</code>. Answers
+ * <code>defaultValue</code> if no such field can be found in the response
+ * header.
+ *
+ * @param field
+ * the field in question
+ * @param defaultValue
+ * the default value if no field is found
+ * @return milliseconds since epoch
+ *
+ * @see #ifModifiedSince
+ * @see #setIfModifiedSince
+ */
+ public long getHeaderFieldDate(String field, long defaultValue) {
+ String date = getHeaderField(field);
+ if (date == null) {
+ return defaultValue;
}
- }
+ return Util.parseDate(date);
+ }
- /**
- * Answers the value of the field corresponding to the <code>key</code>
- * Answers <code>null</code> if there is no such field.
- *
- * @param key
- * the name of the header field
- * @return The value of the header field
- *
- * @see #getHeaderFieldDate
- * @see #getHeaderFieldInt
- * @see #getHeaderFieldKey
- */
- public String getHeaderField(String key) {
- return null;
- }
-
- /**
- * Answers the date value in the form of milliseconds since epoch
- * corresponding to the field <code>field</code>. Answers
- * <code>defaultValue</code> if no such field can be found in the response
- * header.
- *
- * @param field
- * the field in question
- * @param defaultValue
- * the default value if no field is found
- * @return milliseconds since epoch
- *
- * @see #ifModifiedSince
- * @see #setIfModifiedSince
- */
- public long getHeaderFieldDate(String field, long defaultValue) {
- String date = getHeaderField(field);
- if (date == null) {
+ /**
+ * Answers the integer value of the specified field. Answers default value
+ * <code>defaultValue</code> if no such field exists.
+ *
+ * @param field
+ * the field to return
+ * @param defaultValue
+ * to be returned if <code>field></code> does not exist
+ * @return value of the field
+ */
+ public int getHeaderFieldInt(String field, int defaultValue) {
+ try {
+ return Integer.parseInt(getHeaderField(field));
+ } catch (NumberFormatException e) {
return defaultValue;
}
- return Util.parseDate(date);
- }
+ }
+
+ /**
+ * Answers the name of the field at position specified by <code>posn</code>,
+ * null if there are fewer than <code>posn</code> fields.
+ *
+ * @param posn
+ * the position to look for; the first field being 0
+ * @return the name of the field
+ *
+ * @see #getHeaderFieldDate
+ * @see #getHeaderFieldInt
+ * @see #getHeaderField(int)
+ * @see #getHeaderField(String)
+ * @see #getHeaderFieldDate(String, long)
+ * @see #getHeaderFieldInt(String, int)
+ * @see #getHeaderFieldKey(int)
+ */
+ public String getHeaderFieldKey(int posn) {
+ return null;
+ }
- /**
- * Answers the integer value of the specified field. Answers default value
- * <code>defaultValue</code> if no such field exists.
- *
- * @param field
- * the field to return
- * @param defaultValue
- * to be returned if <code>field></code> does not exist
- * @return value of the field
- */
- public int getHeaderFieldInt(String field, int defaultValue) {
- try {
- return Integer.parseInt(getHeaderField(field));
- } catch (NumberFormatException e) {
- return defaultValue;
- }
- }
-
- /**
- * Answers the name of the field at position specified by <code>posn</code>,
- * null if there are fewer than <code>posn</code> fields.
- *
- * @param posn
- * the position to look for; the first field being 0
- * @return the name of the field
- *
- * @see #getHeaderFieldDate
- * @see #getHeaderFieldInt
- * @see #getHeaderField(int)
- * @see #getHeaderField(String)
- * @see #getHeaderFieldDate(String, long)
- * @see #getHeaderFieldInt(String, int)
- * @see #getHeaderFieldKey(int)
- */
- public String getHeaderFieldKey(int posn) {
- return null;
- }
-
- /**
- * Answers the value of <code>ifModifiedSince</code> of this connection in
- * milliseconds since epoch
- *
- * @return the time since epoch
- *
- * @see #ifModifiedSince
- * @see #setIfModifiedSince
- */
- public long getIfModifiedSince() {
- return ifModifiedSince;
- }
-
- /**
- * Creates an InputStream for reading from this URL Connection. It throws
- * UnknownServiceException by default. This method should be overridden by
- * its subclasses
- *
- * @return The InputStream to read from
- *
- * @throws IOException
- * If an InputStream could not be created
- *
- * @see #getContent()
- * @see #getContent(Class[])
- * @see #getOutputStream
- * @see java.io.InputStream
- * @see java.io.IOException
- *
- */
- public InputStream getInputStream() throws IOException {
- throw new UnknownServiceException(Msg.getString("K004d"));
- }
-
- /**
- * Answers the value of the field <code>Last-Modified</code> in the
- * response header, 0 if no such field exists
- *
- * @return the value of the field last modified
- *
- * @see java.util.Date
- * @see #getDate
- * @see #getExpiration
- */
- public long getLastModified() {
- if (lastModified != -1) {
+ /**
+ * Answers the value of <code>ifModifiedSince</code> of this connection in
+ * milliseconds since epoch
+ *
+ * @return the time since epoch
+ *
+ * @see #ifModifiedSince
+ * @see #setIfModifiedSince
+ */
+ public long getIfModifiedSince() {
+ return ifModifiedSince;
+ }
+
+ /**
+ * Creates an InputStream for reading from this URL Connection. It throws
+ * UnknownServiceException by default. This method should be overridden by
+ * its subclasses
+ *
+ * @return The InputStream to read from
+ *
+ * @throws IOException
+ * If an InputStream could not be created
+ *
+ * @see #getContent()
+ * @see #getContent(Class[])
+ * @see #getOutputStream
+ * @see java.io.InputStream
+ * @see java.io.IOException
+ *
+ */
+ public InputStream getInputStream() throws IOException {
+ throw new UnknownServiceException(Msg.getString("K004d")); //$NON-NLS-1$
+ }
+
+ /**
+ * Answers the value of the field <code>Last-Modified</code> in the
+ * response header, 0 if no such field exists
+ *
+ * @return the value of the field last modified
+ *
+ * @see java.util.Date
+ * @see #getDate
+ * @see #getExpiration
+ */
+ public long getLastModified() {
+ if (lastModified != -1) {
return lastModified;
}
- return lastModified = getHeaderFieldDate("Last-Modified", 0);
- }
+ return lastModified = getHeaderFieldDate("Last-Modified", 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates an OutputStream for writing to this URL Connection. It throws
+ * UnknownServiceException by default. This method should be overridden by
+ * subclasses.
+ *
+ * @return The OutputStream to write to
+ *
+ * @throws IOException
+ * If an OutputStream could not be created
+ *
+ * @see #getContent()
+ * @see #getContent(Class[])
+ * @see #getInputStream
+ * @see java.io.IOException
+ *
+ */
+ public OutputStream getOutputStream() throws IOException {
+ throw new UnknownServiceException(Msg.getString("K005f")); //$NON-NLS-1$
+ }
- /**
- * Creates an OutputStream for writing to this URL Connection. It throws
- * UnknownServiceException by default. This method should be overridden by
- * subclasses.
- *
- * @return The OutputStream to write to
- *
- * @throws IOException
- * If an OutputStream could not be created
- *
- * @see #getContent()
- * @see #getContent(Class[])
- * @see #getInputStream
- * @see java.io.IOException
- *
- */
- public OutputStream getOutputStream() throws IOException {
- throw new UnknownServiceException(Msg.getString("K005f"));
- }
-
- /**
- * Answers the permissions necessary to make the connection. Depending on
- * the protocol, this can be any of the permission subclasses. The
- * permission returned may also depend on the state of the connection, E.G
- * In the case of HTTP, redirection can change the applicable permission if
- * the host changed.
- *
- * <p>
- * By default, this methods returns <code>AllPermission</code>.
- * Subclasses should override this and return the appropriate permission
- * object.
- *
- * @return the permission object governing the connection
- *
- * @throws IOException
- * if an IO exception occurs during the creation of the
- * permission object.
- */
- public java.security.Permission getPermission() throws IOException {
- return new java.security.AllPermission();
- }
-
- /**
- * Answers the value corresponding to the field in the request Header, null
- * if no such field exists.
- *
- * @param field
- * the field to get the property for
- * @return the field to look up
- * @throws IllegalStateException -
- * if connection already established
- *
- * @see #getDefaultRequestProperty
- * @see #setDefaultRequestProperty
- * @see #setRequestProperty
- */
+ /**
+ * Answers the permissions necessary to make the connection. Depending on
+ * the protocol, this can be any of the permission subclasses. The
+ * permission returned may also depend on the state of the connection, E.G
+ * In the case of HTTP, redirection can change the applicable permission if
+ * the host changed.
+ *
+ * <p>
+ * By default, this methods returns <code>AllPermission</code>.
+ * Subclasses should override this and return the appropriate permission
+ * object.
+ *
+ * @return the permission object governing the connection
+ *
+ * @throws IOException
+ * if an IO exception occurs during the creation of the
+ * permission object.
+ */
+ public java.security.Permission getPermission() throws IOException {
+ return new java.security.AllPermission();
+ }
+
+ /**
+ * Answers the value corresponding to the field in the request Header, null
+ * if no such field exists.
+ *
+ * @param field
+ * the field to get the property for
+ * @return the field to look up
+ * @throws IllegalStateException -
+ * if connection already established
+ *
+ * @see #getDefaultRequestProperty
+ * @see #setDefaultRequestProperty
+ * @see #setRequestProperty
+ */
public String getRequestProperty(String field) {
if (connected) {
throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
@@ -667,356 +671,361 @@
return null;
}
- /**
- * Answers the <code>URL</code> of this connection
- *
- * @return the URL of this connection
- *
- * @see URL
- * @see #URLConnection(URL)
- */
- public URL getURL() {
- return url;
- }
-
- /**
- * Answers whether this connection uses caches
- *
- * @return the value of the flag
- */
- public boolean getUseCaches() {
- return useCaches;
- }
-
- /**
- * Determines the MIME type of the file specified by the
- * <code> string </code> URL, using the filename extension. Any fragment
- * identifier is removed before processing.
- *
- * @param url
- * the MIME type of the file.
- * @return the string representation of an URL
- *
- * @see FileNameMap
- * @see FileNameMap#getContentTypeFor(String)
- * @see #getContentType
- * @see #guessContentTypeFromStream
- *
- */
- public static String guessContentTypeFromName(String url) {
- return getFileNameMap().getContentTypeFor(url);
- }
-
- /**
- * Examines the bytes of the input stream and returns the MIME type, null if
- * no content type can be deduced.
- *
- * @param is
- * the input stream for the URL
- * @return the type of the input stream
- *
- * @throws IOException
- * If an IO error occurs
- */
- public static String guessContentTypeFromStream(InputStream is)
- throws IOException {
- if (!is.markSupported()) {
+ /**
+ * Answers the <code>URL</code> of this connection
+ *
+ * @return the URL of this connection
+ *
+ * @see URL
+ * @see #URLConnection(URL)
+ */
+ public URL getURL() {
+ return url;
+ }
+
+ /**
+ * Answers whether this connection uses caches
+ *
+ * @return the value of the flag
+ */
+ public boolean getUseCaches() {
+ return useCaches;
+ }
+
+ /**
+ * Determines the MIME type of the file specified by the
+ * <code> string </code> URL, using the filename extension. Any fragment
+ * identifier is removed before processing.
+ *
+ * @param url
+ * the MIME type of the file.
+ * @return the string representation of an URL
+ *
+ * @see FileNameMap
+ * @see FileNameMap#getContentTypeFor(String)
+ * @see #getContentType
+ * @see #guessContentTypeFromStream
+ *
+ */
+ public static String guessContentTypeFromName(String url) {
+ return getFileNameMap().getContentTypeFor(url);
+ }
+
+ /**
+ * Examines the bytes of the input stream and returns the MIME type, null if
+ * no content type can be deduced.
+ *
+ * @param is
+ * the input stream for the URL
+ * @return the type of the input stream
+ *
+ * @throws IOException
+ * If an IO error occurs
+ */
+ public static String guessContentTypeFromStream(InputStream is)
+ throws IOException {
+ if (!is.markSupported()) {
return null;
}
- is.mark(4);
- char[] chars = new char[4];
- for (int i = 0; i < chars.length; i++) {
+ 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";
- }
- if ((chars[0] == 'G') && (chars[1] == 'I')) {
- return "image/gif";
- }
- if (new String(chars).trim().startsWith("<")) {
- return "text/html";
- }
- return null;
- }
-
- /**
- * Performs any necessary string parsing on the input string such as
- * converting non-alphanumeric character into underscore.
- *
- * @param typeString
- * the parsed string
- * @return the string to be parsed
- */
- private String parseTypeString(String typeString) {
- 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 == '.')) {
+ 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;
+ }
+
+ /**
+ * Performs any necessary string parsing on the input string such as
+ * converting non-alphanumeric character into underscore.
+ *
+ * @param typeString
+ * the parsed string
+ * @return the string to be parsed
+ */
+ private String parseTypeString(String typeString) {
+ 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();
- }
-
- /**
- * Sets the flag indicating whether this connection allows user interaction
- * This can only be called prior to connection establishment.
- *
- * @param newValue
- * the value of the flag to be set
- *
- * @throws IllegalStateException
- * if this method attempts to change the flag after a connection
- * has been established
- */
- public void setAllowUserInteraction(boolean newValue) {
- if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
- }
- this.allowUserInteraction = newValue;
- }
-
- /**
- * Sets the current content handler factory to be
- * <code>contentFactory</code>. It can only do so with the permission of
- * the security manager. The ContentFactory can only be specified once
- * during the lifetime of an application.
- *
- * @param contentFactory
- * the factory
- *
- * @throws Error
- * if a ContentFactory has been created before SecurityException
- * if the security manager does not allow this action
- *
- * @see ContentHandler
- * @see ContentHandlerFactory
- * @see java.lang.SecurityException
- * @see java.lang.SecurityManager#checkSetFactory()
- */
- public static synchronized void setContentHandlerFactory(
- ContentHandlerFactory contentFactory) {
- if (contentHandlerFactory != null) {
- throw new Error(Msg.getString("K004e"));
}
- SecurityManager sManager = System.getSecurityManager();
- if (sManager != null) {
+ return typeStringBuffer.toString();
+ }
+
+ /**
+ * Sets the flag indicating whether this connection allows user interaction
+ * This can only be called prior to connection establishment.
+ *
+ * @param newValue
+ * the value of the flag to be set
+ *
+ * @throws IllegalStateException
+ * if this method attempts to change the flag after a connection
+ * has been established
+ */
+ public void setAllowUserInteraction(boolean newValue) {
+ if (connected) {
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
+ }
+ this.allowUserInteraction = newValue;
+ }
+
+ /**
+ * Sets the current content handler factory to be
+ * <code>contentFactory</code>. It can only do so with the permission of
+ * the security manager. The ContentFactory can only be specified once
+ * during the lifetime of an application.
+ *
+ * @param contentFactory
+ * the factory
+ *
+ * @throws Error
+ * if a ContentFactory has been created before SecurityException
+ * if the security manager does not allow this action
+ *
+ * @see ContentHandler
+ * @see ContentHandlerFactory
+ * @see java.lang.SecurityException
+ * @see java.lang.SecurityManager#checkSetFactory()
+ */
+ public static synchronized void setContentHandlerFactory(
+ ContentHandlerFactory contentFactory) {
+ if (contentHandlerFactory != null) {
+ throw new Error(Msg.getString("K004e")); //$NON-NLS-1$
+ }
+ SecurityManager sManager = System.getSecurityManager();
+ if (sManager != null) {
sManager.checkSetFactory();
}
- contentHandlerFactory = contentFactory;
- }
+ contentHandlerFactory = contentFactory;
+ }
- /**
- * Set whether user interaction is allowed by default. Existing
- * URLConnections are unaffected.
- *
- * @param allows
- * allow user interaction
- */
- public static void setDefaultAllowUserInteraction(boolean allows) {
- defaultAllowUserInteraction = allows;
- }
-
- /**
- * Sets the <code>field</code> in the default request header with the
- * value <code>value</code>
- *
- * @param field
- * the request header field to be set
- * @param value
- * the new value
- *
- * @deprecated Use getRequestProperty().
- */
- @Deprecated
+ /**
+ * Set whether user interaction is allowed by default. Existing
+ * URLConnections are unaffected.
+ *
+ * @param allows
+ * allow user interaction
+ */
+ public static void setDefaultAllowUserInteraction(boolean allows) {
+ defaultAllowUserInteraction = allows;
+ }
+
+ /**
+ * Sets the <code>field</code> in the default request header with the
+ * value <code>value</code>
+ *
+ * @param field
+ * the request header field to be set
+ * @param value
+ * the new value
+ *
+ * @deprecated Use getRequestProperty().
+ */
+ @Deprecated
public static void setDefaultRequestProperty(String field, String value) {
- }
+ }
+
+ /**
+ * Set whether caches are used by default. Existing URLConnections are
+ * unaffected.
+ *
+ * @param newValue
+ * the value of the flag to be set
+ *
+ * @see #getDefaultUseCaches
+ * @see #getUseCaches
+ * @see #setUseCaches
+ * @see #useCaches
+ */
+ public void setDefaultUseCaches(boolean newValue) {
+ if (connected) {
+ throw new IllegalAccessError(Msg.getString("K0037")); //$NON-NLS-1$
+ }
+ defaultUseCaches = newValue;
+ }
- /**
- * Set whether caches are used by default. Existing URLConnections are
- * unaffected.
- *
- * @param newValue
- * the value of the flag to be set
- *
- * @see #getDefaultUseCaches
- * @see #getUseCaches
- * @see #setUseCaches
- * @see #useCaches
- */
- public void setDefaultUseCaches(boolean newValue) {
- if (connected) {
- throw new IllegalAccessError(Msg.getString("K0037"));
- }
- defaultUseCaches = newValue;
- }
-
- /**
- * Sets whether this URLConnection allows input. It cannot be set after the
- * connection is made.
- *
- * @param newValue
- * boolean
- *
- * @throws IllegalAccessError
- * Exception thrown when this method attempts to change the
- * value after connected
- *
- * @see #doInput
- * @see #getDoInput
- * @see #setDoInput
- * @see java.lang.IllegalAccessError
- */
- public void setDoInput(boolean newValue) {
- if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
- }
- this.doInput = newValue;
- }
-
- /**
- * Sets whether this URLConnection allows output. It cannot be set after the
- * connection is made.
- *
- * @param newValue
- * boolean
- *
- * @throws IllegalAccessError
- * Exception thrown when this method attempts to change the
- * value after connected
- *
- * @see #doOutput
- * @see #getDoOutput
- * @see #setDoOutput
- * @see java.lang.IllegalAccessError
- */
- public void setDoOutput(boolean newValue) {
- if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
- }
- this.doOutput = newValue;
- }
-
- /**
- * With permission from the security manager, this method sets the
- * <code>map</code> to be the MIME Table of this URL connection.
- *
- * @param map
- * the MIME table to be set.
- */
- public static void setFileNameMap(FileNameMap map) {
- SecurityManager manager = System.getSecurityManager();
- if (manager != null) {
+ /**
+ * Sets whether this URLConnection allows input. It cannot be set after the
+ * connection is made.
+ *
+ * @param newValue
+ * boolean
+ *
+ * @throws IllegalAccessError
+ * Exception thrown when this method attempts to change the
+ * value after connected
+ *
+ * @see #doInput
+ * @see #getDoInput
+ * @see #setDoInput
+ * @see java.lang.IllegalAccessError
+ */
+ public void setDoInput(boolean newValue) {
+ if (connected) {
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
+ }
+ this.doInput = newValue;
+ }
+
+ /**
+ * Sets whether this URLConnection allows output. It cannot be set after the
+ * connection is made.
+ *
+ * @param newValue
+ * boolean
+ *
+ * @throws IllegalAccessError
+ * Exception thrown when this method attempts to change the
+ * value after connected
+ *
+ * @see #doOutput
+ * @see #getDoOutput
+ * @see #setDoOutput
+ * @see java.lang.IllegalAccessError
+ */
+ public void setDoOutput(boolean newValue) {
+ if (connected) {
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
+ }
+ this.doOutput = newValue;
+ }
+
+ /**
+ * With permission from the security manager, this method sets the
+ * <code>map</code> to be the MIME Table of this URL connection.
+ *
+ * @param map
+ * the MIME table to be set.
+ */
+ public static void setFileNameMap(FileNameMap map) {
+ SecurityManager manager = System.getSecurityManager();
+ if (manager != null) {
manager.checkSetFactory();
}
- fileNameMap = map;
- }
+ fileNameMap = map;
+ }
- /**
- * Sets the header field <code>ifModifiedSince</code>.
- *
- * @param newValue
- * number of milliseconds since epoch
- * @throws IllegalStateException if already connected.
- */
- public void setIfModifiedSince(long newValue) {
- if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
- }
- this.ifModifiedSince = newValue;
- }
-
- /**
- * Sets the value of the request header field <code> field </code> to
- * <code>newValue</code> Only the current URL Connection is affected. It
- * can only be called before the connection is made
- *
- * @param field
- * the field
- * @param newValue
- * the field's new value
- *
- * @throws IllegalStateException - if connection already established
- * @throws NullPointerException - if field is null
- *
- * @see #getDefaultRequestProperty
- * @see #setDefaultRequestProperty
- * @see #getRequestProperty
- */
- public void setRequestProperty(String field, String newValue) {
+ /**
+ * Sets the header field <code>ifModifiedSince</code>.
+ *
+ * @param newValue
+ * number of milliseconds since epoch
+ * @throws IllegalStateException
+ * if already connected.
+ */
+ public void setIfModifiedSince(long newValue) {
if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
+ }
+ this.ifModifiedSince = newValue;
+ }
+
+ /**
+ * Sets the value of the request header field <code> field </code> to
+ * <code>newValue</code> Only the current URL Connection is affected. It
+ * can only be called before the connection is made
+ *
+ * @param field
+ * the field
+ * @param newValue
+ * the field's new value
+ *
+ * @throws IllegalStateException -
+ * if connection already established
+ * @throws NullPointerException -
+ * if field is null
+ *
+ * @see #getDefaultRequestProperty
+ * @see #setDefaultRequestProperty
+ * @see #getRequestProperty
+ */
+ public void setRequestProperty(String field, String newValue) {
+ if (connected) {
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
}
if (field == null) {
- throw new NullPointerException(Msg.getString("KA007"));
+ throw new NullPointerException(Msg.getString("KA007")); //$NON-NLS-1$
}
- }
+ }
+
+ /**
+ * Sets the flag indicating if this connection uses caches. This value
+ * cannot be set after the connection is made.
+ *
+ * @param newValue
+ * the value of the flag to be set
+ *
+ * @throws IllegalStateException
+ * Exception thrown when this method attempts to change the
+ * value after connected
+ *
+ * @see #getDefaultUseCaches
+ * @see #setDefaultUseCaches
+ * @see #getUseCaches
+ * @see #useCaches
+ */
+ public void setUseCaches(boolean newValue) {
+ if (connected) {
+ throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$
+ }
+ this.useCaches = newValue;
+ }
- /**
- * Sets the flag indicating if this connection uses caches. This value
- * cannot be set after the connection is made.
- *
- * @param newValue
- * the value of the flag to be set
- *
- * @throws IllegalStateException
- * Exception thrown when this method attempts to change the
- * value after connected
- *
- * @see #getDefaultUseCaches
- * @see #setDefaultUseCaches
- * @see #getUseCaches
- * @see #useCaches
- */
- public void setUseCaches(boolean newValue) {
- if (connected) {
- throw new IllegalStateException(Msg.getString("K0037"));
- }
- this.useCaches = newValue;
- }
-
/**
* Sets a timeout for connection to perform non-block. Default is zero.
* Timeout of zero means infinite.
+ *
* @param timeout
* timeout for connection in milliseconds.
* @throws IllegalArgumentException
* if timeout is less than zero.
*/
- public void setConnectTimeout(int timeout){
- if (0 > timeout){
- throw new IllegalArgumentException(Msg.getString("K0036"));
+ public void setConnectTimeout(int timeout) {
+ if (0 > timeout) {
+ throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
}
this.connectTimeout = timeout;
}
-
+
/**
* Returns a timeout of connection by milliseconds
*
* @return timeout of connection by milliseconds
*/
- public int getConnectTimeout(){
+ public int getConnectTimeout() {
return connectTimeout;
}
-
+
/**
- * Sets a timeout for reading to perform non-block. Default is zero.
- * Timeout of zero means infinite.
+ * Sets a timeout for reading to perform non-block. Default is zero. Timeout
+ * of zero means infinite.
+ *
* @param timeout
* timeout for reading in milliseconds.
* @throws IllegalArgumentException
* if timeout is less than zero.
*/
- public void setReadTimeout(int timeout){
- if (0 > timeout){
- throw new IllegalArgumentException(Msg.getString("K0036"));
+ public void setReadTimeout(int timeout) {
+ if (0 > timeout) {
+ throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
}
this.readTimeout = timeout;
}
-
+
/**
* Returns a timeout of reading by milliseconds
*
@@ -1026,30 +1035,30 @@
return readTimeout;
}
- /**
- * Answers the name of the class of the <code>URLConnection </code>
- *
- * @return The string representation of this <code>URLConnection</code>
- *
- * @see #getURL
- * @see #URLConnection(URL)
- */
- @Override
+ /**
+ * Answers the name of the class of the <code>URLConnection </code>
+ *
+ * @return The string representation of this <code>URLConnection</code>
+ *
+ * @see #getURL
+ * @see #URLConnection(URL)
+ */
+ @Override
public String toString() {
- return getClass().getName() + ":" + url.toString();
- }
+ return getClass().getName() + ":" + url.toString(); //$NON-NLS-1$
+ }
- static class DefaultContentHandler extends java.net.ContentHandler {
+ static class DefaultContentHandler extends java.net.ContentHandler {
- /**
- * @param u
- * the URL connection
- *
- * @see java.net.ContentHandler#getContent(java.net.URLConnection)
- */
- @Override
+ /**
+ * @param u
+ * the URL connection
+ *
+ * @see java.net.ContentHandler#getContent(java.net.URLConnection)
+ */
+ @Override
public Object getContent(URLConnection u) throws IOException {
- return u.getInputStream();
- }
- }
+ return u.getInputStream();
+ }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java Fri Jan 5 06:44:04 2007
@@ -17,7 +17,6 @@
package java.net;
-
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
@@ -30,88 +29,88 @@
*/
public class URLDecoder {
- /**
- * Decodes the string argument which is assumed to be encoded in the
- * <code>x-www-form-urlencoded</code> MIME content type.
- * <p>
- * '+' will be converted to space, '%' and two following hex digit
- * characters are converted to the equivalent byte value. All other
- * characters are passed through unmodified.
- * <p>
- * e.g. "A+B+C %24%25" -> "A B C $%"
- *
- * @param s
- * java.lang.String The encoded string.
- * @return java.lang.String The decoded version.
- *
- * @deprecated use URLDecoder#decode(String, String) instead
- */
- @Deprecated
+ /**
+ * Decodes the string argument which is assumed to be encoded in the
+ * <code>x-www-form-urlencoded</code> MIME content type.
+ * <p>
+ * '+' will be converted to space, '%' and two following hex digit
+ * characters are converted to the equivalent byte value. All other
+ * characters are passed through unmodified.
+ * <p>
+ * e.g. "A+B+C %24%25" -> "A B C $%"
+ *
+ * @param s
+ * java.lang.String The encoded string.
+ * @return java.lang.String The decoded version.
+ *
+ * @deprecated use URLDecoder#decode(String, String) instead
+ */
+ @Deprecated
public static String decode(String s) {
- return Util.decode(s, true);
- }
+ return Util.decode(s, true);
+ }
+
+ /**
+ * Decodes the string argument which is assumed to be encoded in the
+ * <code>x-www-form-urlencoded</code> MIME content type using the
+ * specified encoding scheme.
+ * <p>
+ * '+' will be converted to space, '%' and two following hex digit
+ * characters are converted to the equivalent byte value. All other
+ * characters are passed through unmodified.
+ *
+ * <p>
+ * e.g. "A+B+C %24%25" -> "A B C $%"
+ *
+ * @param s
+ * java.lang.String The encoded string.
+ * @param enc
+ * java.lang.String The encoding scheme to use
+ * @return java.lang.String The decoded version.
+ */
+ public static String decode(String s, String enc)
+ throws UnsupportedEncodingException {
- /**
- * Decodes the string argument which is assumed to be encoded in the
- * <code>x-www-form-urlencoded</code> MIME content type using the
- * specified encoding scheme.
- * <p>
- * '+' will be converted to space, '%' and two following hex digit
- * characters are converted to the equivalent byte value. All other
- * characters are passed through unmodified.
- *
- * <p>
- * e.g. "A+B+C %24%25" -> "A B C $%"
- *
- * @param s
- * java.lang.String The encoded string.
- * @param enc
- * java.lang.String The encoding scheme to use
- * @return java.lang.String The decoded version.
- */
- public static String decode(String s, String enc)
- throws UnsupportedEncodingException {
-
- if (enc == null) {
- throw new NullPointerException();
- }
+ if (enc == null) {
+ throw new NullPointerException();
+ }
- // If the given encoding is an empty string throw an exception.
+ // If the given encoding is an empty string throw an exception.
if (enc.length() == 0) {
throw new UnsupportedEncodingException(Msg
- .getString("K00a5", "enc")); //$NON-NLS-1$
+ .getString("K00a5", "enc")); //$NON-NLS-1$ //$NON-NLS-2$
}
- StringBuffer result = new StringBuffer(s.length());
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- for (int i = 0; i < s.length();) {
- char c = s.charAt(i);
- if (c == '+') {
+ StringBuffer result = new StringBuffer(s.length());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ for (int i = 0; i < s.length();) {
+ char c = s.charAt(i);
+ if (c == '+') {
result.append(' ');
} else if (c == '%') {
- out.reset();
- do {
- if (i + 2 >= s.length()) {
+ out.reset();
+ do {
+ if (i + 2 >= s.length()) {
throw new IllegalArgumentException(Msg.getString(
- "K01fe", i));
+ "K01fe", i)); //$NON-NLS-1$
}
- int d1 = Character.digit(s.charAt(i + 1), 16);
- int d2 = Character.digit(s.charAt(i + 2), 16);
- if (d1 == -1 || d2 == -1) {
+ int d1 = Character.digit(s.charAt(i + 1), 16);
+ int d2 = Character.digit(s.charAt(i + 2), 16);
+ if (d1 == -1 || d2 == -1) {
throw new IllegalArgumentException(Msg.getString(
- "K01ff", s.substring(i, i + 3), String
- .valueOf(i)));
+ "K01ff", //$NON-NLS-1$
+ s.substring(i, i + 3), String.valueOf(i)));
}
- out.write((byte) ((d1 << 4) + d2));
- i += 3;
- } while (i < s.length() && s.charAt(i) == '%');
- result.append(out.toString(enc));
- continue;
- } else {
+ out.write((byte) ((d1 << 4) + d2));
+ i += 3;
+ } while (i < s.length() && s.charAt(i) == '%');
+ result.append(out.toString(enc));
+ continue;
+ } else {
result.append(c);
}
- i++;
- }
- return result.toString();
- }
+ i++;
+ }
+ return result.toString();
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java Fri Jan 5 06:44:04 2007
@@ -17,7 +17,6 @@
package java.net;
-
import java.io.UnsupportedEncodingException;
/**
@@ -25,115 +24,115 @@
* <code>application/x-www-form-urlencoded</code> MIME content type.
*/
public class URLEncoder {
- static final String digits = "0123456789ABCDEF";
- /**
- * Prevents this class from being instantiated.
- *
- */
- private URLEncoder() {
- }
-
- /**
- * This class contains a utility method for converting a string to the
- * format required by the <code>application/x-www-form-urlencoded</code>
- * MIME content type.
- * <p>
- * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
- * and characters '.', '-', '*', '_' are converted into their hexidecimal
- * value prepended by '%'.
- * <p>
- * For example: '#' -> %23
- * <p>
- * In addition, spaces are substituted by '+'
- *
- * @return java.lang.String the string to be converted
- * @param s
- * java.lang.String the converted string
- *
- * @deprecated use URLEncoder#encode(String, String) instead
- */
- @Deprecated
+ static final String digits = "0123456789ABCDEF"; //$NON-NLS-1$
+
+ /**
+ * Prevents this class from being instantiated.
+ */
+ private URLEncoder() {
+ }
+
+ /**
+ * This class contains a utility method for converting a string to the
+ * format required by the <code>application/x-www-form-urlencoded</code>
+ * MIME content type.
+ * <p>
+ * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
+ * and characters '.', '-', '*', '_' are converted into their hexidecimal
+ * value prepended by '%'.
+ * <p>
+ * For example: '#' -> %23
+ * <p>
+ * In addition, spaces are substituted by '+'
+ *
+ * @return java.lang.String the string to be converted
+ * @param s
+ * java.lang.String the converted string
+ *
+ * @deprecated use URLEncoder#encode(String, String) instead
+ */
+ @Deprecated
public static String encode(String s) {
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < s.length(); i++) {
- char ch = s.charAt(i);
- if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
- || (ch >= '0' && ch <= '9') || ".-*_".indexOf(ch) > -1) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < s.length(); i++) {
+ char ch = s.charAt(i);
+ if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
+ || (ch >= '0' && ch <= '9') || ".-*_".indexOf(ch) > -1) { //$NON-NLS-1$
buf.append(ch);
} else if (ch == ' ') {
buf.append('+');
} else {
- byte[] bytes = new String(new char[] { ch }).getBytes();
- for (int j = 0; j < bytes.length; j++) {
- buf.append('%');
- buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
- buf.append(digits.charAt(bytes[j] & 0xf));
- }
- }
- }
- return buf.toString();
- }
-
- /**
- * This class contains a utility method for converting a string to the
- * format required by the <code>application/x-www-form-urlencoded</code>
- * MIME content type.
- * <p>
- * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
- * and characters '.', '-', '*', '_' are converted into their hexadecimal
- * value prepended by '%'.
- * <p>
- * For example: '#' -> %23
- * <p>
- * In addition, spaces are substituted by '+'
- *
- * @return java.lang.String the string to be converted
- * @param s
- * java.lang.String the converted string
- */
- public static String encode(String s, String enc)
- throws UnsupportedEncodingException {
- if (s == null || enc == null) {
- throw new NullPointerException();
- }
- // check for UnsupportedEncodingException
- "".getBytes(enc);
-
- StringBuffer buf = new StringBuffer();
- int start = -1;
- for (int i = 0; i < s.length(); i++) {
- char ch = s.charAt(i);
- if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
- || (ch >= '0' && ch <= '9') || " .-*_".indexOf(ch) > -1) {
- if (start >= 0) {
- convert(s.substring(start, i), buf, enc);
- start = -1;
- }
- if (ch != ' ') {
- buf.append(ch);
- } else {
- buf.append('+');
- }
- } else {
- if (start < 0) {
- start = i;
- }
- }
- }
- if (start >= 0) {
- convert(s.substring(start, s.length()), buf, enc);
- }
- return buf.toString();
- }
-
- private static void convert(String s, StringBuffer buf, String enc)
- throws UnsupportedEncodingException {
- byte[] bytes = s.getBytes(enc);
- for (int j = 0; j < bytes.length; j++) {
- buf.append('%');
- buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
- buf.append(digits.charAt(bytes[j] & 0xf));
- }
- }
+ byte[] bytes = new String(new char[] { ch }).getBytes();
+ for (int j = 0; j < bytes.length; j++) {
+ buf.append('%');
+ buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
+ buf.append(digits.charAt(bytes[j] & 0xf));
+ }
+ }
+ }
+ return buf.toString();
+ }
+
+ /**
+ * This class contains a utility method for converting a string to the
+ * format required by the <code>application/x-www-form-urlencoded</code>
+ * MIME content type.
+ *
+ * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
+ * and characters '.', '-', '*', '_' are converted into their hexadecimal
+ * value prepended by '%'.
+ *
+ * For example: '#' -> %23
+ *
+ * In addition, spaces are substituted by '+'
+ *
+ * @param s
+ * the string to be converted
+ * @return the converted string
+ */
+ public static String encode(String s, String enc)
+ throws UnsupportedEncodingException {
+ if (s == null || enc == null) {
+ throw new NullPointerException();
+ }
+ // check for UnsupportedEncodingException
+ "".getBytes(enc); //$NON-NLS-1$
+
+ StringBuffer buf = new StringBuffer();
+ int start = -1;
+ for (int i = 0; i < s.length(); i++) {
+ char ch = s.charAt(i);
+ if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
+ || (ch >= '0' && ch <= '9') || " .-*_".indexOf(ch) > -1) { //$NON-NLS-1$
+ if (start >= 0) {
+ convert(s.substring(start, i), buf, enc);
+ start = -1;
+ }
+ if (ch != ' ') {
+ buf.append(ch);
+ } else {
+ buf.append('+');
+ }
+ } else {
+ if (start < 0) {
+ start = i;
+ }
+ }
+ }
+ if (start >= 0) {
+ convert(s.substring(start, s.length()), buf, enc);
+ }
+ return buf.toString();
+ }
+
+ private static void convert(String s, StringBuffer buf, String enc)
+ throws UnsupportedEncodingException {
+ byte[] bytes = s.getBytes(enc);
+ for (int j = 0; j < bytes.length; j++) {
+ buf.append('%');
+ buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
+ buf.append(digits.charAt(bytes[j] & 0xf));
+ }
+ }
}