summaryrefslogtreecommitdiffstats
path: root/libjava/java/net/URLConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/net/URLConnection.java')
-rw-r--r--libjava/java/net/URLConnection.java44
1 files changed, 24 insertions, 20 deletions
diff --git a/libjava/java/net/URLConnection.java b/libjava/java/net/URLConnection.java
index 7d2ab44f6c5..3b8a85be139 100644
--- a/libjava/java/net/URLConnection.java
+++ b/libjava/java/net/URLConnection.java
@@ -331,20 +331,19 @@ public abstract class URLConnection
*/
public int getHeaderFieldInt(String name, int defaultValue)
{
- String str = getHeaderField(name);
- int result = defaultValue;
+ String value = getHeaderField (name);
+ if (value == null)
+ return defaultValue;
+
try
{
- if (str != null)
- result = Integer.parseInt (str);
+ return Integer.parseInt (value);
}
catch (NumberFormatException e)
{
- ; // Do nothing; defaultValue is the default.
+ return defaultValue;
}
-
- return result;
}
/**
@@ -353,27 +352,32 @@ public abstract class URLConnection
* value if the field is not present or cannot be converted to a date.
*
* @param name The name of the header field
- * @param val The dafault date
+ * @param defaultValue The default date if the header field is not found
+ * or can't be converted.
*
* @return Returns the date value of the header filed or the default value
* if the field is missing or malformed
*/
- public long getHeaderFieldDate(String name, long val)
+ public long getHeaderFieldDate (String name, long defaultValue)
{
if (! dateformats_initialized)
- initializeDateFormats();
- String str = getHeaderField(name);
+ initializeDateFormats ();
+
+ long result = defaultValue;
+ String str = getHeaderField (name);
+
if (str != null)
{
- Date date;
- if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)
- val = date.getTime();
- else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)
- val = date.getTime();
- else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)
- val = date.getTime();
+ Date date;
+ if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null)
+ result = date.getTime ();
+ else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null)
+ result = date.getTime ();
+ else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null)
+ result = date.getTime ();
}
- return val;
+
+ return result;
}
/**
@@ -387,7 +391,7 @@ public abstract class URLConnection
* @return The header field key or null if index is past the end
* of the headers.
*/
- public String getHeaderFieldKey(int index)
+ public String getHeaderFieldKey (int index)
{
// Subclasses for specific protocols override this.
return null;
OpenPOWER on IntegriCloud