将BufferedInputStream传递给接受InputStream的方法

时间:2016-10-25 21:18:58

标签: java groovy inputstream metadata-extractor

我正在调用一个接受InputStream的方法。这是github上的方法:https://github.com/drewnoakes/metadata-extractor/blob/2.8.0/Source/com/drew/imaging/ImageMetadataReader.java#L89

我使用BufferedInputStream调用方法,因为它是InputStream的孩子,所以应该有效但我一直收到这个错误:

No signature of method: static com.drew.imaging.ImageMetadataReader.readMetadata() is applicable for argument types: (java.io.BufferedInputStream) values: [java.io.BufferedInputStream@74d4ec5f]
Possible solutions: readMetadata(java.io.File), readMetadata(java.io.BufferedInputStream, boolean). Stacktrace follows:
Message: No signature of method: static com.drew.imaging.ImageMetadataReader.readMetadata() is applicable for argument types: (java.io.BufferedInputStream) values: [java.io.BufferedInputStream@74d4ec5f]
Possible solutions: readMetadata(java.io.File), readMetadata(java.io.BufferedInputStream, boolean)
    Line | Method
->>  137 | settings  in com.foo.scanner.AdminController
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     62 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|     59 | doFilter  in grails.plugin.springsecurity.web.SecurityRequestHolderFilter

这是我的代码:

println file62.name //prints name of the file
println file62.inputStream.getClass() //prints java.io.BufferedInputStream
InputStream is = (InputStream)file62.inputStream
Metadata metadata = com.drew.imaging.ImageMetadataReader.readMetadata(is) //readMetadata expects InputStream

我拥有的图书馆版本:

✗ grails dependency-report | grep "drew" +--- com.drewnoakes:metadata-extractor:2.9.1 +--- com.drewnoakes:metadata-extractor:2.9.1 +--- com.drewnoakes:metadata-extractor:2.9.1

这是2.9.1中的方法:https://github.com/drewnoakes/metadata-extractor/blob/2.9.1/Source/com/drew/imaging/ImageMetadataReader.java#L88

2 个答案:

答案 0 :(得分:3)

例外情况表明该方法需要FileBufferedInputStream 布尔值。没有任何重载需要 BufferedInputStream

如果您确定形式参数和实际参数匹配,那么这种异常(由正式参数不匹配引起)的最可能原因是周围有一个旧罐子。运行mvn cleangradle clean,检查您的Web容器的lib目录,并通常从系统中删除错误的jar。

答案 1 :(得分:0)

@PaulHicks是完全正确的。您提出的API被误导,并在2012年以极端偏见被删除,并提交此承诺:

https://github.com/drewnoakes/metadata-extractor/commit/9f3854b81313f1ea498b991d36253f221db79dca#diff-8fa1b864bada9112be69ec00784af715

GitHub建议在2.7.0版本中删除API。