@ Override public FSDataOutputStream create ( Path path , FsPermission permission , boolean overwrite , int bufferSize , short replication , long blockSize , Progressable progress ) throws IOException { LOG . debug ( "create({}, {}, {}, {}, {}, {}, {})" , path , permission , overwrite , bufferSize , replication , blockSize , progress ) ; if ( mStatistics != null ) { mStatistics . incrementWriteOps ( 1 ) ; } AlluxioURI uri = new AlluxioURI ( HadoopUtils . getPathWithoutScheme ( path ) ) ; CreateFilePOptions options = CreateFilePOptions . newBuilder ( ) . setBlockSizeBytes ( blockSize ) . setMode ( new Mode ( permission . toShort ( ) ) . toProto ( ) ) . setRecursive ( true ) . build ( ) ; FileOutStream outStream ; try { outStream = mFileSystem . createFile ( uri , options ) ; } catch ( AlluxioException e ) { //now we should consider the override parameter try { if ( mFileSystem . exists ( uri ) ) { if ( ! overwrite ) { throw new IOException ( ExceptionMessage . FILE_ALREADY_EXISTS . getMessage ( uri ) ) ; } if ( mFileSystem . getStatus ( uri ) . isFolder ( ) ) { throw new IOException ( ExceptionMessage . FILE_CREATE_IS_DIRECTORY . getMessage ( uri ) ) ; } mFileSystem . delete ( uri ) ; } outStream = mFileSystem . createFile ( uri , options ) ; } catch ( AlluxioException e2 ) { throw new IOException ( e2 ) ; } } return new FSDataOutputStream ( outStream , mStatistics ) ; }
Attempts to create a file . Overwrite will not succeed if the path exists and is a folder .