3333import java .awt .image .WritableRaster ;
3434import java .io .File ;
3535import java .io .IOException ;
36+ import java .io .InputStream ;
3637import java .util .Hashtable ;
3738import java .util .Random ;
3839import javax .imageio .ImageIO ;
@@ -80,13 +81,13 @@ static void setUp()
8081 * Tests RGB LosslessFactoryTest#createFromImage(PDDocument document,
8182 * BufferedImage image)
8283 *
83- * @throws java.io. IOException
84+ * @throws IOException
8485 */
8586 @ Test
8687 void testCreateLosslessFromImageRGB () throws IOException
8788 {
8889 PDDocument document = new PDDocument ();
89- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
90+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
9091
9192 PDImageXObject ximage1 = LosslessFactory .createFromImage (document , image );
9293 validate (ximage1 , 8 , image .getWidth (), image .getHeight (), "png" , PDDeviceRGB .INSTANCE .getName ());
@@ -138,13 +139,13 @@ void testCreateLosslessFromImageRGB() throws IOException
138139 * Tests INT_ARGB LosslessFactoryTest#createFromImage(PDDocument document,
139140 * BufferedImage image)
140141 *
141- * @throws java.io. IOException
142+ * @throws IOException
142143 */
143144 @ Test
144145 void testCreateLosslessFromImageINT_ARGB () throws IOException
145146 {
146147 PDDocument document = new PDDocument ();
147- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
148+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
148149
149150 // create an ARGB image
150151 int w = image .getWidth ();
@@ -178,7 +179,7 @@ void testCreateLosslessFromImageINT_ARGB() throws IOException
178179 * Tests INT_ARGB LosslessFactoryTest#createFromImage(PDDocument document,
179180 * BufferedImage image) with BITMASK transparency
180181 *
181- * @throws java.io. IOException
182+ * @throws IOException
182183 */
183184 @ Test
184185 void testCreateLosslessFromImageBITMASK_INT_ARGB () throws IOException
@@ -190,7 +191,7 @@ void testCreateLosslessFromImageBITMASK_INT_ARGB() throws IOException
190191 * Tests 4BYTE_ABGR LosslessFactoryTest#createFromImage(PDDocument document,
191192 * BufferedImage image) with BITMASK transparency
192193 *
193- * @throws java.io. IOException
194+ * @throws IOException
194195 */
195196 @ Test
196197 void testCreateLosslessFromImageBITMASK4BYTE_ABGR () throws IOException
@@ -202,13 +203,13 @@ void testCreateLosslessFromImageBITMASK4BYTE_ABGR() throws IOException
202203 * Tests 4BYTE_ABGR LosslessFactoryTest#createFromImage(PDDocument document,
203204 * BufferedImage image)
204205 *
205- * @throws java.io. IOException
206+ * @throws IOException
206207 */
207208 @ Test
208209 void testCreateLosslessFromImage4BYTE_ABGR () throws IOException
209210 {
210211 PDDocument document = new PDDocument ();
211- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
212+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
212213
213214 // create an ARGB image
214215 int w = image .getWidth ();
@@ -253,13 +254,13 @@ void testCreateLosslessFromImage4BYTE_ABGR() throws IOException
253254 * image). This should create an 8-bit-image; prevent the problems from PDFBOX-4674 in case
254255 * image creation is modified in the future.
255256 *
256- * @throws java.io. IOException
257+ * @throws IOException
257258 */
258259 @ Test
259260 void testCreateLosslessFromImageUSHORT_555_RGB () throws IOException
260261 {
261262 PDDocument document = new PDDocument ();
262- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
263+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
263264
264265 // create an USHORT_555_RGB image
265266 int w = image .getWidth ();
@@ -292,13 +293,13 @@ void testCreateLosslessFromImageUSHORT_555_RGB() throws IOException
292293 * Tests LosslessFactoryTest#createFromImage(PDDocument document,
293294 * BufferedImage image) with transparent GIF
294295 *
295- * @throws java.io. IOException
296+ * @throws IOException
296297 */
297298 @ Test
298299 void testCreateLosslessFromTransparentGIF () throws IOException
299300 {
300301 PDDocument document = new PDDocument ();
301- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("gif.gif" ));
302+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("gif.gif" ));
302303
303304 assertEquals (Transparency .BITMASK , image .getColorModel ().getTransparency ());
304305
@@ -322,13 +323,13 @@ void testCreateLosslessFromTransparentGIF() throws IOException
322323 * BufferedImage image) with a transparent 1 bit GIF. (PDFBOX-4672)
323324 * This ends up as RGB because the 1 bit fast path doesn't support transparency.
324325 *
325- * @throws java.io. IOException
326+ * @throws IOException
326327 */
327328 @ Test
328329 void testCreateLosslessFromTransparent1BitGIF () throws IOException
329330 {
330331 PDDocument document = new PDDocument ();
331- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("gif-1bit-transparent.gif" ));
332+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("gif-1bit-transparent.gif" ));
332333
333334 assertEquals (Transparency .BITMASK , image .getColorModel ().getTransparency ());
334335 assertEquals (BufferedImage .TYPE_BYTE_BINARY , image .getType ());
@@ -351,7 +352,7 @@ void testCreateLosslessFromTransparent1BitGIF() throws IOException
351352 /**
352353 * Test file that had a predictor encoding bug in PDFBOX-4184.
353354 *
354- * @throws java.io. IOException
355+ * @throws IOException
355356 */
356357 @ Test
357358 void testCreateLosslessFromGovdocs032163 () throws IOException
@@ -561,10 +562,13 @@ private void doBitmaskTransparencyTest(int imageType, String pdfFilename) throws
561562 void testCreateLosslessFromImageCMYK () throws IOException
562563 {
563564 PDDocument document = new PDDocument ();
564- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
565+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
565566
566- final ColorSpace targetCS = new ICC_ColorSpace (ICC_Profile
567- .getInstance (this .getClass ().getResourceAsStream ("/org/apache/pdfbox/resources/icc/ISOcoated_v2_300_bas.icc" )));
567+ final ColorSpace targetCS ;
568+ try (InputStream is = this .getClass ().getResourceAsStream ("/org/apache/pdfbox/resources/icc/ISOcoated_v2_300_bas.icc" ))
569+ {
570+ targetCS = new ICC_ColorSpace (ICC_Profile .getInstance (is ));
571+ }
568572 ColorConvertOp op = new ColorConvertOp (image .getColorModel ().getColorSpace (), targetCS , null );
569573 BufferedImage imageCMYK = op .filter (image , null );
570574
@@ -581,7 +585,7 @@ void testCreateLosslessFromImageCMYK() throws IOException
581585 void testCreateLosslessFrom16Bit () throws IOException
582586 {
583587 PDDocument document = new PDDocument ();
584- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
588+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
585589
586590 ColorSpace targetCS = ColorSpace .getInstance (ColorSpace .CS_sRGB );
587591 int dataBufferType = DataBuffer .TYPE_USHORT ;
@@ -604,7 +608,7 @@ void testCreateLosslessFrom16Bit() throws IOException
604608 void testCreateLosslessFromImageINT_BGR () throws IOException
605609 {
606610 PDDocument document = new PDDocument ();
607- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
611+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
608612
609613 BufferedImage imgBgr = new BufferedImage (image .getWidth (), image .getHeight (), BufferedImage .TYPE_INT_BGR );
610614 Graphics2D graphics = imgBgr .createGraphics ();
@@ -619,7 +623,7 @@ void testCreateLosslessFromImageINT_BGR() throws IOException
619623 void testCreateLosslessFromImageINT_RGB () throws IOException
620624 {
621625 PDDocument document = new PDDocument ();
622- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
626+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
623627
624628 BufferedImage imgRgb = new BufferedImage (image .getWidth (), image .getHeight (), BufferedImage .TYPE_INT_RGB );
625629 Graphics2D graphics = imgRgb .createGraphics ();
@@ -634,7 +638,7 @@ void testCreateLosslessFromImageINT_RGB() throws IOException
634638 void testCreateLosslessFromImageBYTE_3BGR () throws IOException
635639 {
636640 PDDocument document = new PDDocument ();
637- BufferedImage image = ImageIO .read (this .getClass ().getResourceAsStream ("png.png" ));
641+ BufferedImage image = ImageIO .read (this .getClass ().getResource ("png.png" ));
638642
639643 BufferedImage imgRgb = new BufferedImage (image .getWidth (), image .getHeight (), BufferedImage .TYPE_3BYTE_BGR );
640644 Graphics2D graphics = imgRgb .createGraphics ();
0 commit comments