1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.qedeq.base.io; |
19 |
|
|
20 |
|
import java.io.BufferedOutputStream; |
21 |
|
import java.io.BufferedReader; |
22 |
|
import java.io.BufferedWriter; |
23 |
|
import java.io.ByteArrayInputStream; |
24 |
|
import java.io.File; |
25 |
|
import java.io.FileFilter; |
26 |
|
import java.io.FileInputStream; |
27 |
|
import java.io.FileOutputStream; |
28 |
|
import java.io.FileReader; |
29 |
|
import java.io.FileWriter; |
30 |
|
import java.io.IOException; |
31 |
|
import java.io.InputStream; |
32 |
|
import java.io.InputStreamReader; |
33 |
|
import java.io.OutputStream; |
34 |
|
import java.io.OutputStreamWriter; |
35 |
|
import java.io.Reader; |
36 |
|
import java.io.UnsupportedEncodingException; |
37 |
|
import java.lang.reflect.Field; |
38 |
|
import java.net.MalformedURLException; |
39 |
|
import java.net.URL; |
40 |
|
import java.nio.charset.Charset; |
41 |
|
import java.util.ArrayList; |
42 |
|
import java.util.Arrays; |
43 |
|
import java.util.Enumeration; |
44 |
|
import java.util.List; |
45 |
|
import java.util.Properties; |
46 |
|
import java.util.StringTokenizer; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@version |
55 |
|
@author |
56 |
|
|
|
|
| 37,6% |
Uncovered Elements: 272 (436) |
Complexity: 124 |
Complexity Density: 0,43 |
|
57 |
|
public final class IoUtility { |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
62 |
0
|
private IoUtility() {... |
63 |
|
|
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@return |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
2
|
public static String getDefaultEncoding() {... |
72 |
2
|
return new InputStreamReader( |
73 |
|
new ByteArrayInputStream(new byte[0])).getEncoding(); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
@param |
81 |
|
@return |
82 |
|
|
83 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0,83 |
|
84 |
0
|
public static String getWorkingEncoding(final String encoding) {... |
85 |
0
|
if (encoding != null) { |
86 |
0
|
try { |
87 |
0
|
if (Charset.isSupported(encoding) |
88 |
|
&& Charset.forName(encoding).canEncode()) { |
89 |
0
|
return encoding; |
90 |
|
} |
91 |
|
} catch (RuntimeException e) { |
92 |
|
|
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
0
|
System.err.println("not supported encoding: " + encoding); |
99 |
0
|
return "ISO-8859-1"; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
@param |
106 |
|
@param |
107 |
|
@return |
108 |
|
@throws |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
110 |
0
|
public static String loadFile(final String filename, final String encoding)... |
111 |
|
throws IOException { |
112 |
|
|
113 |
0
|
final StringBuffer buffer = new StringBuffer(); |
114 |
0
|
loadFile(filename, buffer, encoding); |
115 |
0
|
return buffer.toString(); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
@param |
122 |
|
@param |
123 |
|
@param |
124 |
|
@throws |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0
|
public static void loadFile(final String filename,... |
127 |
|
final StringBuffer buffer, final String encoding) |
128 |
|
throws IOException { |
129 |
0
|
loadFile(new File(filename), buffer, encoding); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@param |
136 |
|
@param |
137 |
|
@throws |
138 |
|
|
139 |
|
@deprecated@link |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
141 |
0
|
public static void loadStream(final InputStream in, final StringBuffer buffer)... |
142 |
|
throws IOException { |
143 |
|
|
144 |
0
|
buffer.setLength(0); |
145 |
0
|
int c; |
146 |
0
|
while ((c = in.read()) >= 0) { |
147 |
0
|
buffer.append((char) c); |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
@link |
153 |
|
|
154 |
|
@param |
155 |
|
@param |
156 |
|
@throws |
157 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
158 |
2
|
public static void loadReader(final Reader in, final StringBuffer buffer)... |
159 |
|
throws IOException { |
160 |
|
|
161 |
2
|
buffer.setLength(0); |
162 |
2
|
int c; |
163 |
?
|
while ((c = in.read()) >= 0) { |
164 |
7322
|
buffer.append((char) c); |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
@param |
172 |
|
@param |
173 |
|
@throws |
174 |
|
|
175 |
|
@deprecated@link |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
177 |
0
|
public static void loadFile(final File file,... |
178 |
|
final StringBuffer buffer) |
179 |
|
throws IOException { |
180 |
|
|
181 |
0
|
final int size = (int) file.length(); |
182 |
0
|
buffer.setLength(0); |
183 |
0
|
final FileReader in = new FileReader(file); |
184 |
0
|
final char[] data = new char[size]; |
185 |
0
|
int charsread = 0; |
186 |
0
|
while (charsread < size) { |
187 |
0
|
charsread += in.read(data, charsread, size - charsread); |
188 |
|
} |
189 |
0
|
in.close(); |
190 |
0
|
buffer.insert(0, data); |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
@param |
197 |
|
@param |
198 |
|
@param |
199 |
|
@throws |
200 |
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
201 |
1
|
public static void loadFile(final File file,... |
202 |
|
final StringBuffer buffer, final String encoding) |
203 |
|
throws IOException { |
204 |
|
|
205 |
1
|
buffer.setLength((int) file.length()); |
206 |
1
|
buffer.setLength(0); |
207 |
1
|
final InputStreamReader in = new InputStreamReader(new FileInputStream(file), encoding); |
208 |
1
|
final char[] data = new char[10 * 1024]; |
209 |
|
|
210 |
1
|
try { |
211 |
1
|
int charsread = 0; |
212 |
?
|
while (0 < (charsread = in.read(data, 0, data.length))) { |
213 |
1
|
buffer.append(data, 0, charsread); |
214 |
|
} |
215 |
|
} finally { |
216 |
1
|
in.close(); |
217 |
|
} |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@param |
224 |
|
@return |
225 |
|
@throws |
226 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 3 |
Complexity Density: 0,2 |
|
227 |
0
|
public static final byte[] loadFileBinary(final File file) throws IOException {... |
228 |
0
|
final int size = (int) file.length(); |
229 |
0
|
final FileInputStream in = new FileInputStream(file); |
230 |
0
|
try { |
231 |
0
|
final byte[] data = new byte[size]; |
232 |
0
|
int charsread = 0; |
233 |
0
|
while (charsread < size) { |
234 |
0
|
final int read = in.read(data, charsread, size - charsread); |
235 |
0
|
if (read == -1) { |
236 |
0
|
final byte[] result = new byte[charsread]; |
237 |
0
|
System.arraycopy(data, 0, result, 0, charsread); |
238 |
0
|
return result; |
239 |
|
} |
240 |
0
|
charsread += read; |
241 |
|
} |
242 |
0
|
in.close(); |
243 |
0
|
return data; |
244 |
|
} finally { |
245 |
0
|
close(in); |
246 |
|
} |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
@param |
253 |
|
@param |
254 |
|
@throws |
255 |
|
|
256 |
|
@deprecated |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0,2 |
|
258 |
0
|
public static void loadFile(final URL url, final StringBuffer buffer) throws IOException {... |
259 |
0
|
InputStream in = null; |
260 |
0
|
BufferedReader dis = null; |
261 |
0
|
try { |
262 |
0
|
in = url.openStream(); |
263 |
0
|
dis = new BufferedReader(new InputStreamReader(in)); |
264 |
0
|
int i; |
265 |
0
|
while ((i = dis.read()) != -1) { |
266 |
0
|
buffer.append((char) i); |
267 |
|
} |
268 |
|
} finally { |
269 |
0
|
close(in); |
270 |
0
|
close(dis); |
271 |
|
} |
272 |
|
} |
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
@param |
277 |
|
@param |
278 |
|
@param |
279 |
|
@throws |
280 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0,2 |
|
281 |
0
|
public static void loadFile(final URL url, final StringBuffer buffer, final String encoding)... |
282 |
|
throws IOException { |
283 |
0
|
InputStream in = null; |
284 |
0
|
BufferedReader dis = null; |
285 |
0
|
try { |
286 |
0
|
in = url.openStream(); |
287 |
0
|
dis = new BufferedReader(new InputStreamReader(in, encoding)); |
288 |
0
|
int i; |
289 |
0
|
while ((i = dis.read()) != -1) { |
290 |
0
|
buffer.append((char) i); |
291 |
|
} |
292 |
|
} finally { |
293 |
0
|
close(in); |
294 |
0
|
close(dis); |
295 |
|
} |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
@param |
302 |
|
@param |
303 |
|
@throws |
304 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
305 |
0
|
public static void saveFile(final URL url, final File file) throws IOException {... |
306 |
0
|
saveFile(url.openStream(), file); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
@param |
313 |
|
@param |
314 |
|
|
315 |
|
@throws |
316 |
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
317 |
18
|
public static void saveFile(final InputStream in, final File file) throws IOException {... |
318 |
18
|
FileOutputStream out = null; |
319 |
18
|
try { |
320 |
18
|
out = new FileOutputStream(file); |
321 |
18
|
final byte[] data = new byte[8 * 1024]; |
322 |
18
|
int length; |
323 |
?
|
while ((length = in.read(data)) != -1) { |
324 |
90
|
out.write(data, 0, length); |
325 |
|
} |
326 |
|
} finally { |
327 |
18
|
close(in); |
328 |
18
|
close(out); |
329 |
|
} |
330 |
|
} |
331 |
|
|
332 |
|
|
333 |
|
@link |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
@param |
339 |
|
@return |
340 |
|
|
|
|
| 66,7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0,67 |
|
341 |
137
|
public static final Reader stringToReader(final String data) {... |
342 |
137
|
try { |
343 |
137
|
return new InputStreamReader(new ByteArrayInputStream(data.getBytes("ISO-8859-1"))); |
344 |
|
} catch (UnsupportedEncodingException e) { |
345 |
0
|
throw new RuntimeException(e); |
346 |
|
} |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
@param |
354 |
|
@param |
355 |
|
@throws |
356 |
|
|
357 |
|
@deprecated@link |
358 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
359 |
0
|
public static void saveFile(final String filename, final String text)... |
360 |
|
throws IOException { |
361 |
0
|
saveFile(new File(filename), text); |
362 |
|
} |
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
@param |
368 |
|
@param |
369 |
|
@throws |
370 |
|
|
371 |
|
@deprecated@link |
372 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
373 |
0
|
public static void saveFile(final String filename, final StringBuffer text)... |
374 |
|
throws IOException { |
375 |
0
|
saveFile(new File(filename), text.toString()); |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
@param |
382 |
|
@param |
383 |
|
@throws |
384 |
|
|
385 |
|
@deprecated@link |
386 |
|
|
387 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
388 |
0
|
public static void saveFile(final File file, final StringBuffer text)... |
389 |
|
throws IOException { |
390 |
0
|
saveFile(file, text.toString()); |
391 |
|
} |
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
@param |
397 |
|
@param |
398 |
|
@throws |
399 |
|
|
400 |
|
@deprecated@link |
401 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
402 |
0
|
public static void saveFile(final File file, final String text)... |
403 |
|
throws IOException { |
404 |
0
|
BufferedWriter out = new BufferedWriter( |
405 |
|
new FileWriter(file)); |
406 |
0
|
out.write(text); |
407 |
0
|
out.close(); |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
@param |
414 |
|
@param |
415 |
|
@param |
416 |
|
@throws |
417 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
418 |
0
|
public static void saveFile(final File file, final StringBuffer text, final String encoding)... |
419 |
|
throws IOException { |
420 |
0
|
saveFile(file, text.toString(), encoding); |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
@param |
427 |
|
@param |
428 |
|
@param |
429 |
|
@throws |
430 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
431 |
1
|
public static void saveFile(final File file, final String text, final String encoding)... |
432 |
|
throws IOException { |
433 |
1
|
BufferedWriter out = new BufferedWriter( |
434 |
|
new OutputStreamWriter(new FileOutputStream(file), encoding)); |
435 |
1
|
out.write(text); |
436 |
1
|
out.close(); |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
@param |
443 |
|
@param |
444 |
|
@throws |
445 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
446 |
0
|
public static void saveFileBinary(final File file, final byte[] data)... |
447 |
|
throws IOException { |
448 |
0
|
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); |
449 |
0
|
out.write(data); |
450 |
0
|
out.close(); |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
@param |
457 |
|
@param |
458 |
|
@throws |
459 |
|
|
|
|
| 71,4% |
Uncovered Elements: 4 (14) |
Complexity: 3 |
Complexity Density: 0,3 |
|
460 |
54
|
public static void copyFile(final File from, final File to)... |
461 |
|
throws IOException { |
462 |
|
|
463 |
54
|
if (from.getCanonicalFile().equals(to.getCanonicalFile())) { |
464 |
0
|
return; |
465 |
|
} |
466 |
54
|
FileInputStream in = new FileInputStream(from); |
467 |
54
|
FileOutputStream out = new FileOutputStream(to); |
468 |
|
|
469 |
54
|
byte[] data = new byte[8 * 1024]; |
470 |
54
|
int length; |
471 |
|
|
472 |
?
|
while ((length = in.read(data)) != -1) { |
473 |
538
|
out.write(data, 0, length); |
474 |
|
} |
475 |
54
|
in.close(); |
476 |
54
|
out.close(); |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
@param |
483 |
|
@param |
484 |
|
@return |
485 |
|
@throws |
486 |
|
|
|
|
| 63,2% |
Uncovered Elements: 14 (38) |
Complexity: 10 |
Complexity Density: 0,42 |
|
487 |
3
|
public static boolean compareFilesBinary(final File from, final File with)... |
488 |
|
throws IOException { |
489 |
3
|
if (from == null && with == null) { |
490 |
0
|
return true; |
491 |
|
} |
492 |
3
|
if (from == null || with == null) { |
493 |
0
|
return false; |
494 |
|
} |
495 |
3
|
if (from.getAbsoluteFile().equals(with.getAbsoluteFile())) { |
496 |
0
|
return true; |
497 |
|
} |
498 |
3
|
if (from.length() != with.length()) { |
499 |
0
|
return false; |
500 |
|
} |
501 |
3
|
byte[] dataOne = new byte[8 * 1024]; |
502 |
3
|
byte[] dataTwo = new byte[8 * 1024]; |
503 |
3
|
int length; |
504 |
|
|
505 |
3
|
FileInputStream one = null; |
506 |
3
|
FileInputStream two = null; |
507 |
3
|
try { |
508 |
3
|
one = new FileInputStream(from); |
509 |
3
|
two = new FileInputStream(with); |
510 |
|
|
511 |
?
|
while ((length = one.read(dataOne)) != -1) { |
512 |
36
|
if (length != two.read(dataTwo)) { |
513 |
0
|
return false; |
514 |
|
} |
515 |
36
|
if (!Arrays.equals(dataOne, dataTwo)) { |
516 |
0
|
return false; |
517 |
|
} |
518 |
|
} |
519 |
3
|
return true; |
520 |
|
} finally { |
521 |
3
|
close(one); |
522 |
3
|
close(two); |
523 |
|
} |
524 |
|
} |
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
@param |
530 |
|
@param |
531 |
|
@return |
532 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 8 |
Complexity Density: 0,42 |
|
533 |
0
|
public static boolean deleteDir(final File directory, final boolean deleteDir) {... |
534 |
|
|
535 |
|
|
536 |
|
|
537 |
0
|
File candir; |
538 |
0
|
try { |
539 |
0
|
candir = directory.getCanonicalFile(); |
540 |
|
} catch (IOException e) { |
541 |
0
|
return false; |
542 |
|
} |
543 |
|
|
544 |
|
|
545 |
|
|
546 |
0
|
if (!candir.equals(directory.getAbsoluteFile())) { |
547 |
|
|
548 |
|
|
549 |
|
|
550 |
0
|
return false; |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
|
|
555 |
0
|
boolean success = true; |
556 |
0
|
File[] files = candir.listFiles(); |
557 |
0
|
if (files != null) { |
558 |
0
|
for (int i = 0; i < files.length; i++) { |
559 |
0
|
File file = files[i]; |
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
|
564 |
0
|
boolean deleted = file.delete(); |
565 |
0
|
if (!deleted) { |
566 |
|
|
567 |
|
|
568 |
0
|
if (file.isDirectory()) { |
569 |
0
|
deleted = deleteDir(file, true); |
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
|
} |
574 |
0
|
success = success && deleted; |
575 |
|
} |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
0
|
if (deleteDir) { |
581 |
0
|
return directory.delete(); |
582 |
|
} |
583 |
0
|
return success; |
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
@param |
591 |
|
@param |
592 |
|
@return |
593 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 7 |
Complexity Density: 0,41 |
|
594 |
0
|
public static boolean deleteDir(final File directory, final FileFilter filter) {... |
595 |
|
|
596 |
|
|
597 |
|
|
598 |
0
|
File candir; |
599 |
0
|
try { |
600 |
0
|
candir = directory.getCanonicalFile(); |
601 |
|
} catch (IOException e) { |
602 |
0
|
return false; |
603 |
|
} |
604 |
|
|
605 |
|
|
606 |
|
|
607 |
0
|
if (!candir.equals(directory.getAbsoluteFile())) { |
608 |
|
|
609 |
|
|
610 |
|
|
611 |
0
|
return false; |
612 |
|
} |
613 |
|
|
614 |
|
|
615 |
|
|
616 |
0
|
boolean success = true; |
617 |
0
|
File[] files = candir.listFiles(filter); |
618 |
0
|
if (files != null) { |
619 |
0
|
for (int i = 0; i < files.length; i++) { |
620 |
0
|
File file = files[i]; |
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
|
625 |
0
|
boolean deleted = file.delete(); |
626 |
0
|
if (!deleted) { |
627 |
|
|
628 |
|
|
629 |
0
|
if (file.isDirectory()) { |
630 |
0
|
deleted = deleteDir(file, true); |
631 |
|
} |
632 |
|
|
633 |
|
|
634 |
|
} |
635 |
0
|
success = success && deleted; |
636 |
|
} |
637 |
|
} |
638 |
|
|
639 |
0
|
return success; |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
645 |
0
|
public static void printAllSystemProperties() {... |
646 |
0
|
Properties sysprops = System.getProperties(); |
647 |
0
|
for (Enumeration e = sysprops.propertyNames(); e.hasMoreElements(); ) { |
648 |
0
|
String key = (String) e.nextElement(); |
649 |
0
|
String value = sysprops.getProperty(key); |
650 |
0
|
System.out.println(key + "=" + value); |
651 |
|
} |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
@return |
658 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
659 |
0
|
public static File getUserHomeDirectory() {... |
660 |
0
|
return new File((String) System.getProperties().get("user.home")); |
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
@param |
667 |
|
@return |
668 |
|
|
|
|
| 66,7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0,67 |
|
669 |
7658
|
public static URL toUrl(final File file) {... |
670 |
7658
|
try { |
671 |
7658
|
return file.toURI().toURL(); |
672 |
|
} catch (MalformedURLException e) { |
673 |
0
|
throw new RuntimeException(e); |
674 |
|
} |
675 |
|
} |
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
|
680 |
|
@param |
681 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
682 |
39
|
public static void createNecessaryDirectories(final File file) {... |
683 |
39
|
if (file.getParentFile() != null) { |
684 |
39
|
file.getParentFile().mkdirs(); |
685 |
|
} |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
@param |
692 |
|
@param |
693 |
|
@return |
694 |
|
|
|
|
| 68,9% |
Uncovered Elements: 14 (45) |
Complexity: 13 |
Complexity Density: 0,45 |
|
695 |
4
|
public static final String createRelativePath(final File orgin, final File next) {... |
696 |
4
|
try { |
697 |
4
|
if (orgin.equals(next)) { |
698 |
0
|
return ""; |
699 |
|
} |
700 |
4
|
try { |
701 |
4
|
String org = orgin.getCanonicalPath().replace('\\', '/'); |
702 |
4
|
if (!org.endsWith("/")) { |
703 |
4
|
org += ('/'); |
704 |
|
} |
705 |
4
|
String nex = next.getCanonicalPath().replace('\\', '/'); |
706 |
4
|
if (!nex.endsWith("/")) { |
707 |
4
|
nex += ('/'); |
708 |
|
} |
709 |
4
|
if (org.equals(nex)) { |
710 |
0
|
return ""; |
711 |
|
} |
712 |
4
|
int i = -1; |
713 |
4
|
int j = 0; |
714 |
?
|
while (0 <= (i = org.indexOf("/", j))) { |
715 |
17
|
if (i >= 0 && nex.length() > i |
716 |
|
&& org.substring(j, i).equals( |
717 |
|
nex.substring(j, i))) { |
718 |
15
|
j = i + 1; |
719 |
|
} else { |
720 |
2
|
break; |
721 |
|
} |
722 |
|
} |
723 |
4
|
if (j > 0) { |
724 |
4
|
i = j; |
725 |
4
|
final StringBuffer result = new StringBuffer(nex.length()); |
726 |
?
|
while (0 <= (i = org.indexOf("/", i))) { |
727 |
3
|
i++; |
728 |
3
|
result.append("../"); |
729 |
|
} |
730 |
4
|
result.append(nex.substring(j, nex.length() - 1)); |
731 |
4
|
return result.toString(); |
732 |
|
} |
733 |
0
|
return nex.substring(0, nex.length() - 1); |
734 |
|
} catch (RuntimeException e) { |
735 |
0
|
return next.toString(); |
736 |
|
} |
737 |
|
} catch (IOException e) { |
738 |
0
|
return new File(orgin, next.getPath()).getPath(); |
739 |
|
} |
740 |
|
} |
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0,67 |
|
745 |
0
|
public static void waitln() {... |
746 |
0
|
System.out.println("\n..press <return> to continue"); |
747 |
0
|
try { |
748 |
0
|
(new java.io.BufferedReader(new java.io.InputStreamReader( |
749 |
|
System.in))).readLine(); |
750 |
|
} catch (IOException e) { |
751 |
|
|
752 |
|
} |
753 |
|
} |
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
|
758 |
|
@param |
759 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
760 |
24
|
public static void close(final InputStream in) {... |
761 |
24
|
if (in != null) { |
762 |
24
|
try { |
763 |
24
|
in.close(); |
764 |
|
} catch (Exception e) { |
765 |
|
|
766 |
|
} |
767 |
|
} |
768 |
|
} |
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
|
773 |
|
@param |
774 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
775 |
57
|
public static void close(final OutputStream out) {... |
776 |
57
|
if (out != null) { |
777 |
57
|
try { |
778 |
57
|
out.close(); |
779 |
|
} catch (Exception e) { |
780 |
|
|
781 |
|
} |
782 |
|
} |
783 |
|
} |
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
|
788 |
|
@param |
789 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
790 |
61691
|
public static void close(final Reader reader) {... |
791 |
61691
|
if (reader != null) { |
792 |
61691
|
try { |
793 |
61691
|
reader.close(); |
794 |
|
} catch (Exception e) { |
795 |
|
|
796 |
|
} |
797 |
|
} |
798 |
|
} |
799 |
|
|
800 |
|
|
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
@param |
807 |
|
|
808 |
|
|
809 |
|
@return |
810 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
811 |
0
|
public static final File getStartDirectory(final String application) {... |
812 |
0
|
final File startDirectory; |
813 |
0
|
if (isWebStarted()) { |
814 |
0
|
final String userHome = System.getProperty("user.home", "."); |
815 |
0
|
startDirectory = new File(new File(userHome), "." + application); |
816 |
|
} else { |
817 |
0
|
startDirectory = new File("."); |
818 |
|
} |
819 |
0
|
return startDirectory; |
820 |
|
} |
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
@return |
826 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
827 |
0
|
public static final boolean isWebStarted() {... |
828 |
0
|
final String webStart = (String) System.getProperties().get("javawebstart.version"); |
829 |
0
|
return webStart != null; |
830 |
|
} |
831 |
|
|
832 |
|
|
833 |
|
|
834 |
|
|
835 |
|
@param |
836 |
|
@return |
837 |
|
@throws |
838 |
|
@throws |
839 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
840 |
0
|
public static Properties loadProperties(final URL url)... |
841 |
|
throws IOException { |
842 |
0
|
Properties newprops = new Properties(); |
843 |
0
|
InputStream in = url.openStream(); |
844 |
0
|
newprops.load(in); |
845 |
0
|
in.close(); |
846 |
0
|
return newprops; |
847 |
|
} |
848 |
|
|
849 |
|
|
850 |
|
|
851 |
|
|
852 |
|
@param |
853 |
|
@param |
854 |
|
@return |
855 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 5 |
Complexity Density: 0,5 |
|
856 |
25278
|
public static Object getFieldContent(final Object obj, final String name) {... |
857 |
25278
|
final Field field; |
858 |
25278
|
try { |
859 |
25278
|
field = obj.getClass().getDeclaredField(name); |
860 |
25278
|
field.setAccessible(true); |
861 |
|
} catch (SecurityException e) { |
862 |
0
|
throw new RuntimeException(e); |
863 |
|
} catch (NoSuchFieldException e) { |
864 |
0
|
throw new RuntimeException(e); |
865 |
|
} |
866 |
25278
|
try { |
867 |
25278
|
return field.get(obj); |
868 |
|
} catch (IllegalArgumentException e) { |
869 |
0
|
throw new RuntimeException(e); |
870 |
|
} catch (IllegalAccessException e) { |
871 |
0
|
throw new RuntimeException(e); |
872 |
|
} |
873 |
|
} |
874 |
|
|
875 |
|
|
876 |
|
|
877 |
|
|
878 |
|
@param |
879 |
|
@param |
880 |
|
@return |
881 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 6 |
Complexity Density: 0,4 |
|
882 |
0
|
public static Object getFieldContentSuper(final Object obj, final String name) {... |
883 |
0
|
Field field = null; |
884 |
0
|
try { |
885 |
0
|
Class cl = obj.getClass(); |
886 |
0
|
while (!Object.class.equals(cl)) { |
887 |
0
|
try { |
888 |
0
|
field = cl.getDeclaredField(name); |
889 |
0
|
break; |
890 |
|
} catch (NoSuchFieldException ex) { |
891 |
0
|
cl = cl.getSuperclass(); |
892 |
0
|
System.out.println(cl); |
893 |
|
} |
894 |
|
} |
895 |
0
|
field.setAccessible(true); |
896 |
|
} catch (SecurityException e) { |
897 |
0
|
throw new RuntimeException(e); |
898 |
|
|
899 |
|
|
900 |
|
} |
901 |
0
|
try { |
902 |
0
|
return field.get(obj); |
903 |
|
} catch (IllegalArgumentException e) { |
904 |
0
|
throw new RuntimeException(e); |
905 |
|
} catch (IllegalAccessException e) { |
906 |
0
|
throw new RuntimeException(e); |
907 |
|
} |
908 |
|
} |
909 |
|
|
910 |
|
|
911 |
|
|
912 |
|
|
913 |
|
@param |
914 |
|
@param |
915 |
|
@param |
916 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 5 |
Complexity Density: 0,5 |
|
917 |
3
|
public static void setFieldContent(final Object obj, final String name, final Object value) {... |
918 |
3
|
final Field field; |
919 |
3
|
try { |
920 |
3
|
field = obj.getClass().getDeclaredField(name); |
921 |
3
|
field.setAccessible(true); |
922 |
|
} catch (SecurityException e) { |
923 |
0
|
throw new RuntimeException(e); |
924 |
|
} catch (NoSuchFieldException e) { |
925 |
0
|
throw new RuntimeException(e); |
926 |
|
} |
927 |
3
|
try { |
928 |
3
|
field.set(obj, value); |
929 |
|
} catch (IllegalArgumentException e) { |
930 |
0
|
throw new RuntimeException(e); |
931 |
|
} catch (IllegalAccessException e) { |
932 |
0
|
throw new RuntimeException(e); |
933 |
|
} |
934 |
|
} |
935 |
|
|
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
@param |
940 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
|
941 |
0
|
public static void sleep(final int ms) {... |
942 |
0
|
final String monitor = ""; |
943 |
0
|
synchronized (monitor) { |
944 |
0
|
try { |
945 |
0
|
monitor.wait(ms); |
946 |
|
} catch (InterruptedException e) { |
947 |
|
} |
948 |
|
} |
949 |
|
} |
950 |
|
|
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
|
955 |
|
@return |
956 |
|
|
|
|
| 86,2% |
Uncovered Elements: 4 (29) |
Complexity: 7 |
Complexity Density: 0,37 |
|
957 |
39
|
public static int[] getJavaVersion() {... |
958 |
39
|
final String version = System.getProperty("java.version"); |
959 |
39
|
final List numbers = new ArrayList(); |
960 |
39
|
final StringTokenizer tokenizer = new StringTokenizer(version, "."); |
961 |
156
|
while (tokenizer.hasMoreElements()) { |
962 |
117
|
String sub = (String) tokenizer.nextToken(); |
963 |
234
|
for (int i = 0; i < sub.length(); i++) { |
964 |
156
|
if (!Character.isDigit(sub.charAt(i))) { |
965 |
39
|
sub = sub.substring(0, i); |
966 |
39
|
break; |
967 |
|
} |
968 |
|
} |
969 |
117
|
try { |
970 |
117
|
numbers.add(new Integer(Integer.parseInt(sub))); |
971 |
|
} catch (Exception e) { |
972 |
0
|
e.printStackTrace(); |
973 |
0
|
break; |
974 |
|
} |
975 |
|
} |
976 |
39
|
if (numbers.size() == 0) { |
977 |
0
|
return null; |
978 |
|
} |
979 |
39
|
final int[] result = new int[numbers.size()]; |
980 |
156
|
for (int i = 0; i < numbers.size(); i++) { |
981 |
117
|
result[i] = ((Integer) numbers.get(i)).intValue(); |
982 |
|
} |
983 |
39
|
return result; |
984 |
|
} |
985 |
|
|
986 |
|
} |