(String className, ClassLoader cl)
| 756 | |
| 757 | |
| 758 | @SuppressWarnings("null") // is cannot be null when used |
| 759 | private static String getSmap(String className, ClassLoader cl) { |
| 760 | Charset encoding = StandardCharsets.ISO_8859_1; |
| 761 | boolean found = false; |
| 762 | String smap = null; |
| 763 | |
| 764 | InputStream is = null; |
| 765 | try { |
| 766 | is = cl.getResourceAsStream(className.replace(".", "/") + ".smap"); |
| 767 | if (is != null) { |
| 768 | encoding = SMAP_ENCODING; |
| 769 | found = true; |
| 770 | } else { |
| 771 | is = cl.getResourceAsStream(className.replace(".", "/") + ".class"); |
| 772 | if (is != null) { |
| 773 | // Alternative approach would be to read the class file as per the |
| 774 | // JLS. That would require duplicating a lot of BCEL functionality. |
| 775 | int b = is.read(); |
| 776 | while (b != -1) { |
| 777 | if (b == 'S') { |
| 778 | if ((b = is.read()) != 'M') { |
| 779 | continue; |
| 780 | } |
| 781 | if ((b = is.read()) != 'A') { |
| 782 | continue; |
| 783 | } |
| 784 | if ((b = is.read()) != 'P') { |
| 785 | continue; |
| 786 | } |
| 787 | if ((b = is.read()) != '\n') { |
| 788 | continue; |
| 789 | } |
| 790 | found = true; |
| 791 | break; |
| 792 | } |
| 793 | b = is.read(); |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | if (found) { |
| 799 | ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); |
| 800 | byte[] buf = new byte[1024]; |
| 801 | int numRead; |
| 802 | while ((numRead = is.read(buf)) >= 0) { |
| 803 | baos.write(buf, 0, numRead); |
| 804 | } |
| 805 | |
| 806 | smap = baos.toString(encoding); |
| 807 | } |
| 808 | } catch (IOException ioe) { |
| 809 | Log log = LogFactory.getLog(SmapUtil.class); |
| 810 | log.warn(Localizer.getMessage("jsp.warning.loadSmap", className), ioe); |
| 811 | } finally { |
| 812 | if (is != null) { |
| 813 | try { |
| 814 | is.close(); |
| 815 | } catch (IOException ioe) { |
no test coverage detected