1 package org.apache.struts.scripting;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.Reader;
6 import java.nio.file.Files;
7 import java.nio.file.Path;
8 import java.nio.file.attribute.BasicFileAttributes;
9 import java.nio.file.attribute.FileTime;
10
11
12
13
14
15
16
17
18 class IOUtils {
19
20 private IOUtils() {}
21
22
23
24
25
26
27
28
29
30
31
32
33
34 static FileTime getLastModifiedTime(final Path path) throws IOException {
35 if (path == null) {
36 return null;
37 }
38
39 BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
40 return attr.lastModifiedTime();
41 }
42
43
44
45
46
47
48
49
50
51
52
53 static String getStringFromReader(Reader reader) throws IOException {
54 try (BufferedReader br = reader instanceof BufferedReader
55 ? (BufferedReader)reader
56 : new BufferedReader(reader)) {
57
58 final String lineSeparator = System.lineSeparator();
59 final StringBuilder sb = new StringBuilder(8 * 1024);
60
61 String line;
62 while ((line = br.readLine()) != null) {
63 sb.append(lineSeparator).append(line);
64 }
65
66 return sb.substring(sb.length() == 0 ? 0 : lineSeparator.length());
67 }
68 }
69 }