我有一个方法在S3上返回文件的InputStream。如果我两次使用此方法,则会对S3进行两次调用。我想知道是否有办法存储输入流?
例如:
InputStream getInputStreamForObject(String fileName) {
//return inputstream for fileName on S3
}
String determineFiletype (InputStream is) {
//some way to determine filetype from inputstream.
//inputstream would be read here
}
void someMethod(String fileName) {
String fileType = determineFileType(getInputStreamForObject(fileName))
if (fileType == "DOCX") {
docxParser.parse(getInputStreamForObject(fileName))
}
else if (fileType == "XLSX") {
xlsxParser.parse(getInputStreamForObject(fileName))
}
}