11package com .convertapi ;
22
3- import okhttp3 .*;
3+ import okhttp3 .MediaType ;
4+ import okhttp3 .Request ;
5+ import okhttp3 .RequestBody ;
6+
47import javax .activation .MimetypesFileTypeMap ;
5- import java .io .* ;
8+ import java .io .IOException ;
69import java .math .BigDecimal ;
710import java .nio .file .Files ;
811import java .nio .file .Path ;
1114import java .util .concurrent .CompletableFuture ;
1215import java .util .concurrent .ExecutionException ;
1316
17+ @ SuppressWarnings ("WeakerAccess" )
1418public class Param {
15- private String name ;
19+ private final String name ;
1620 private CompletableFuture <List <String >> value ;
1721
22+ @ SuppressWarnings ("unused" )
1823 private Param (String name ) {
1924 this .name = name .toLowerCase ();
2025 }
2126
27+ @ SuppressWarnings ("unused" )
2228 public Param (String name , String value ) {
2329 this (name .toLowerCase ());
24- List <String > valueList = new ArrayList ();
30+ List <String > valueList = new ArrayList <> ();
2531 valueList .add (value );
2632 this .value = CompletableFuture .completedFuture (valueList );
2733 }
2834
35+ @ SuppressWarnings ("unused" )
2936 public Param (String name , int value ) {
3037 this (name , String .valueOf (value ));
3138 }
3239
40+ @ SuppressWarnings ("unused" )
3341 public Param (String name , BigDecimal value ) {
3442 this (name , String .valueOf (value ));
3543 }
3644
45+ @ SuppressWarnings ("unused" )
3746 public Param (String name , byte [] value , String fileFormat ) {
3847 this (name , value , fileFormat , Config .defaults ());
3948 }
4049
50+ @ SuppressWarnings ("WeakerAccess" )
4151 public Param (String name , byte [] value , String fileFormat , Config config ) {
4252 this (name );
4353 String fileName = "getFile." + fileFormat ;
@@ -49,27 +59,31 @@ public Param(String name, Path value) throws IOException {
4959 this (name , value , Config .defaults ());
5060 }
5161
62+ @ SuppressWarnings ("WeakerAccess" )
5263 public Param (String name , Path value , Config config ) throws IOException {
5364 this (name );
5465 String contentTypeString = MimetypesFileTypeMap .getDefaultFileTypeMap ().getContentType (value .toFile ());
5566 this .value = upload (Files .readAllBytes (value ), value .getFileName ().toString (), MediaType .parse (contentTypeString ), config );
5667 }
5768
58- public Param (String name , ConversionResult value ) throws ExecutionException , InterruptedException {
69+ @ SuppressWarnings ("unused" )
70+ public Param (String name , ConversionResult value ) {
5971 this (name , value , 0 );
6072 this .value = CompletableFuture .completedFuture (value .urls ());
6173 }
6274
63- public Param (String name , ConversionResult value , int fileIndex ) throws ExecutionException , InterruptedException {
75+ @ SuppressWarnings ("WeakerAccess" )
76+ public Param (String name , ConversionResult value , int fileIndex ) {
6477 this (name );
65- List <String > valueList = new ArrayList ();
78+ List <String > valueList = new ArrayList <> ();
6679 valueList .add (value .getFile (fileIndex ).getUrl ());
6780 this .value = CompletableFuture .completedFuture (valueList );
6881 }
6982
70- public Param (String name , CompletableFuture <ConversionResult > value ) throws ExecutionException , InterruptedException {
83+ @ SuppressWarnings ("unused" )
84+ public Param (String name , CompletableFuture <ConversionResult > value ) {
7185 this (name );
72- this .value = value .thenApply (r -> r . urls () );
86+ this .value = value .thenApply (ConversionResult :: urls );
7387 }
7488
7589 public String getName () {
@@ -84,12 +98,13 @@ private static CompletableFuture<List<String>> upload(byte[] data, String fileNa
8498 return CompletableFuture .supplyAsync (() -> {
8599 Request request = new Request .Builder ()
86100 .url (Http .getUrlBuilder (config ).addPathSegment ("upload" )
87- .addQueryParameter ("filename" , fileName . toString () )
101+ .addQueryParameter ("filename" , fileName )
88102 .build ())
89103 .post (RequestBody .create (fileContentType , data ))
90104 .build ();
91105 try {
92- List <String > valueList = new ArrayList <String >();
106+ List <String > valueList = new ArrayList <>();
107+ //noinspection ConstantConditions
93108 valueList .add (Http .getClient ().newCall (request ).execute ().body ().string ());
94109 return valueList ;
95110 } catch (IOException e ) {
0 commit comments