private File extractToTemp ( InputStream _fileToExtract , String _tmpName , String _fileSuffix ) throws IOException { if ( _fileToExtract == null ) { throw new IOException ( "Null stream" ) ; } File tempFile = File . createTempFile ( _tmpName , _fileSuffix ) ; tempFile . deleteOnExit ( ) ; if ( ! tempFile . exists ( ) ) { throw new FileNotFoundException ( "File " + tempFile . getAbsolutePath ( ) + " could not be created" ) ; } byte [ ] buffer = new byte [ 1024 ] ; int readBytes ; OutputStream os = new FileOutputStream ( tempFile ) ; try { while ( ( readBytes = _fileToExtract . read ( buffer ) ) != - 1 ) { os . write ( buffer , 0 , readBytes ) ; } } finally { os . close ( ) ; _fileToExtract . close ( ) ; } return tempFile ; }
Extract the file behind InputStream _fileToExtract to the tmp - folder .