public void writeTag ( RandomAccessFile raf ) throws FileNotFoundException , IOException { int curSize = getSize ( ) ; origPadding = padding ; padding = getUpdatedPadding ( ) ; // This means that the file does not need to change size if ( ( padding > origPadding ) || ( ( padding == origPadding ) && ( curSize == origSize ) ) ) { byte [ ] out = getBytes ( ) ; raf . seek ( 0 ) ; raf . write ( out ) ; } else { //TODO: This needs copying without full loading int bufSize = ( int ) ( raf . length ( ) + curSize ) ; byte [ ] out = new byte [ bufSize ] ; System . arraycopy ( getBytes ( ) , 0 , out , 0 , curSize ) ; int bufSize2 = ( int ) ( raf . length ( ) - origSize ) ; byte [ ] in = new byte [ bufSize2 ] ; raf . seek ( origSize ) ; if ( raf . read ( in ) != in . length ) { throw new IOException ( "Error reading mp3 file before writing" ) ; } System . arraycopy ( in , 0 , out , curSize , in . length ) ; raf . setLength ( bufSize2 ) ; raf . seek ( 0 ) ; raf . write ( out ) ; } origSize = curSize ; exists = true ; }
Saves all the information in the tag to the file passed to the constructor . If a tag doesn t exist a tag is prepended to the file . If the padding has not changed since the creation of this object and the size is less than the original size + the original padding then the previous tag and part of the previous padding will be overwritten . Otherwise a new tag will be prepended to the file .