@@ -108,62 +108,101 @@ public static String getResponse(@NotNull URL url) throws IOException {
108108 /**
109109 * 非同期でストリームを取得
110110 * 失敗時はnullを返す
111+ * {@link #getStreamAsync(URL)}に移行してください
111112 *
112113 * @param url URL
113114 * @param streamConsumer ストリーム
114115 * @return 処理結果
115116 */
117+ @ Deprecated
116118 public static CompletableFuture <Void > getStreamAsync (URL url , Consumer <InputStream > streamConsumer ) {
117- return CompletableFuture .runAsync (() -> {
118- InputStream stream = null ;
119+ return getStreamAsync (url ).thenAccept (streamConsumer );
120+ }
121+
122+ /**
123+ * 非同期でストリームを取得
124+ * 失敗時はnullを返す
125+ *
126+ * @param url URL
127+ * @return ストリーム
128+ */
129+ @ NotNull
130+ public static CompletableFuture <InputStream > getStreamAsync (@ NotNull URL url ) {
131+ return CompletableFuture .supplyAsync (() -> {
119132 try {
120- stream = getStream (url );
133+ return getStream (url );
121134 } catch (IOException e ) {
122- e . printStackTrace () ;
135+ return null ;
123136 }
124- streamConsumer .accept (stream );
125137 });
126138 }
127139
128140 /**
129141 * 非同期で文字列を取得
130142 * 失敗時はnullを返す
143+ * {@link #getResponseAsync(URL)}に移行してください
131144 *
132145 * @param url URL
133146 * @param stringConsumer 文字列
134147 * @return 処理結果
135148 */
149+ @ Deprecated ()
136150 public static CompletableFuture <Void > getResponseAsync (URL url , Consumer <String > stringConsumer ) {
137- return CompletableFuture .runAsync (() -> {
138- String str = null ;
151+ return getResponseAsync (url ).thenAccept (stringConsumer );
152+ }
153+
154+ /**
155+ * 非同期で文字列を取得
156+ * 失敗時はnullを返す
157+ *
158+ * @param url URL
159+ * @return 処理結果
160+ */
161+ @ NotNull
162+ public static CompletableFuture <String > getResponseAsync (@ NotNull URL url ) {
163+ return CompletableFuture .supplyAsync (() -> {
139164 try {
140- str = getResponse (url );
165+ return getResponse (url );
141166 } catch (IOException e ) {
142- e . printStackTrace () ;
167+ return null ;
143168 }
144- stringConsumer .accept (str );
145169 });
146170 }
147171
148172 /**
149- * POSTでテキストを送り返ってきた文字列とステータスコードを取得
173+ * 非同期でPOSTでテキストを送り返ってきた文字列とステータスコードを取得
174+ * {@link #getResponseByPOSTAsync(URL, String, String, String)}に移行してください
150175 *
151176 * @param url URL
152177 * @param body テキスト
153178 * @param language 言語
154179 * @param contentType type
155180 * @param responseConsumer 返答とステータスコードのペア
156- * @return 返答とステータスコードのペア
181+ * @return 返答
157182 */
183+ @ Deprecated
158184 public static CompletableFuture <Void > getResponseByPOSTAsync (URL url , String body , String language , String contentType , Consumer <PostResponse > responseConsumer ) {
159- return CompletableFuture .runAsync (() -> {
160- PostResponse ret = null ;
185+ return getResponseByPOSTAsync (url , body , language , contentType ).thenAccept (responseConsumer );
186+ }
187+
188+ /**
189+ * 非同期でPOSTでテキストを送り返ってきた文字列とステータスコードを取得
190+ * 失敗時はnullを返す
191+ *
192+ * @param url URL
193+ * @param body テキスト
194+ * @param language 言語
195+ * @param contentType type
196+ * @return 返答
197+ */
198+ @ NotNull
199+ public static CompletableFuture <PostResponse > getResponseByPOSTAsync (@ NotNull URL url , @ NotNull String body , @ NotNull String language , @ NotNull String contentType ) {
200+ return CompletableFuture .supplyAsync (() -> {
161201 try {
162- ret = getResponseByPOST (url , body , language , contentType );
202+ return getResponseByPOST (url , body , language , contentType );
163203 } catch (IOException e ) {
164- e . printStackTrace () ;
204+ return null ;
165205 }
166- responseConsumer .accept (ret );
167206 });
168207 }
169208
0 commit comments