我想验证上传的图片,该文件是否为图片。 为此,我使用Tika Parser,它正确解析它,但解析后输入流为空。
public static FileType checkFileType(InputStream inputStream) throws IOException, SAXException, TikaException,
InvalidArgumentException {
ContentHandler contenthandler = new BodyContentHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
ParseContext context = new ParseContext();
parser.parse(inputStream, contenthandler, metadata, context);
//inputStream.close();
String contentType = metadata.get(Metadata.CONTENT_TYPE);
}
我从org.apache.cxf.jaxrs.ext.multipart.Attachment获取输入流 InputStream inputStream = attachment.getDataHandler()。getInputStream();