| | 98 | if(uri.toString().indexOf("resource:")>-1) { |
| | 99 | BufferedInputStream bis = null; |
| | 100 | ByteArrayOutputStream baos = null; |
| | 101 | try { |
| | 102 | bis = new BufferedInputStream(PDFUtils.class.getResourceAsStream(uri.toString().substring("resource:".length()))); |
| | 103 | baos = new ByteArrayOutputStream(); |
| | 104 | byte[] data = new byte[1024]; |
| | 105 | int tmp = bis.read(data); |
| | 106 | while(tmp != -1) { |
| | 107 | baos.write(data, 0, tmp); |
| | 108 | tmp = bis.read(data); |
| | 109 | } |
| | 110 | Image image = Image.getInstance(baos.toByteArray()); |
| | 111 | return image; |
| | 112 | } catch (DocumentException e) { |
| | 113 | LOGGER.warn("Couldn't generate a transparent image"); |
| | 114 | throw e; |
| | 115 | } |
| | 116 | finally { |
| | 117 | if(bis != null) { |
| | 118 | bis.close(); |
| | 119 | } |
| | 120 | if(baos != null) { |
| | 121 | baos.close(); |
| | 122 | } |
| | 123 | } |
| | 124 | } |