dd9035a83591fddec44c988ecadfc6c1d927bac0.svn-base
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.thinkgem.jeesite.modules.cms.entity;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
/**
* User: songlai
* Date: 13-8-22
* Time: 上午9:44
*/
public class FileTpl {
private File file;
// 应用的根目录
private String root;
public FileTpl(File file, String root) {
this.file = file;
this.root = root;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getRoot() {
return root;
}
public void setRoot(String root) {
this.root = root;
}
public String getName() {
String ap = file.getAbsolutePath().substring(root.length());
ap = ap.replace(File.separatorChar, '/');
// 在resin里root的结尾是带'/'的,这样会导致getName返回的名称不以'/'开头。
if (!ap.startsWith("/")) {
ap = "/" + ap;
}
return ap;
}
public String getParent(){
String ap = file.getParent().substring(root.length());
ap = ap.replace(File.separatorChar, '/');
// 在resin里root的结尾是带'/'的,这样会导致getName返回的名称不以'/'开头。
if (!ap.startsWith("/")) {
ap = "/" + ap;
}
return ap;
}
public String getPath() {
String name = getName();
return name.substring(0, name.lastIndexOf('/'));
}
public String getFilename() {
return file.getName();
}
public String getSource() {
if (file.isDirectory()) {
return null;
}
try {
return FileUtils.readFileToString(this.file, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public long getLastModified() {
return file.lastModified();
}
public Date getLastModifiedDate() {
return new Timestamp(getLastModified());
}
public long getLength() {
return file.length();
}
public int getSize() {
return (int) (getLength() / 1024) + 1;
}
public boolean isDirectory() {
return file.isDirectory();
}
}