【问题标题】:how to convert S3ObjectInputStream to PushbackInputStream如何将 S3ObjectInputStream 转换为 PushbackInputStream
【发布时间】:2016-12-31 04:52:56
【问题描述】:

我正在将一个 excel(xls) 文件上传到 s3,然后另一个应用程序应该从 s3 下载该文件并使用 Apache POI 阅读器进行解析。读者接受inputstream 类型作为输入,但为了正确解析它期望PushbackInputStream 的excel。我从从 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

任何人都知道这个问题的解决方案

【问题讨论】:

标签: java excel amazon-s3 apache-poi inputstream


【解决方案1】:

这解决了我的问题。

InputStream inputStream = s3object.getObjectContent(); 
PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 2018-01-28
    • 2010-09-08
    • 2013-09-21
    • 2011-05-14
    相关资源
    最近更新 更多