< prev index next >

src/java.base/share/classes/java/net/URLConnection.java

Print this page




1398                             }
1399                             handler = f.createContentHandler(contentType);
1400                             if (handler != null) {
1401                                 break;
1402                             }
1403                         }
1404                         return handler;
1405                     }
1406                 });
1407     }
1408 
1409     /**
1410      * Utility function to map a MIME content type into an equivalent
1411      * pair of class name components.  For example: "text/html" would
1412      * be returned as "text.html"
1413      */
1414     private String typeToPackageName(String contentType) {
1415         // make sure we canonicalize the class name: all lower case
1416         contentType = contentType.toLowerCase();
1417         int len = contentType.length();
1418         char nm[] = new char[len];
1419         contentType.getChars(0, len, nm, 0);
1420         for (int i = 0; i < len; i++) {
1421             char c = nm[i];
1422             if (c == '/') {
1423                 nm[i] = '.';
1424             } else if (!('A' <= c && c <= 'Z' ||
1425                        'a' <= c && c <= 'z' ||
1426                        '0' <= c && c <= '9')) {
1427                 nm[i] = '_';
1428             }
1429         }
1430         return new String(nm);
1431     }
1432 
1433 
1434     /**
1435      * Returns a vertical bar separated list of package prefixes for potential
1436      * content handlers.  Tries to get the java.content.handler.pkgs property
1437      * to use as a set of package prefixes to search.  Whether or not
1438      * that property has been defined, the {@value #contentClassPrefix}


1676          *                                     We will assume value of 0 (i.e.,
1677          *                                     rootEntry is in first directory)
1678          */
1679 
1680         // Mark the stream so we can reset it. 0x100 is enough for the first
1681         // few reads, but the mark will have to be reset and set again once
1682         // the offset to the root directory entry is computed. That offset
1683         // can be very large and isn't know until the stream has been read from
1684         is.mark(0x100);
1685 
1686         // Get the byte ordering located at 0x1E. 0xFE is Intel,
1687         // 0xFF is other
1688         long toSkip = (long)0x1C;
1689         long posn;
1690 
1691         if ((posn = skipForward(is, toSkip)) < toSkip) {
1692           is.reset();
1693           return false;
1694         }
1695 
1696         int c[] = new int[16];
1697         if (readBytes(c, 2, is) < 0) {
1698             is.reset();
1699             return false;
1700         }
1701 
1702         int byteOrder = c[0];
1703 
1704         posn+=2;
1705         int uSectorShift;
1706         if (readBytes(c, 2, is) < 0) {
1707             is.reset();
1708             return false;
1709         }
1710 
1711         if(byteOrder == 0xFE) {
1712             uSectorShift = c[0];
1713             uSectorShift += c[1] << 8;
1714         }
1715         else {
1716             uSectorShift = c[0] << 8;


1795         }
1796 
1797         // non-intel byte order
1798         else if (c[3] == 0x00 && c[1] == 0x61 && c[0] == 0x56 &&
1799             c[5] == 0x54 && c[4] == 0xC1 && c[7] == 0xCE &&
1800             c[6] == 0x11 && c[8] == 0x85 && c[9] == 0x53 &&
1801             c[10]== 0x00 && c[11]== 0xAA && c[12]== 0x00 &&
1802             c[13]== 0xA1 && c[14]== 0xF9 && c[15]== 0x5B) {
1803             is.reset();
1804             return true;
1805         }
1806         is.reset();
1807         return false;
1808     }
1809 
1810     /**
1811      * Tries to read the specified number of bytes from the stream
1812      * Returns -1, If EOF is reached before len bytes are read, returns 0
1813      * otherwise
1814      */
1815     private static int readBytes(int c[], int len, InputStream is)
1816                 throws IOException {
1817 
1818         byte buf[] = new byte[len];
1819         if (is.read(buf, 0, len) < len) {
1820             return -1;
1821         }
1822 
1823         // fill the passed in int array
1824         for (int i = 0; i < len; i++) {
1825              c[i] = buf[i] & 0xff;
1826         }
1827         return 0;
1828     }
1829 
1830 
1831     /**
1832      * Skips through the specified number of bytes from the stream
1833      * until either EOF is reached, or the specified
1834      * number of bytes have been skipped
1835      */
1836     private static long skipForward(InputStream is, long toSkip)
1837                 throws IOException {
1838 




1398                             }
1399                             handler = f.createContentHandler(contentType);
1400                             if (handler != null) {
1401                                 break;
1402                             }
1403                         }
1404                         return handler;
1405                     }
1406                 });
1407     }
1408 
1409     /**
1410      * Utility function to map a MIME content type into an equivalent
1411      * pair of class name components.  For example: "text/html" would
1412      * be returned as "text.html"
1413      */
1414     private String typeToPackageName(String contentType) {
1415         // make sure we canonicalize the class name: all lower case
1416         contentType = contentType.toLowerCase();
1417         int len = contentType.length();
1418         char[] nm = new char[len];
1419         contentType.getChars(0, len, nm, 0);
1420         for (int i = 0; i < len; i++) {
1421             char c = nm[i];
1422             if (c == '/') {
1423                 nm[i] = '.';
1424             } else if (!('A' <= c && c <= 'Z' ||
1425                        'a' <= c && c <= 'z' ||
1426                        '0' <= c && c <= '9')) {
1427                 nm[i] = '_';
1428             }
1429         }
1430         return new String(nm);
1431     }
1432 
1433 
1434     /**
1435      * Returns a vertical bar separated list of package prefixes for potential
1436      * content handlers.  Tries to get the java.content.handler.pkgs property
1437      * to use as a set of package prefixes to search.  Whether or not
1438      * that property has been defined, the {@value #contentClassPrefix}


1676          *                                     We will assume value of 0 (i.e.,
1677          *                                     rootEntry is in first directory)
1678          */
1679 
1680         // Mark the stream so we can reset it. 0x100 is enough for the first
1681         // few reads, but the mark will have to be reset and set again once
1682         // the offset to the root directory entry is computed. That offset
1683         // can be very large and isn't know until the stream has been read from
1684         is.mark(0x100);
1685 
1686         // Get the byte ordering located at 0x1E. 0xFE is Intel,
1687         // 0xFF is other
1688         long toSkip = (long)0x1C;
1689         long posn;
1690 
1691         if ((posn = skipForward(is, toSkip)) < toSkip) {
1692           is.reset();
1693           return false;
1694         }
1695 
1696         int[] c = new int[16];
1697         if (readBytes(c, 2, is) < 0) {
1698             is.reset();
1699             return false;
1700         }
1701 
1702         int byteOrder = c[0];
1703 
1704         posn+=2;
1705         int uSectorShift;
1706         if (readBytes(c, 2, is) < 0) {
1707             is.reset();
1708             return false;
1709         }
1710 
1711         if(byteOrder == 0xFE) {
1712             uSectorShift = c[0];
1713             uSectorShift += c[1] << 8;
1714         }
1715         else {
1716             uSectorShift = c[0] << 8;


1795         }
1796 
1797         // non-intel byte order
1798         else if (c[3] == 0x00 && c[1] == 0x61 && c[0] == 0x56 &&
1799             c[5] == 0x54 && c[4] == 0xC1 && c[7] == 0xCE &&
1800             c[6] == 0x11 && c[8] == 0x85 && c[9] == 0x53 &&
1801             c[10]== 0x00 && c[11]== 0xAA && c[12]== 0x00 &&
1802             c[13]== 0xA1 && c[14]== 0xF9 && c[15]== 0x5B) {
1803             is.reset();
1804             return true;
1805         }
1806         is.reset();
1807         return false;
1808     }
1809 
1810     /**
1811      * Tries to read the specified number of bytes from the stream
1812      * Returns -1, If EOF is reached before len bytes are read, returns 0
1813      * otherwise
1814      */
1815     private static int readBytes(int[] c, int len, InputStream is)
1816                 throws IOException {
1817 
1818         byte[] buf = new byte[len];
1819         if (is.read(buf, 0, len) < len) {
1820             return -1;
1821         }
1822 
1823         // fill the passed in int array
1824         for (int i = 0; i < len; i++) {
1825              c[i] = buf[i] & 0xff;
1826         }
1827         return 0;
1828     }
1829 
1830 
1831     /**
1832      * Skips through the specified number of bytes from the stream
1833      * until either EOF is reached, or the specified
1834      * number of bytes have been skipped
1835      */
1836     private static long skipForward(InputStream is, long toSkip)
1837                 throws IOException {
1838 


< prev index next >