|
32 | 32 | import java.io.InputStream; |
33 | 33 | import java.io.OutputStream; |
34 | 34 | import java.util.Collections; |
| 35 | +import java.util.Date; |
35 | 36 | import java.util.List; |
36 | 37 | import java.util.Map; |
37 | 38 |
|
@@ -1444,183 +1445,183 @@ public int getReadTimeout() { |
1444 | 1445 |
|
1445 | 1446 |
|
1446 | 1447 |
|
1447 | | -// /** |
1448 | | -// * Returns the value of the <code>content-length</code> header field. |
1449 | | -// * |
1450 | | -// * @return the content length of the resource that this connection's URL |
1451 | | -// * references, or <code>-1</code> if the content length is |
1452 | | -// * not known. |
1453 | | -// */ |
1454 | | -// public int getContentLength() { |
1455 | | -// return getHeaderFieldInt("content-length", -1); |
1456 | | -// } |
1457 | | -// |
1458 | | -// /** |
1459 | | -// * Returns the value of the <code>content-type</code> header field. |
1460 | | -// * |
1461 | | -// * @return the content type of the resource that the URL references, |
1462 | | -// * or <code>null</code> if not known. |
1463 | | -// * @see java.net.URLConnection#getHeaderField(java.lang.String) |
1464 | | -// */ |
1465 | | -// public String getContentType() { |
1466 | | -// return getHeaderField("content-type"); |
1467 | | -// } |
1468 | | -// |
1469 | | -// /** |
1470 | | -// * Returns the value of the <code>content-encoding</code> header field. |
1471 | | -// * |
1472 | | -// * @return the content encoding of the resource that the URL references, |
1473 | | -// * or <code>null</code> if not known. |
1474 | | -// * @see java.net.URLConnection#getHeaderField(java.lang.String) |
1475 | | -// */ |
1476 | | -// public String getContentEncoding() { |
1477 | | -// return getHeaderField("content-encoding"); |
1478 | | -// } |
1479 | | -// |
1480 | | -// /** |
1481 | | -// * Returns the value of the <code>expires</code> header field. |
1482 | | -// * |
1483 | | -// * @return the expiration date of the resource that this URL references, |
1484 | | -// * or 0 if not known. The value is the number of milliseconds since |
1485 | | -// * January 1, 1970 GMT. |
1486 | | -// * @see java.net.URLConnection#getHeaderField(java.lang.String) |
1487 | | -// */ |
1488 | | -// public long getExpiration() { |
1489 | | -// return getHeaderFieldDate("expires", 0); |
1490 | | -// } |
1491 | | -// |
1492 | | -// /** |
1493 | | -// * Returns the value of the <code>date</code> header field. |
1494 | | -// * |
1495 | | -// * @return the sending date of the resource that the URL references, |
1496 | | -// * or <code>0</code> if not known. The value returned is the |
1497 | | -// * number of milliseconds since January 1, 1970 GMT. |
1498 | | -// * @see java.net.URLConnection#getHeaderField(java.lang.String) |
1499 | | -// */ |
1500 | | -// public long getDate() { |
1501 | | -// return getHeaderFieldDate("date", 0); |
1502 | | -// } |
1503 | | -// |
1504 | | -// /** |
1505 | | -// * Returns the value of the <code>last-modified</code> header field. |
1506 | | -// * The result is the number of milliseconds since January 1, 1970 GMT. |
1507 | | -// * |
1508 | | -// * @return the date the resource referenced by this |
1509 | | -// * <code>URLConnection</code> was last modified, or 0 if not known. |
1510 | | -// * @see java.net.URLConnection#getHeaderField(java.lang.String) |
1511 | | -// */ |
1512 | | -// public long getLastModified() { |
1513 | | -// return getHeaderFieldDate("last-modified", 0); |
1514 | | -// } |
1515 | | -// |
1516 | | -// /** |
1517 | | -// * Returns the value of the named header field. |
1518 | | -// * <p> |
1519 | | -// * If called on a connection that sets the same header multiple times |
1520 | | -// * with possibly different values, only the last value is returned. |
1521 | | -// * |
1522 | | -// * |
1523 | | -// * @param name the name of a header field. |
1524 | | -// * @return the value of the named header field, or <code>null</code> |
1525 | | -// * if there is no such field in the header. |
1526 | | -// */ |
1527 | | -// public String getHeaderField(String name) { |
1528 | | -// return null; |
1529 | | -// } |
1530 | | -// |
1531 | | -// /** |
1532 | | -// * Returns an unmodifiable Map of the header fields. |
1533 | | -// * The Map keys are Strings that represent the |
1534 | | -// * response-header field names. Each Map value is an |
1535 | | -// * unmodifiable List of Strings that represents |
1536 | | -// * the corresponding field values. |
1537 | | -// * |
1538 | | -// * @return a Map of header fields |
1539 | | -// * @since 1.4 |
1540 | | -// */ |
1541 | | -// public Map<String,List<String>> getHeaderFields() { |
1542 | | -// return Collections.EMPTY_MAP; |
1543 | | -// } |
1544 | | -// |
1545 | | -// /** |
1546 | | -// * Returns the value of the named field parsed as a number. |
1547 | | -// * <p> |
1548 | | -// * This form of <code>getHeaderField</code> exists because some |
1549 | | -// * connection types (e.g., <code>http-ng</code>) have pre-parsed |
1550 | | -// * headers. Classes for that connection type can override this method |
1551 | | -// * and short-circuit the parsing. |
1552 | | -// * |
1553 | | -// * @param name the name of the header field. |
1554 | | -// * @param Default the default value. |
1555 | | -// * @return the value of the named field, parsed as an integer. The |
1556 | | -// * <code>Default</code> value is returned if the field is |
1557 | | -// * missing or malformed. |
1558 | | -// */ |
1559 | | -// public int getHeaderFieldInt(String name, int Default) { |
1560 | | -// String value = getHeaderField(name); |
1561 | | -// try { |
1562 | | -// return Integer.parseInt(value); |
1563 | | -// } catch (Exception e) { } |
1564 | | -// return Default; |
1565 | | -// } |
1566 | | -// |
1567 | | -// /** |
1568 | | -// * Returns the value of the named field parsed as date. |
1569 | | -// * The result is the number of milliseconds since January 1, 1970 GMT |
1570 | | -// * represented by the named field. |
1571 | | -// * <p> |
1572 | | -// * This form of <code>getHeaderField</code> exists because some |
1573 | | -// * connection types (e.g., <code>http-ng</code>) have pre-parsed |
1574 | | -// * headers. Classes for that connection type can override this method |
1575 | | -// * and short-circuit the parsing. |
1576 | | -// * |
1577 | | -// * @param name the name of the header field. |
1578 | | -// * @param Default a default value. |
1579 | | -// * @return the value of the field, parsed as a date. The value of the |
1580 | | -// * <code>Default</code> argument is returned if the field is |
1581 | | -// * missing or malformed. |
1582 | | -// */ |
1583 | | -// public long getHeaderFieldDate(String name, long Default) { |
1584 | | -// String value = getHeaderField(name); |
1585 | | -// try { |
1586 | | -// return Date.parse(value); |
1587 | | -// } catch (Exception e) { } |
1588 | | -// return Default; |
1589 | | -// } |
1590 | | -// |
1591 | | -// /** |
1592 | | -// * Returns the key for the <code>n</code><sup>th</sup> header field. |
1593 | | -// * It returns <code>null</code> if there are fewer than <code>n+1</code> |
1594 | | -// fields. |
1595 | | -// * |
1596 | | -// * @param n an index, where n>=0 |
1597 | | -// * @return the key for the <code>n</code><sup>th</sup> header field, |
1598 | | -// * or <code>null</code> if there are fewer than <code>n+1</code> |
1599 | | -// * fields. |
1600 | | -// */ |
1601 | | -// public String getHeaderFieldKey(int n) { |
1602 | | -// return null; |
1603 | | -// } |
1604 | | -// |
1605 | | -// /** |
1606 | | -// * Returns the value for the <code>n</code><sup>th</sup> header field. |
1607 | | -// * It returns <code>null</code> if there are fewer than |
1608 | | -// * <code>n+1</code>fields. |
1609 | | -// * <p> |
1610 | | -// * This method can be used in conjunction with the |
1611 | | -// * {@link #getHeaderFieldKey(int) getHeaderFieldKey} method to iterate through |
1612 | | -// all |
1613 | | -// * the headers in the message. |
1614 | | -// * |
1615 | | -// * @param n an index, where n>=0 |
1616 | | -// * @return the value of the <code>n</code><sup>th</sup> header field |
1617 | | -// * or <code>null</code> if there are fewer than <code>n+1</code> fields |
1618 | | -// * @see java.net.URLConnection#getHeaderFieldKey(int) |
1619 | | -// */ |
1620 | | -// public String getHeaderField(int n) { |
1621 | | -// return null; |
1622 | | -// } |
1623 | | -// |
| 1448 | + /** |
| 1449 | + * Returns the value of the <code>content-length</code> header field. |
| 1450 | + * |
| 1451 | + * @return the content length of the resource that this connection's URL |
| 1452 | + * references, or <code>-1</code> if the content length is |
| 1453 | + * not known. |
| 1454 | + */ |
| 1455 | + public int getContentLength() { |
| 1456 | + return getHeaderFieldInt("content-length", -1); |
| 1457 | + } |
| 1458 | + |
| 1459 | + /** |
| 1460 | + * Returns the value of the <code>content-type</code> header field. |
| 1461 | + * |
| 1462 | + * @return the content type of the resource that the URL references, |
| 1463 | + * or <code>null</code> if not known. |
| 1464 | + * @see java.net.URLConnection#getHeaderField(java.lang.String) |
| 1465 | + */ |
| 1466 | + public String getContentType() { |
| 1467 | + return getHeaderField("content-type"); |
| 1468 | + } |
| 1469 | + |
| 1470 | + /** |
| 1471 | + * Returns the value of the <code>content-encoding</code> header field. |
| 1472 | + * |
| 1473 | + * @return the content encoding of the resource that the URL references, |
| 1474 | + * or <code>null</code> if not known. |
| 1475 | + * @see java.net.URLConnection#getHeaderField(java.lang.String) |
| 1476 | + */ |
| 1477 | + public String getContentEncoding() { |
| 1478 | + return getHeaderField("content-encoding"); |
| 1479 | + } |
| 1480 | + |
| 1481 | + /** |
| 1482 | + * Returns the value of the <code>expires</code> header field. |
| 1483 | + * |
| 1484 | + * @return the expiration date of the resource that this URL references, |
| 1485 | + * or 0 if not known. The value is the number of milliseconds since |
| 1486 | + * January 1, 1970 GMT. |
| 1487 | + * @see java.net.URLConnection#getHeaderField(java.lang.String) |
| 1488 | + */ |
| 1489 | + public long getExpiration() { |
| 1490 | + return getHeaderFieldDate("expires", 0); |
| 1491 | + } |
| 1492 | + |
| 1493 | + /** |
| 1494 | + * Returns the value of the <code>date</code> header field. |
| 1495 | + * |
| 1496 | + * @return the sending date of the resource that the URL references, |
| 1497 | + * or <code>0</code> if not known. The value returned is the |
| 1498 | + * number of milliseconds since January 1, 1970 GMT. |
| 1499 | + * @see java.net.URLConnection#getHeaderField(java.lang.String) |
| 1500 | + */ |
| 1501 | + public long getDate() { |
| 1502 | + return getHeaderFieldDate("date", 0); |
| 1503 | + } |
| 1504 | + |
| 1505 | + /** |
| 1506 | + * Returns the value of the <code>last-modified</code> header field. |
| 1507 | + * The result is the number of milliseconds since January 1, 1970 GMT. |
| 1508 | + * |
| 1509 | + * @return the date the resource referenced by this |
| 1510 | + * <code>URLConnection</code> was last modified, or 0 if not known. |
| 1511 | + * @see java.net.URLConnection#getHeaderField(java.lang.String) |
| 1512 | + */ |
| 1513 | + public long getLastModified() { |
| 1514 | + return getHeaderFieldDate("last-modified", 0); |
| 1515 | + } |
| 1516 | + |
| 1517 | + /** |
| 1518 | + * Returns the value of the named header field. |
| 1519 | + * <p> |
| 1520 | + * If called on a connection that sets the same header multiple times |
| 1521 | + * with possibly different values, only the last value is returned. |
| 1522 | + * |
| 1523 | + * |
| 1524 | + * @param name the name of a header field. |
| 1525 | + * @return the value of the named header field, or <code>null</code> |
| 1526 | + * if there is no such field in the header. |
| 1527 | + */ |
| 1528 | + public String getHeaderField(String name) { |
| 1529 | + return null; |
| 1530 | + } |
| 1531 | + |
| 1532 | + /** |
| 1533 | + * Returns an unmodifiable Map of the header fields. |
| 1534 | + * The Map keys are Strings that represent the |
| 1535 | + * response-header field names. Each Map value is an |
| 1536 | + * unmodifiable List of Strings that represents |
| 1537 | + * the corresponding field values. |
| 1538 | + * |
| 1539 | + * @return a Map of header fields |
| 1540 | + * @since 1.4 |
| 1541 | + */ |
| 1542 | + public Map<String,List<String>> getHeaderFields() { |
| 1543 | + return Collections.EMPTY_MAP; |
| 1544 | + } |
| 1545 | + |
| 1546 | + /** |
| 1547 | + * Returns the value of the named field parsed as a number. |
| 1548 | + * <p> |
| 1549 | + * This form of <code>getHeaderField</code> exists because some |
| 1550 | + * connection types (e.g., <code>http-ng</code>) have pre-parsed |
| 1551 | + * headers. Classes for that connection type can override this method |
| 1552 | + * and short-circuit the parsing. |
| 1553 | + * |
| 1554 | + * @param name the name of the header field. |
| 1555 | + * @param Default the default value. |
| 1556 | + * @return the value of the named field, parsed as an integer. The |
| 1557 | + * <code>Default</code> value is returned if the field is |
| 1558 | + * missing or malformed. |
| 1559 | + */ |
| 1560 | + public int getHeaderFieldInt(String name, int Default) { |
| 1561 | + String value = getHeaderField(name); |
| 1562 | + try { |
| 1563 | + return Integer.parseInt(value); |
| 1564 | + } catch (Exception e) { } |
| 1565 | + return Default; |
| 1566 | + } |
| 1567 | + |
| 1568 | + /** |
| 1569 | + * Returns the value of the named field parsed as date. |
| 1570 | + * The result is the number of milliseconds since January 1, 1970 GMT |
| 1571 | + * represented by the named field. |
| 1572 | + * <p> |
| 1573 | + * This form of <code>getHeaderField</code> exists because some |
| 1574 | + * connection types (e.g., <code>http-ng</code>) have pre-parsed |
| 1575 | + * headers. Classes for that connection type can override this method |
| 1576 | + * and short-circuit the parsing. |
| 1577 | + * |
| 1578 | + * @param name the name of the header field. |
| 1579 | + * @param Default a default value. |
| 1580 | + * @return the value of the field, parsed as a date. The value of the |
| 1581 | + * <code>Default</code> argument is returned if the field is |
| 1582 | + * missing or malformed. |
| 1583 | + */ |
| 1584 | + public long getHeaderFieldDate(String name, long Default) { |
| 1585 | + String value = getHeaderField(name); |
| 1586 | + try { |
| 1587 | + return Date.parse(value); |
| 1588 | + } catch (Exception e) { } |
| 1589 | + return Default; |
| 1590 | + } |
| 1591 | + |
| 1592 | + /** |
| 1593 | + * Returns the key for the <code>n</code><sup>th</sup> header field. |
| 1594 | + * It returns <code>null</code> if there are fewer than <code>n+1</code> |
| 1595 | + fields. |
| 1596 | + * |
| 1597 | + * @param n an index, where n>=0 |
| 1598 | + * @return the key for the <code>n</code><sup>th</sup> header field, |
| 1599 | + * or <code>null</code> if there are fewer than <code>n+1</code> |
| 1600 | + * fields. |
| 1601 | + */ |
| 1602 | + public String getHeaderFieldKey(int n) { |
| 1603 | + return null; |
| 1604 | + } |
| 1605 | + |
| 1606 | + /** |
| 1607 | + * Returns the value for the <code>n</code><sup>th</sup> header field. |
| 1608 | + * It returns <code>null</code> if there are fewer than |
| 1609 | + * <code>n+1</code>fields. |
| 1610 | + * <p> |
| 1611 | + * This method can be used in conjunction with the |
| 1612 | + * {@link #getHeaderFieldKey(int) getHeaderFieldKey} method to iterate through |
| 1613 | + all |
| 1614 | + * the headers in the message. |
| 1615 | + * |
| 1616 | + * @param n an index, where n>=0 |
| 1617 | + * @return the value of the <code>n</code><sup>th</sup> header field |
| 1618 | + * or <code>null</code> if there are fewer than <code>n+1</code> fields |
| 1619 | + * @see java.net.URLConnection#getHeaderFieldKey(int) |
| 1620 | + */ |
| 1621 | + public String getHeaderField(int n) { |
| 1622 | + return null; |
| 1623 | + } |
| 1624 | + |
1624 | 1625 | // /** |
1625 | 1626 | // * Retrieves the contents of this URL connection. |
1626 | 1627 | // * <p> |
|
0 commit comments