litesoft
Diff Revisions
927
vs
961
for /trunk/DeviceDesktopTest/src/org/litesoft/utils/FileUtils.java
|
@@ -2,23 +2,18 @@ |
2 |
2 |
|
|
3 |
3 |
|
import java.io.*; |
4 |
4 |
|
|
5 |
|
- |
public class FileUtils |
6 |
|
- |
{ |
|
5 |
+ |
public class FileUtils { |
7 |
6 |
|
public static final String UTF_8 = "UTF-8"; |
8 |
7 |
|
|
9 |
8 |
|
public static String loadTextFileAsString( InputStream pInputStream, String pLineSeparator ) |
10 |
|
- |
throws IOException |
11 |
|
- |
{ |
|
9 |
+ |
throws IOException { |
12 |
10 |
|
StringBuilder buffer = new StringBuilder(); |
13 |
11 |
|
BufferedReader reader = createReader( pInputStream ); |
14 |
12 |
|
boolean closed = false; |
15 |
|
- |
try |
16 |
|
- |
{ |
|
13 |
+ |
try { |
17 |
14 |
|
int count = 0; |
18 |
|
- |
for ( String line; null != (line = reader.readLine()); count++ ) |
19 |
|
- |
{ |
20 |
|
- |
if ( count > 0 ) |
21 |
|
- |
{ |
|
15 |
+ |
for ( String line; null != (line = reader.readLine()); count++ ) { |
|
16 |
+ |
if ( count > 0 ) { |
22 |
17 |
|
buffer.append( pLineSeparator ); |
23 |
18 |
|
} |
24 |
19 |
|
buffer.append( line ); |
|
@@ -26,16 +21,12 @@ |
26 |
21 |
|
closed = true; |
27 |
22 |
|
reader.close(); |
28 |
23 |
|
} |
29 |
|
- |
finally |
30 |
|
- |
{ |
31 |
|
- |
if ( !closed ) |
32 |
|
- |
{ |
33 |
|
- |
try |
34 |
|
- |
{ |
|
24 |
+ |
finally { |
|
25 |
+ |
if ( !closed ) { |
|
26 |
+ |
try { |
35 |
27 |
|
reader.close(); |
36 |
28 |
|
} |
37 |
|
- |
catch ( IOException ignore ) |
38 |
|
- |
{ |
|
29 |
+ |
catch ( IOException ignore ) { |
39 |
30 |
|
// Whatever... |
40 |
31 |
|
} |
41 |
32 |
|
} |
|
@@ -45,8 +36,7 @@ |
45 |
36 |
|
} |
46 |
37 |
|
|
47 |
38 |
|
public static BufferedReader createReader( InputStream pInputStream ) |
48 |
|
- |
throws IOException |
49 |
|
- |
{ |
|
39 |
+ |
throws IOException { |
50 |
40 |
|
return new BufferedReader( new InputStreamReader( pInputStream, UTF_8 ) ); |
51 |
41 |
|
} |
52 |
42 |
|
} |