Skip to content

Commit

Permalink
Fix image validation #262
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Nov 19, 2024
1 parent 2653cfb commit 327c041
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.fugerit.java.doc.val.core.basic;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -11,7 +10,6 @@
import javax.imageio.stream.ImageInputStream;

import org.fugerit.java.core.lang.helpers.JavaVersionHelper;
import org.fugerit.java.core.util.result.Result;
import org.fugerit.java.doc.val.core.DocTypeValidationResult;
import org.fugerit.java.doc.val.core.DocTypeValidator;

Expand Down Expand Up @@ -54,23 +52,19 @@ public static boolean javaVersionSupportHelper( int javaMajorVersionFound, int j
private int javaMajorVersionRequired;

@Override
public DocTypeValidationResult validate(InputStream is) throws IOException {
DocTypeValidationResult result = DocTypeValidationResult.newFail();
public DocTypeValidationResult validate(InputStream is) {
try ( ImageInputStream iis = ImageIO.createImageInputStream( is ) ) {
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName( this.format );
while (readers.hasNext()) {
try {
ImageReader reader = readers.next();
reader.setInput(iis);
reader.read(0);
result.setResultCode( Result.RESULT_CODE_OK );
break;
} catch (IOException exp) {
log.debug( "checkImage {}", exp.getMessage() );
}
}
ImageReader reader = readers.next();
reader.setInput(iis);
reader.read(0);
return DocTypeValidationResult.newOk();
}
} catch (Exception exp) {
log.debug( "checkImage (v2) {}", exp.getMessage() );
}
return result;
return DocTypeValidationResult.newFail();
}

protected ImageValidator(String mimeType, Set<String> supportedExtensions, String format, int javaMajorVersionRequired) {
Expand Down

0 comments on commit 327c041

Please sign in to comment.