private String getContentId ( File baseDir , File file ) { String filePath = file . getPath ( ) ; String basePath = baseDir . getPath ( ) ; int index = filePath . indexOf ( basePath ) ; if ( index == - 1 ) { StringBuilder sb = new StringBuilder ( "Invalid basePath for file: " ) ; sb . append ( "b: '" + basePath + "', " ) ; sb . append ( "f: '" + filePath + "'" ) ; throw new DuraCloudRuntimeException ( sb . toString ( ) ) ; } String contentId = filePath . substring ( index + basePath . length ( ) ) ; if ( contentId . startsWith ( File . separator ) ) { contentId = contentId . substring ( 1 , contentId . length ( ) ) ; } // Replace backslash (\) with forward slash (/) for all content IDs contentId = contentId . replaceAll ( "\\\\" , "/" ) ; return contentId ; }
This method defines the returned contentId as the path of the arg file minus the path of the arg baseDir in which the file was found .