public Status encode ( File inputFile , File outputFile ) { Status status = Status . FULL_ENCODE ; this . outFile = outputFile ; //take file and initial configuration. //open file AudioInputStream sin = null ; AudioFormat format = null ; try { sin = AudioSystem . getAudioInputStream ( inputFile ) ; } catch ( IOException e ) { status = Status . FILE_IO_ERROR ; } catch ( UnsupportedAudioFileException e ) { status = Status . UNSUPPORTED_FILE ; } finally { if ( status != Status . FULL_ENCODE ) { try { sin . close ( ) ; } catch ( IOException e ) { //Nothing to do, close failed } return status ; } } try { format = sin . getFormat ( ) ; //sanitize and optimize configurations adjustConfigurations ( format ) ; //open stream openStream ( ) ; AudioStreamEncoder . encodeAudioInputStream ( sin , MAX_READ , flac , useThreads ) ; } catch ( IOException e ) { status = Status . FILE_IO_ERROR ; } catch ( IllegalArgumentException e ) { status = Status . GENERAL_ERROR ; String message = e . getMessage ( ) ; if ( message . equals ( Status . UNSUPPORTED_SAMPLE_SIZE . name ( ) ) ) status = Status . UNSUPPORTED_SAMPLE_SIZE ; else throw e ; } finally { try { sin . close ( ) ; } catch ( IOException e ) { //Nothing to do, close failed } } return status ; }
Encode the given input wav file to an output file .