An implementation of the answer from Kathy Van Stone:
At first, create a helper class, which creates a DataSource from an InputStream:
public class InputStreamDataSource implements DataSource {
private InputStream inputStream;
public InputStreamDataSource(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public InputStream getInputStream() throws IOException {
return inputStream;
}
@Override
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public String getContentType() {
return "*/*";
}
@Override
public String getName() {
return "InputStreamDataSource";
}
}
And then you can create a DataHandler from an InputStream:
DataHandler dataHandler = new DataHandler(new InputStreamDataSource(inputStream))
imports:
import javax.activation.DataSource;
import java.io.OutputStream;
import java.io.InputStream;