kpouer commented on code in PR #271:
URL: https://github.com/apache/commons-imaging/pull/271#discussion_r1114983562


##########
src/test/java/org/apache/commons/imaging/roundtrip/NullParametersRoundtripTest.java:
##########
@@ -38,13 +38,17 @@ public static Stream<FormatInfo> data() {
     @MethodSource("data")
     public void testNullParametersRoundtrip(final FormatInfo formatInfo) 
throws Exception {
         final BufferedImage testImage = TestImages.createFullColorImage(1, 1);
-        final File temp1 = Files.createTempFile("nullParameters.", "." + 
formatInfo.format.getDefaultExtension()).toFile();
-        Imaging.writeImage(testImage, temp1, formatInfo.format);
-        Imaging.getImageInfo(temp1);
-        Imaging.getImageSize(temp1);
-        Imaging.getMetadata(temp1);
-        Imaging.getICCProfile(temp1);
-        final BufferedImage imageRead = Imaging.getBufferedImage(temp1);
+        final byte[] temp1;
+        try (ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream()) {
+            Imaging.writeImage(testImage, byteArrayOutputStream, 
formatInfo.format);
+            temp1 = byteArrayOutputStream.toByteArray();
+        }
+        final String filename = "nullParameters." + 
formatInfo.format.getDefaultExtension();
+        Imaging.getImageInfo(new ByteArrayInputStream(temp1), filename);
+        Imaging.getImageSize(new ByteArrayInputStream(temp1), filename);
+        Imaging.getMetadata(new ByteArrayInputStream(temp1), filename);
+        Imaging.getICCProfile(new ByteArrayInputStream(temp1), filename);

Review Comment:
   In fact we can reuse the same ByteArrayInputStream but the code is more 
verbose, and closing it has no effect (however it is useful for static analysis 
of IDE so they do not complains about it ;) )
   
   ```java
   try (ByteArrayInputStream bos = new ByteArrayInputStream(temp1)) {
               Imaging.getImageInfo(bos, filename);
               bos.reset();
               Imaging.getImageSize(bos, filename);
               bos.reset();
               Imaging.getMetadata(bos, filename);
               bos.reset();
               Imaging.getICCProfile(bos, filename);
               bos.reset();
               final BufferedImage imageRead = Imaging.getBufferedImage(bos, 
filename);
               bos.reset();
               assertNotNull(imageRead);
           }
   ```
   
   Another option is to use the methods taking directly a byte[] but it would 
require to create new methods also taking the filename as the file extension is 
sometimes used to help reading data (unfortunately some exists but the 
parameter order is not consistent, sometimes the filename comes first some 
other time it comes after)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to