16
16
*/
17
17
package com .egzosn .pay .common .util ;
18
18
19
- import java .io .BufferedInputStream ;
20
- import java .io .BufferedReader ;
21
- import java .io .ByteArrayInputStream ;
22
- import java .io .ByteArrayOutputStream ;
23
- import java .io .CharArrayWriter ;
24
- import java .io .Closeable ;
25
- import java .io .EOFException ;
26
- import java .io .IOException ;
27
- import java .io .InputStream ;
28
- import java .io .InputStreamReader ;
29
- import java .io .OutputStream ;
30
- import java .io .OutputStreamWriter ;
31
- import java .io .PrintWriter ;
32
- import java .io .Reader ;
33
- import java .io .StringWriter ;
34
- import java .io .UnsupportedEncodingException ;
35
- import java .io .Writer ;
36
- import java .net .HttpURLConnection ;
37
- import java .net .ServerSocket ;
38
- import java .net .Socket ;
39
- import java .net .URI ;
40
- import java .net .URL ;
41
- import java .net .URLConnection ;
19
+ import org .apache .commons .codec .Charsets ;
20
+
21
+ import java .io .*;
22
+ import java .net .*;
42
23
import java .nio .channels .Selector ;
43
24
import java .nio .charset .Charset ;
44
25
import java .nio .charset .UnsupportedCharsetException ;
45
26
import java .util .ArrayList ;
46
27
import java .util .Collection ;
47
28
import java .util .List ;
48
29
49
- import org .apache .commons .codec .Charsets ;
50
-
51
30
/**
52
31
* General IO stream manipulation utilities.
53
32
* <p>
80
59
* Origin of code: Excalibur.
81
60
*
82
61
* @version $Id: IOUtils.java 1326636 2012-04-16 14:54:53Z ggregory $
83
- *
84
62
*/
85
63
public class IOUtils {
86
64
// NOTE: This class is focussed on InputStream, OutputStream, Reader and
@@ -283,8 +261,7 @@ public static void closeQuietly(Closeable closeable) {
283
261
if (closeable != null ) {
284
262
closeable .close ();
285
263
}
286
- }
287
- catch (IOException ioe ) {
264
+ } catch (IOException ioe ) {
288
265
// ignore
289
266
}
290
267
}
@@ -316,8 +293,7 @@ public static void closeQuietly(Socket sock) {
316
293
if (sock != null ) {
317
294
try {
318
295
sock .close ();
319
- }
320
- catch (IOException ioe ) {
296
+ } catch (IOException ioe ) {
321
297
// ignored
322
298
}
323
299
}
@@ -350,8 +326,7 @@ public static void closeQuietly(Selector selector) {
350
326
if (selector != null ) {
351
327
try {
352
328
selector .close ();
353
- }
354
- catch (IOException ioe ) {
329
+ } catch (IOException ioe ) {
355
330
// ignored
356
331
}
357
332
}
@@ -384,8 +359,7 @@ public static void closeQuietly(ServerSocket sock) {
384
359
if (sock != null ) {
385
360
try {
386
361
sock .close ();
387
- }
388
- catch (IOException ioe ) {
362
+ } catch (IOException ioe ) {
389
363
// ignored
390
364
}
391
365
}
@@ -409,7 +383,6 @@ public static void closeQuietly(ServerSocket sock) {
409
383
*
410
384
* @param input Stream to be fully buffered.
411
385
* @return A fully buffered stream.
412
- * @throws IOException if an I/O error occurs
413
386
* @since 2.0
414
387
*/
415
388
public static InputStream toBufferedInputStream (InputStream input ) {
@@ -612,8 +585,7 @@ public static byte[] toByteArray(URL url) throws IOException {
612
585
URLConnection conn = url .openConnection ();
613
586
try {
614
587
return IOUtils .toByteArray (conn );
615
- }
616
- finally {
588
+ } finally {
617
589
close (conn );
618
590
}
619
591
}
@@ -631,8 +603,7 @@ public static byte[] toByteArray(URLConnection urlConn) throws IOException {
631
603
InputStream inputStream = urlConn .getInputStream ();
632
604
try {
633
605
return IOUtils .toByteArray (inputStream );
634
- }
635
- finally {
606
+ } finally {
636
607
inputStream .close ();
637
608
}
638
609
}
@@ -864,8 +835,7 @@ public static String toString(URL url, Charset encoding) throws IOException {
864
835
InputStream inputStream = url .openStream ();
865
836
try {
866
837
return toString (inputStream , encoding );
867
- }
868
- finally {
838
+ } finally {
869
839
inputStream .close ();
870
840
}
871
841
}
@@ -2252,7 +2222,7 @@ public static void skipFully(Reader input, long toSkip) throws IOException {
2252
2222
* @param input where to read input from
2253
2223
* @param buffer destination
2254
2224
* @param offset inital offset into buffer
2255
- * @param length length to read, must be >= 0
2225
+ * @param length length to read, must
2256
2226
* @return actual length read; may be less than requested if EOF was reached
2257
2227
* @throws IOException if a read error occurs
2258
2228
* @since 2.2
@@ -2298,7 +2268,7 @@ public static int read(Reader input, char[] buffer) throws IOException {
2298
2268
* @param input where to read input from
2299
2269
* @param buffer destination
2300
2270
* @param offset inital offset into buffer
2301
- * @param length length to read, must be >= 0
2271
+ * @param length length to read,
2302
2272
* @return actual length read; may be less than requested if EOF was reached
2303
2273
* @throws IOException if a read error occurs
2304
2274
* @since 2.2
@@ -2344,7 +2314,7 @@ public static int read(InputStream input, byte[] buffer) throws IOException {
2344
2314
* @param input where to read input from
2345
2315
* @param buffer destination
2346
2316
* @param offset inital offset into buffer
2347
- * @param length length to read, must be >= 0
2317
+ * @param length length to read, must
2348
2318
* @throws IOException if there is a problem reading the file
2349
2319
* @throws IllegalArgumentException if length is negative
2350
2320
* @throws EOFException if the number of characters read was incorrect
@@ -2383,7 +2353,7 @@ public static void readFully(Reader input, char[] buffer) throws IOException {
2383
2353
* @param input where to read input from
2384
2354
* @param buffer destination
2385
2355
* @param offset inital offset into buffer
2386
- * @param length length to read, must be >= 0
2356
+ * @param length length to read
2387
2357
* @throws IOException if there is a problem reading the file
2388
2358
* @throws IllegalArgumentException if length is negative
2389
2359
* @throws EOFException if the number of bytes read was incorrect
0 commit comments