@Test void testEmptyValidBucketForLocationWithKey() throws Exception { assertThatThrownBy(() -> getObjectNameFromLocation("s3: .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("valid bucket name"); }
static String getObjectNameFromLocation(String location) { Assert.notNull(location, "Location must not be null"); if (!isSimpleStorageResource(location)) { throw new IllegalArgumentException( "The location :'" + location + "' is not a valid S3 location"); } int bucketEndIndex = location.indexOf(PATH_DELIMITER, S3_PROTOCOL_PREFIX.length()); if (bucketEndIndex == -1 || bucketEndIndex == S3_PROTOCOL_PREFIX.length()) { throw new IllegalArgumentException("The location :'" + location + "' does not contain a valid bucket name"); } if (location.contains(VERSION_DELIMITER)) { return getObjectNameFromLocation( location.substring(0, location.indexOf(VERSION_DELIMITER))); } int endIndex = location.length(); if (location.endsWith(PATH_DELIMITER)) { endIndex--; } if (bucketEndIndex >= endIndex) { return ""; } return location.substring(++bucketEndIndex, endIndex); }
SimpleStorageNameUtils { static String getObjectNameFromLocation(String location) { Assert.notNull(location, "Location must not be null"); if (!isSimpleStorageResource(location)) { throw new IllegalArgumentException( "The location :'" + location + "' is not a valid S3 location"); } int bucketEndIndex = location.indexOf(PATH_DELIMITER, S3_PROTOCOL_PREFIX.length()); if (bucketEndIndex == -1 || bucketEndIndex == S3_PROTOCOL_PREFIX.length()) { throw new IllegalArgumentException("The location :'" + location + "' does not contain a valid bucket name"); } if (location.contains(VERSION_DELIMITER)) { return getObjectNameFromLocation( location.substring(0, location.indexOf(VERSION_DELIMITER))); } int endIndex = location.length(); if (location.endsWith(PATH_DELIMITER)) { endIndex--; } if (bucketEndIndex >= endIndex) { return ""; } return location.substring(++bucketEndIndex, endIndex); } }
SimpleStorageNameUtils { static String getObjectNameFromLocation(String location) { Assert.notNull(location, "Location must not be null"); if (!isSimpleStorageResource(location)) { throw new IllegalArgumentException( "The location :'" + location + "' is not a valid S3 location"); } int bucketEndIndex = location.indexOf(PATH_DELIMITER, S3_PROTOCOL_PREFIX.length()); if (bucketEndIndex == -1 || bucketEndIndex == S3_PROTOCOL_PREFIX.length()) { throw new IllegalArgumentException("The location :'" + location + "' does not contain a valid bucket name"); } if (location.contains(VERSION_DELIMITER)) { return getObjectNameFromLocation( location.substring(0, location.indexOf(VERSION_DELIMITER))); } int endIndex = location.length(); if (location.endsWith(PATH_DELIMITER)) { endIndex--; } if (bucketEndIndex >= endIndex) { return ""; } return location.substring(++bucketEndIndex, endIndex); } private  SimpleStorageNameUtils(); }
SimpleStorageNameUtils { static String getObjectNameFromLocation(String location) { Assert.notNull(location, "Location must not be null"); if (!isSimpleStorageResource(location)) { throw new IllegalArgumentException( "The location :'" + location + "' is not a valid S3 location"); } int bucketEndIndex = location.indexOf(PATH_DELIMITER, S3_PROTOCOL_PREFIX.length()); if (bucketEndIndex == -1 || bucketEndIndex == S3_PROTOCOL_PREFIX.length()) { throw new IllegalArgumentException("The location :'" + location + "' does not contain a valid bucket name"); } if (location.contains(VERSION_DELIMITER)) { return getObjectNameFromLocation( location.substring(0, location.indexOf(VERSION_DELIMITER))); } int endIndex = location.length(); if (location.endsWith(PATH_DELIMITER)) { endIndex--; } if (bucketEndIndex >= endIndex) { return ""; } return location.substring(++bucketEndIndex, endIndex); } private  SimpleStorageNameUtils();  }
SimpleStorageNameUtils { static String getObjectNameFromLocation(String location) { Assert.notNull(location, "Location must not be null"); if (!isSimpleStorageResource(location)) { throw new IllegalArgumentException( "The location :'" + location + "' is not a valid S3 location"); } int bucketEndIndex = location.indexOf(PATH_DELIMITER, S3_PROTOCOL_PREFIX.length()); if (bucketEndIndex == -1 || bucketEndIndex == S3_PROTOCOL_PREFIX.length()) { throw new IllegalArgumentException("The location :'" + location + "' does not contain a valid bucket name"); } if (location.contains(VERSION_DELIMITER)) { return getObjectNameFromLocation( location.substring(0, location.indexOf(VERSION_DELIMITER))); } int endIndex = location.length(); if (location.endsWith(PATH_DELIMITER)) { endIndex--; } if (bucketEndIndex >= endIndex) { return ""; } return location.substring(++bucketEndIndex, endIndex); } private  SimpleStorageNameUtils();   }