如何将S3ObjectInputStream转换为PushbackInputStream
我将一个excel(xls)file upload到s3,然后另一个应用程序应该从s3下载该文件并使用Apache POI阅读器进行parsing。 读者接受inputstream
types作为input,但为了正确parsingexcel,它期望PushbackInputStream
。 从s3下载的文件中的inputS3ObjectInputStream
是S3ObjectInputStream
types的。 如何将S3ObjectInputStream
转换为PushbackInputStream
?
我试着直接将S3ObjectInputStream
(因为这是一个inputStream
)传递给PushbackInputStream
,但是却导致了下面的exception:
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:147) at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96) ..... ..... Caused by: java.lang.IllegalStateException: InputStream MUST either support mark/reset, or be wrapped as a PushbackInputStream at org.springframework.batch.item.excel.poi.PoiItemReader.openExcelFile(PoiItemReader.java:82) .....
我试图将S3ObjectInputStream投射到PushbackInputStream,但是导致了classCastexception。
java.lang.ClassCastException: com.amazonaws.services.s3.model.S3ObjectInputStream cannot be cast to java.io.PushbackInputStream
任何人都知道这个解决scheme
这解决了我的问题。
InputStream inputStream = s3object.getObjectContent(); PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);