public List < FileInfo > listFileInfo ( URI path ) throws IOException { Preconditions . checkNotNull ( path , "path can not be null" ) ; logger . atFine ( ) . log ( "listFileInfo(%s)" , path ) ; StorageResourceId pathId = pathCodec . validatePathAndGetId ( path , true ) ; StorageResourceId dirId = pathCodec . validatePathAndGetId ( FileInfo . convertToDirectoryPath ( pathCodec , path ) , true ) ; // To improve performance start to list directory items right away. ExecutorService dirExecutor = Executors . newSingleThreadExecutor ( DAEMON_THREAD_FACTORY ) ; try { Future < GoogleCloudStorageItemInfo > dirFuture = dirExecutor . submit ( ( ) -> gcs . getItemInfo ( dirId ) ) ; dirExecutor . shutdown ( ) ; if ( ! pathId . isDirectory ( ) ) { GoogleCloudStorageItemInfo pathInfo = gcs . getItemInfo ( pathId ) ; if ( pathInfo . exists ( ) ) { List < FileInfo > listedInfo = new ArrayList <> ( ) ; listedInfo . add ( FileInfo . fromItemInfo ( pathCodec , pathInfo ) ) ; return listedInfo ; } } try { GoogleCloudStorageItemInfo dirInfo = dirFuture . get ( ) ; List < GoogleCloudStorageItemInfo > dirItemInfos = dirId . isRoot ( ) ? gcs . listBucketInfo ( ) : gcs . listObjectInfo ( dirId . getBucketName ( ) , dirId . getObjectName ( ) , PATH_DELIMITER ) ; if ( ! dirInfo . exists ( ) && dirItemInfos . isEmpty ( ) ) { throw new FileNotFoundException ( "Item not found: " + path ) ; } List < FileInfo > fileInfos = FileInfo . fromItemInfos ( pathCodec , dirItemInfos ) ; fileInfos . sort ( FILE_INFO_PATH_COMPARATOR ) ; return fileInfos ; } catch ( InterruptedException | ExecutionException e ) { if ( e instanceof InterruptedException ) { Thread . currentThread ( ) . interrupt ( ) ; } throw new IOException ( String . format ( "Failed to listFileInfo for '%s'" , path ) , e ) ; } } finally { dirExecutor . shutdownNow ( ) ; } }
If the given path points to a directory then the information about its children is returned otherwise information about the given file is returned .