I'm writing a code to validate max file size.
public static void main(String[] args) throws IOException {
final InputStream inputStream = new FileInputStream(new File("/path/to/image.jpg"));
System.out.println("initial: " + inputStream.read());
int arr = IOUtils.read(inputStream, new byte[2000001]);
if (arr == 2000001) {
System.out.println("file size greater than limit");
}
System.out.println("after: " + inputStream.read());
}
Output
initial: 255
file size greater than limit
after: 21
Question is what happens to InputStream when it's passed to IOUtils.read()? Moving forward I've to save InputStream as image, when I pass the same InputStream reference to save method upload method of s3 bucket, corrupt image gets saved. Can anybody give me an idea what's going on?