如何将 S3ObjectInputStream 转换为 PushbackInputStream
how to convert S3ObjectInputStream to PushbackInputStream
我正在将 excel(xls) 文件上传到 s3,然后另一个应用程序应从 s3 下载该文件并使用 Apache POI reader 进行解析。 reader 接受 inputstream
类型作为输入,但为了正确解析 excel 它期望 PushbackInputStream
。我从从 s3 下载的文件中获得的输入流类型为 S3ObjectInputStream
。我如何将 S3ObjectInputStream
转换为 PushbackInputStream
?
我尝试直接将 S3ObjectInputStream
(因为这是一个 inputStream
)传递给 PushbackInputStream
,但它导致了以下异常:
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
任何人都知道这个的解决方案
这解决了我的问题。
InputStream inputStream = s3object.getObjectContent();
PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);
我正在将 excel(xls) 文件上传到 s3,然后另一个应用程序应从 s3 下载该文件并使用 Apache POI reader 进行解析。 reader 接受 inputstream
类型作为输入,但为了正确解析 excel 它期望 PushbackInputStream
。我从从 s3 下载的文件中获得的输入流类型为 S3ObjectInputStream
。我如何将 S3ObjectInputStream
转换为 PushbackInputStream
?
我尝试直接将 S3ObjectInputStream
(因为这是一个 inputStream
)传递给 PushbackInputStream
,但它导致了以下异常:
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
任何人都知道这个的解决方案
这解决了我的问题。
InputStream inputStream = s3object.getObjectContent();
PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);