GoogleCloudStorageFileSystem { String getItemName(URI path) { Preconditions.checkNotNull(path); if (path.equals(GCS_ROOT)) { return null; } StorageResourceId resourceId = StorageResourceId.fromUriPath(path, true); if (resourceId.isBucket()) { return resourceId.getBucketName(); } String objectName = resourceId.getObjectName(); int index = StringPaths.isDirectoryPath(objectName) ? objectName.lastIndexOf(PATH_DELIMITER, objectName.length() - 2) : objectName.lastIndexOf(PATH_DELIMITER); return index < 0 ? objectName : objectName.substring(index + 1); } GoogleCloudStorageFileSystem(
      Credential credential, GoogleCloudStorageFileSystemOptions options); @VisibleForTesting  GoogleCloudStorageFileSystem(GoogleCloudStorage gcs); @VisibleForTesting  GoogleCloudStorageFileSystem(
      GoogleCloudStorage gcs, GoogleCloudStorageFileSystemOptions options); GoogleCloudStorageFileSystemOptions getOptions(); static CreateObjectOptions objectOptionsFromFileOptions(CreateFileOptions options); WritableByteChannel create(URI path); WritableByteChannel create(URI path, CreateFileOptions options); SeekableByteChannel open(URI path); SeekableByteChannel open(URI path, GoogleCloudStorageReadOptions readOptions); void delete(URI path, boolean recursive); boolean exists(URI path); void mkdirs(URI path); void mkdirsInternal(StorageResourceId resourceId); void rename(URI src, URI dst); void compose(List<URI> sources, URI destination, String contentType); List<URI> listFileNames(FileInfo fileInfo); List<URI> listFileNames(FileInfo fileInfo, boolean recursive); List<FileInfo> listAllFileInfoForPrefix(URI prefix); ListPage<FileInfo> listAllFileInfoForPrefixPage(URI prefix, String pageToken); List<FileInfo> listFileInfo(URI path); FileInfo getFileInfo(URI path); List<FileInfo> getFileInfos(List<URI> paths); void close(); @VisibleForTesting void mkdir(URI path); GoogleCloudStorage getGcs(); static final String SCHEME; static final URI GCS_ROOT; static final ListObjectOptions LIST_SINGLE_OBJECT_OPTIONS; }
@Test public void testGetItemName() throws URISyntaxException { String[] inputPaths = { "gs:/", "gs: "gs: "gs: "gs: "gs: "gs: }; String[] expectedNames = { null, "my-bucket", "my-bucket", "foo", "foo/", "bar", "bar/", }; List<String> actualNames = new ArrayList<>(); for (String inputPath : inputPaths) { actualNames.add(gcsfs.getItemName(new URI(inputPath))); } assertThat(actualNames.toArray(new String[0])).isEqualTo(expectedNames); }