public static FSDataOutputStream tryCreateFile ( FileSystem fs , Path file ) throws IOException { try { FSDataOutputStream os = fs . create ( file , false ) ; return os ; } catch ( FileAlreadyExistsException e ) { return null ; } catch ( RemoteException e ) { if ( e . unwrapRemoteException ( ) instanceof AlreadyBeingCreatedException ) { return null ; } else { // unexpected error throw e ; } } }
Returns null if file already exists . throws if there was unexpected problem