66import javax .activation .MimetypesFileTypeMap ;
77import java .io .*;
88import java .math .BigDecimal ;
9+ import java .nio .file .Path ;
10+ import java .util .Arrays ;
11+ import java .util .List ;
912import java .util .concurrent .CompletableFuture ;
1013import java .util .concurrent .ExecutionException ;
1114
1215public class Param {
1316 private String name ;
14- private CompletableFuture <String [] > values ;
17+ private CompletableFuture <List < String > > values ;
1518// private InputStream streamValue;
1619 private MediaType fileContentType ;
1720 private String fileExtension ;
18- private File file ;
21+ private Path file ;
1922 private Config config = Config .defaults ();
2023
2124 public Param (String name , String [] values ) {
@@ -38,21 +41,26 @@ public Param(String name, BigDecimal value) {
3841// public Param(String name, InputStream value, String fileFormat) {
3942// }
4043
41- public Param (String name , File value ) throws FileNotFoundException {
44+ public Param (String name , Path value ) throws FileNotFoundException {
4245 this (name , value , Config .defaults ());
4346 }
4447
45- public Param (String name , File value , Config config ) throws FileNotFoundException {
48+ public Param (String name , Path value , Config config ) throws FileNotFoundException {
4649 this (name , new String []{});
4750 file = value ;
48- String contentTypeString = MimetypesFileTypeMap .getDefaultFileTypeMap ().getContentType (file );
51+ String contentTypeString = MimetypesFileTypeMap .getDefaultFileTypeMap ().getContentType (file . toFile () );
4952 fileContentType = MediaType .parse (contentTypeString );
5053 fileExtension = getFileExtension (file );
5154 values = upload (file , fileContentType , config );
5255 }
5356
54- public Param (String name , CompletableFuture < ConversionResponse > value ) throws ExecutionException , InterruptedException {
57+ public Param (String name , ConversionResult value ) throws ExecutionException , InterruptedException {
5558 this (name , new String []{});
59+
60+ value .getResponseFuture ().thenApplyAsync (r -> {
61+ String [] urls = Arrays .stream (r .Files ).map (Param ::apply ).;
62+ });
63+
5664 ConversionResponse conversionResponse = value .get ();
5765 String [] urls = new String [conversionResponse .Files .length ];
5866 for (int i = 0 ; i < conversionResponse .Files .length ; i ++) {
@@ -61,25 +69,29 @@ public Param(String name, CompletableFuture<ConversionResponse> value) throws Ex
6169 this .values = CompletableFuture .completedFuture (urls );
6270 }
6371
64- private static CompletableFuture <String []> upload (File file , MediaType fileContentType , Config config ) {
72+ private static CompletableFuture <String []> upload (Path file , MediaType fileContentType , Config config ) {
6573 return CompletableFuture .supplyAsync (() -> {
6674 Request request = new Request .Builder ()
6775 .url (Http .getUrlBuilder (config ).addPathSegment ("upload" )
68- .addQueryParameter ("filename" , file .getName ())
76+ .addQueryParameter ("filename" , file .getFileName (). toString ())
6977 .build ())
70- .post (RequestBody .create (fileContentType , file ))
78+ .post (RequestBody .create (fileContentType , file . toFile () ))
7179 .build ();
7280
7381 String bodyString = null ;
7482 try {
7583 bodyString = Http .getClient ().newCall (request ).execute ().body ().string ();
7684 } catch (IOException e ) {
77- e . printStackTrace ( );
85+ throw new RuntimeException ( e );
7886 }
7987 return new String [] {bodyString };
8088 });
8189 }
8290
91+ private static String apply (ConversionResponseFile f ) {
92+ return f .Url ;
93+ }
94+
8395 public String getName () {
8496 return name ;
8597 }
@@ -89,8 +101,8 @@ public Param setConfig(Config config) {
89101 return this ;
90102 }
91103
92- private String getFileExtension (File file ) {
93- String name = file .getName ();
104+ private String getFileExtension (Path file ) {
105+ String name = file .getFileName (). toString ();
94106 try {
95107 return name .substring (name .lastIndexOf ("." ) + 2 );
96108 } catch (Exception e ) {
0 commit comments