public int open ( String Filename , int NewMode ) { int retcode = DDC_SUCCESS ; if ( fmode != RFM_UNKNOWN ) { retcode = close ( ) ; } if ( retcode == DDC_SUCCESS ) { switch ( NewMode ) { case RFM_WRITE : try { file = new RandomAccessFile ( Filename , "rw" ) ; fmode = RFM_WRITE ; // Write the RIFF header... // We will have to come back later and patch it! if ( writeHeader_internally ( riff_header ) != DDC_SUCCESS ) { file . close ( ) ; fmode = RFM_UNKNOWN ; } } catch ( IOException ioe ) { fmode = RFM_UNKNOWN ; retcode = DDC_FILE_ERROR ; } break ; case RFM_READ : try { file = new RandomAccessFile ( Filename , "r" ) ; try { // Try to read the RIFF header... byte [ ] br = new byte [ 8 ] ; file . read ( br , 0 , 8 ) ; fmode = RFM_READ ; riff_header . ckID = ( ( br [ 0 ] << 24 ) & 0xFF000000 ) | ( ( br [ 1 ] << 16 ) & 0x00FF0000 ) | ( ( br [ 2 ] << 8 ) & 0x0000FF00 ) | ( br [ 3 ] & 0x000000FF ) ; riff_header . ckSize = ( ( br [ 7 ] << 24 ) & 0xFF000000 ) | ( ( br [ 6 ] << 16 ) & 0x00FF0000 ) | ( ( br [ 5 ] << 8 ) & 0x0000FF00 ) | ( br [ 4 ] & 0x000000FF ) ; } catch ( IOException ioe ) { file . close ( ) ; fmode = RFM_UNKNOWN ; } } catch ( IOException ioe ) { fmode = RFM_UNKNOWN ; retcode = DDC_FILE_ERROR ; } break ; default : retcode = DDC_INVALID_CALL ; } } return retcode ; }
Open a RIFF file .