public long writeTo ( File fileOrDirectory ) throws IOException { long written = 0 ; OutputStream fileOut = null ; try { // Only do something if this part contains a file if ( fileName != null ) { // Check if user supplied directory File file ; if ( fileOrDirectory . isDirectory ( ) ) { // Write it to that dir the user supplied, // with the filename it arrived with file = new File ( fileOrDirectory , fileName ) ; } else { // Write it to the file the user supplied, // ignoring the filename it arrived with file = fileOrDirectory ; } if ( policy != null ) { file = policy . rename ( file ) ; fileName = file . getName ( ) ; } fileOut = new BufferedOutputStream ( new FileOutputStream ( file ) ) ; written = write ( fileOut ) ; } } finally { if ( fileOut != null ) fileOut . close ( ) ; } return written ; }
Write this file part to a file or directory . If the user supplied a file we write it to that file and if they supplied a directory we write it to that directory with the filename that accompanied it . If this part doesn t contain a file this method does nothing .