static String validateObjectName ( String objectName , boolean allowEmptyObjectName ) { logger . atFine ( ) . log ( "validateObjectName('%s', %s)" , objectName , allowEmptyObjectName ) ; if ( isNullOrEmpty ( objectName ) || objectName . equals ( PATH_DELIMITER ) ) { if ( allowEmptyObjectName ) { objectName = "" ; } else { throw new IllegalArgumentException ( "Google Cloud Storage path must include non-empty object name." ) ; } } // We want objectName to look like a traditional file system path, // therefore, disallow objectName with consecutive '/' chars. for ( int i = 0 ; i < ( objectName . length ( ) - 1 ) ; i ++ ) { if ( objectName . charAt ( i ) == ' ' && objectName . charAt ( i + 1 ) == ' ' ) { throw new IllegalArgumentException ( String . format ( "Google Cloud Storage path must not have consecutive '/' characters, got '%s'" , objectName ) ) ; } } // Remove leading '/' if it exists. if ( objectName . startsWith ( PATH_DELIMITER ) ) { objectName = objectName . substring ( 1 ) ; } logger . atFine ( ) . log ( "validateObjectName -> '%s'" , objectName ) ; return objectName ; }
Validate the given object name to make sure that it can be used as a part of a file system path .