src/main/java/com/jmsoftware/datastructuresandalgorithms/common/util/FileUtil.java
/**
     * Convert input stream to file
     *
     * @param inputStream input stream
     * @param savePath    path for saving file
     * @return file
     */
Convert input stream to file
@param inputStream input stream
@param savePath    path for saving file
@return file
Convert input stream to file @param inputStream input stream @param savePath path for saving file @return file
public static File convertFrom(final InputStream inputStream, final String savePath) {
        log.info("Converting InputStream to file, save path: {}", savePath);
        var file = new File(savePath);
        try (OutputStream outputStream = new FileOutputStream(file)) {
            int read;
            byte[] bytes = new byte[1024];
            while ((read = inputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, read);
            }
        } catch (IOException e) {
            log.error("Exception occurred when initializing FileOutputStream. Exception message: {}",
                      e.getMessage(),
                      e);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                log.error("Exception occurred when closing FileOutputStream. Exception message: {}", e.getMessage(), e);
            }
        }
        return file;
    }
public static File convertFrom ( final InputStream inputStream , final String savePath ) { log . info ( "Converting InputStream to file, save path: {}" , savePath ) ; var file = new File ( savePath ) ; try ( OutputStream outputStream = new FileOutputStream ( file ) ) { int read ; byte [ ] bytes = new byte [ 1024 ] ; while ( ( read = inputStream . read ( bytes ) ) != - 1 ) { outputStream . write ( bytes , 0 , read ) ; } } catch ( IOException e ) { log . error ( "Exception occurred when initializing FileOutputStream. Exception message: {}" , e . getMessage ( ) , e ) ; } finally { try { inputStream . close ( ) ; } catch ( IOException e ) { log . error ( "Exception occurred when closing FileOutputStream. Exception message: {}" , e . getMessage ( ) , e ) ; } } return file ; }
Convert input stream to file
 @param inputStream input stream
 @param savePath    path for saving file
 @return file
Convert input stream to file @param inputStream input stream @param savePath path for saving file @return file