Reputation: 67
I want to convert a FileInputStream
to a S3ObjectInputStream
.
This is my current code:
InputStream is = new FileInputStream(file);
S3ObjectInputStream sObject = (S3ObjectInputStream)is;
However, it's giving the error:
java.io.FileInputStream cannot be cast to com.amazonaws.services.s3.model.S3ObjectInputStream
Upvotes: 6
Views: 10521
Reputation: 5884
Use the constructor
new S3ObjectInputStream(InputStream in, ...
I used aws-java-sdk version 1.11.526
Upvotes: 1
Reputation: 61
Use the below constructor to convert an InputStream
to a S3ObjectInputStream
:
var s3ObjectInputStream = new S3ObjectInputStream(inputStream, null);
You can safely use null
for the 2nd argument in the constructor (HttpRequestBase
) as the abort
method which uses it, isn't available in the cast InputStream
.
Upvotes: 6
Reputation: 751
You need cast as a InputStream
InputStream is = new FileInputStream(file);
S3ObjectInputStream sObject = (InputStream) is;
Hope it helps
Upvotes: -6