3737 *
3838 * <p>mvn clean compile
3939 *
40- * <p>mvn exec:java -Dexec.mainClass="com.google.genai.examples.FileSearchStores "
40+ * <p>mvn exec:java -Dexec.mainClass="com.google.genai.examples.FileSearchStoresAsync "
4141 * -Dexec.args="path/to/file"
4242 */
4343package com .google .genai .examples ;
@@ -79,7 +79,7 @@ private static <R, T extends Operation<R, T>> CompletableFuture<T> awaitOperatio
7979 .thenCompose (newOp -> awaitOperationComplete (client , (T ) newOp ));
8080 }
8181
82- public static void main (String [] args ) throws ExecutionException , InterruptedException {
82+ public static void main (String [] args ) throws Exception {
8383 String filePath = args .length > 0 ? args [0 ] : Constants .UPLOAD_FILE_PATH ;
8484
8585 try (Client client = new Client ()) {
@@ -97,7 +97,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
9797 .create (null )
9898 .thenCompose (
9999 store -> {
100- System .out .println ("\n --- Created Store : " + store .name ().get () + " ---" );
100+ System .out .println ("Created file store : " + store .name ().get ());
101101
102102 // Get store
103103 return client
@@ -107,20 +107,20 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
107107 .thenAccept (
108108 retrievedStore ->
109109 System .out .println (
110- "Get Store: Success ( " + retrievedStore .name ().get () + ")" ))
110+ "Retrieved file store: " + retrievedStore .name ().get () + ")" ))
111111
112112 // List stores.
113113 .thenCompose (
114114 v ->
115115 client .async .fileSearchStores .list (
116116 ListFileSearchStoresConfig .builder ().pageSize (10 ).build ()))
117- .thenAccept (
117+ .thenCompose (
118118 pager -> {
119- System .out .println ("List all stores names : " );
120- var unused =
121- pager . forEach (
122- item ->
123- System . out . println ( "Store name: " + item .name ().get ()));
119+ System .out .println ("List file stores: " );
120+ return pager . forEach (
121+ item ->
122+ System . out . println (
123+ " File store name: " + item .name ().get ()));
124124 })
125125 .thenApply (v -> store );
126126 })
@@ -133,9 +133,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
133133 .upload (filePath , UploadFileConfig .builder ().mimeType ("text/plain" ).build ())
134134 .thenApply (
135135 file -> {
136- System .out .println (
137- "Upload File (Files Service): " + file .name ().get ());
138- return new Object [] {store , file }; // Pass both
136+ System .out .println ("Uploaded file: " + file .name ().get ());
137+ return new Object [] {store , file };
139138 });
140139 })
141140 .thenCompose (
@@ -190,14 +189,12 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
190189 v ->
191190 client .async .fileSearchStores .documents .list (
192191 store .name ().get (), null ))
193- .thenAccept (
192+ .thenCompose (
194193 pager -> {
195194 System .out .println ("List all document names: " );
196- var unused =
197- pager .forEach (
198- item ->
199- System .out .println (
200- "document name: " + item .name ().get ()));
195+ return pager .forEach (
196+ item ->
197+ System .out .println (" document name: " + item .name ().get ()));
201198 })
202199
203200 // Delete document
@@ -211,9 +208,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
211208 .thenAccept (v -> System .out .println ("Delete Store: Success." ));
212209 });
213210 finalFuture .get ();
214- } catch (Exception e ) {
215- System .err .println ("An error occurred during async execution: " + e .getMessage ());
216211 }
212+ System .out .println ("Async execution for file search stores completed successfully." );
217213 }
218214
219215 private FileSearchStoresAsync () {}
0 commit comments