/
PathAttributes.java
212 lines (180 loc) · 5.24 KB
/
PathAttributes.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package ch.cyberduck.core;
/*
* Copyright (c) 2005 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to:
* dkocher@cyberduck.ch
*/
import ch.cyberduck.core.i18n.Locale;
import ch.cyberduck.core.serializer.Deserializer;
import ch.cyberduck.core.serializer.DeserializerFactory;
import ch.cyberduck.core.serializer.Serializer;
import ch.cyberduck.core.serializer.SerializerFactory;
import org.apache.log4j.Logger;
/**
* Attributes of a remote directory or file.
*
* @version $Id$
*/
public class PathAttributes implements Attributes, Serializable {
private static Logger log = Logger.getLogger(PathAttributes.class);
/**
* The file length
*/
private long size = -1;
/**
* The file modification date
*/
private long modified = -1;
private long accessed = -1;
private long created = -1;
private String owner = null;
private String group = null;
/**
* The file type
*/
private int type = Path.FILE_TYPE;
protected Permission permission = null;
private String checksum;
public PathAttributes() {
super();
}
public <T> PathAttributes(T dict) {
this.init(dict);
}
public <T> void init(T serialized) {
final Deserializer dict = DeserializerFactory.createDeserializer(serialized);
String typeObj = dict.stringForKey("Type");
if(typeObj != null) {
this.type = Integer.parseInt(typeObj);
}
String sizeObj = dict.stringForKey("Size");
if(sizeObj != null) {
this.size = Long.parseLong(sizeObj);
}
String modifiedObj = dict.stringForKey("Modified");
if(modifiedObj != null) {
this.modified = Long.parseLong(modifiedObj);
}
Object permissionObj = dict.objectForKey("Permission");
if(permissionObj != null) {
this.permission = new Permission(permissionObj);
}
}
public <T> T getAsDictionary() {
final Serializer dict = SerializerFactory.createSerializer();
dict.setStringForKey(String.valueOf(this.type), "Type");
if(this.size != -1) {
dict.setStringForKey(String.valueOf(this.size), "Size");
}
if(this.modified != -1) {
dict.setStringForKey(String.valueOf(this.modified), "Modified");
}
if(null != permission) {
dict.setObjectForKey(permission, "Permission");
}
return dict.<T>getSerialized();
}
/**
* @param size the size of file in bytes.
*/
public void setSize(long size) {
this.size = size;
}
/**
* @return length the size of file in bytes.
*/
public long getSize() {
return this.size;
}
public long getModificationDate() {
return this.modified;
}
public void setModificationDate(long millis) {
this.modified = millis;
}
public long getCreationDate() {
return this.created;
}
public void setCreationDate(long millis) {
this.created = millis;
}
public long getAccessedDate() {
return this.accessed;
}
public void setAccessedDate(long millis) {
this.accessed = millis;
}
/**
* @param p
*/
public void setPermission(Permission p) {
this.permission = p;
}
/**
* @return
*/
public Permission getPermission() {
return this.permission;
}
public void setType(int type) {
this.type = type;
}
public int getType() {
return this.type;
}
public boolean isVolume() {
return (this.type & Path.VOLUME_TYPE) == Path.VOLUME_TYPE;
}
public boolean isDirectory() {
return (this.type & Path.DIRECTORY_TYPE) == Path.DIRECTORY_TYPE
|| this.isVolume();
}
public boolean isFile() {
return (this.type & Path.FILE_TYPE) == Path.FILE_TYPE;
}
public boolean isSymbolicLink() {
return (this.type & Path.SYMBOLIC_LINK_TYPE) == Path.SYMBOLIC_LINK_TYPE;
}
public void setOwner(String o) {
this.owner = o;
}
/**
* @return The owner of the file or 'Unknown' if not set
*/
public String getOwner() {
if(null == this.owner) {
return Locale.localizedString("Unknown");
}
return this.owner;
}
public void setGroup(String g) {
this.group = g;
}
/**
* @return
*/
public String getGroup() {
if(null == this.group) {
return Locale.localizedString("Unknown");
}
return this.group;
}
public String getChecksum() {
return checksum;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
}