drewnoakes / metadata-extractor

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Apache License 2.0
2.56k stars 480 forks source link

About FileTypeDetector.detectFileType : wrong input type paramater #424

Closed eleduc closed 5 years ago

eleduc commented 5 years ago

Why the inputStream parameter for the static method FileTypeDetector.detectFileType should be a BufferedInputStream and not a FilterInputStream ? The mark / reset mechanism is supported by the FilterInputStream implementation and due to the use of BufferedInputStream, it is not possible to use a derived class from FilterInputStream. As a consequence, we have to wrap any FilterInputStream instance within a new BufferedInputStream instance in order to be able to use this method. Moreover, we have to mark and reset the wrapped FilterInputStream, because the mark/reset mechanism is performed on the newly created BufferedInputStream. I do the change on a local version of this library, and it works fine : no need anymore to wrap and to mark/reset the stream.

My local change is :

public static FileType detectFileType(@NotNull final FilterInputStream inputStream) throws IOException

and I use it like this :

class MyStream extends FilterInputStream { ... } 
MyStream myStream = new MyStream();
FileTypeDectector.detectType(myStream); 

Without the change, I did :

class MyStream extends FilterInputStream { ... } 
MyStream myStream = new MyStream();
myStream.mark(-1);
FileTypeDectector.detectType(new BufferedInputStream(myStream)); 
myStream.reset();

Let me know if I missed something important about your implementation choice.

drewnoakes commented 5 years ago

Sounds like a good change. Would you like to send a pull request?

eleduc commented 5 years ago

Yes, I will send you a pull request before end of this week.

eleduc commented 5 years ago

Pull request done. I just perform a maven package command and it is fine. Let me know if missed to perform something.

drewnoakes commented 5 years ago

Thanks for the PR. This will be included in the next release.