001: /**
002: *
003: * edtFTPj
004: *
005: * Copyright (C) 2000-2004 Enterprise Distributed Technologies Ltd
006: *
007: * www.enterprisedt.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: *
023: * Bug fixes, suggestions and comments should be should posted on
024: * http://www.enterprisedt.com/forums/index.php
025: *
026: * Change Log:
027: *
028: * $Log: FTPFile.java,v $
029: * Revision 1.17 2007-10-12 05:21:29 bruceb
030: * print out null if lastmodified is null
031: *
032: * Revision 1.16 2007-08-09 00:10:53 hans
033: * Removed unused imports.
034: *
035: * Revision 1.15 2007/04/21 04:25:14 bruceb
036: * added listFiles() and children
037: *
038: * Revision 1.14 2007/01/15 23:03:48 bruceb
039: * added some setters, new constructor (for MLST)
040: *
041: * Revision 1.13 2006/10/11 08:53:43 hans
042: * made cvsId final
043: *
044: * Revision 1.12 2006/02/09 09:01:52 bruceb
045: * made setters public
046: *
047: * Revision 1.11 2005/06/03 11:26:05 bruceb
048: * VMS stuff
049: *
050: * Revision 1.10 2005/03/03 21:06:46 bruceb
051: * removed type
052: *
053: * Revision 1.9 2005/02/04 12:21:30 bruceb
054: * made FTPFile constructor public
055: *
056: * Revision 1.8 2004/09/17 14:13:00 bruceb
057: * added link count
058: *
059: * Revision 1.7 2004/09/02 11:02:31 bruceb
060: * rolled back
061: *
062: *
063: */package com.enterprisedt.net.ftp;
064:
065: import java.text.SimpleDateFormat;
066: import java.util.Date;
067:
068: /**
069: * Represents a remote file (implementation)
070: *
071: * @author Bruce Blackshaw
072: * @version $Revision: 1.17 $
073: */
074: public class FTPFile {
075:
076: /**
077: * Revision control id
078: */
079: protected static final String cvsId = "@(#)$Id: FTPFile.java,v 1.17 2007-10-12 05:21:29 bruceb Exp $";
080:
081: /**
082: * Unknown remote server type
083: */
084: public final static int UNKNOWN = -1;
085:
086: /**
087: * Windows type
088: */
089: public final static int WINDOWS = 0;
090:
091: /**
092: * UNIX type
093: */
094: public final static int UNIX = 1;
095:
096: /**
097: * VMS type
098: */
099: public final static int VMS = 2;
100:
101: /**
102: * Date formatter type 1
103: */
104: private final static SimpleDateFormat formatter = new SimpleDateFormat(
105: "dd-MM-yyyy HH:mm");
106:
107: /**
108: * Type of file
109: */
110: private int type;
111:
112: /**
113: * Is this file a symbolic link?
114: */
115: protected boolean isLink = false;
116:
117: /**
118: * Number of links to file
119: */
120: protected int linkCount = 1;
121:
122: /**
123: * Permission bits string
124: */
125: protected String permissions;
126:
127: /**
128: * Is this a directory?
129: */
130: protected boolean isDir = false;
131:
132: /**
133: * Size of file
134: */
135: protected long size = 0L;
136:
137: /**
138: * File/dir name
139: */
140: protected String name;
141:
142: /**
143: * Name of file this is linked to
144: */
145: protected String linkedname;
146:
147: /**
148: * Owner if known
149: */
150: protected String owner;
151:
152: /**
153: * Group if known
154: */
155: protected String group;
156:
157: /**
158: * Last modified
159: */
160: protected Date lastModified;
161:
162: /**
163: * Created time
164: */
165: protected Date created;
166:
167: /**
168: * Raw string
169: */
170: protected String raw;
171:
172: /**
173: * Directory if known
174: */
175: protected String path;
176:
177: /**
178: * Children if a directory
179: */
180: private FTPFile[] children;
181:
182: /**
183: * Constructor
184: *
185: * @param type type of file
186: * @param raw raw string returned from server
187: * @param name name of file
188: * @param size size of file
189: * @param isDir true if a directory
190: * @param lastModified last modified timestamp
191: * @deprecated 'type' no longer used.
192: */
193: public FTPFile(int type, String raw, String name, long size,
194: boolean isDir, Date lastModified) {
195: this (raw);
196: this .type = type;
197: this .name = name;
198: this .size = size;
199: this .isDir = isDir;
200: this .lastModified = lastModified;
201: }
202:
203: /**
204: * Constructor
205: *
206: * @param raw raw string returned from server
207: * @param name name of file
208: * @param size size of file
209: * @param isDir true if a directory
210: * @param lastModified last modified timestamp
211: */
212: public FTPFile(String raw, String name, long size, boolean isDir,
213: Date lastModified) {
214: this (raw);
215: this .type = UNKNOWN;
216: this .name = name;
217: this .size = size;
218: this .isDir = isDir;
219: this .lastModified = lastModified;
220: }
221:
222: /**
223: * Constructor
224: *
225: * @param raw raw string returned from server
226: */
227: public FTPFile(String raw) {
228: this .raw = raw;
229: }
230:
231: /**
232: * Returns an array of FTPFile objects denoting the files and directories in this
233: * directory
234: *
235: * @return FTPFile array
236: */
237: public FTPFile[] listFiles() {
238: return children;
239: }
240:
241: /**
242: *
243: * @param children
244: */
245: void setChildren(FTPFile[] children) {
246: this .children = children;
247: }
248:
249: /**
250: * Get the type of file, i.e UNIX
251: *
252: * @return the integer type of the file
253: * @deprecated No longer necessary.
254: */
255: public int getType() {
256: return type;
257: }
258:
259: /**
260: * @return Returns the group.
261: */
262: public String getGroup() {
263: return group;
264: }
265:
266: /**
267: * @return Returns the isDir.
268: */
269: public boolean isDir() {
270: return isDir;
271: }
272:
273: /**
274: * @return Returns the lastModified date.
275: */
276: public Date lastModified() {
277: return lastModified;
278: }
279:
280: /**
281: * Set the last modified date
282: *
283: * @param date last modified date
284: */
285: public void setLastModified(Date date) {
286: lastModified = date;
287: }
288:
289: /**
290: * Get the created date for the file. This is not
291: * supported by many servers, e.g. Unix does not record
292: * the created date of a file.
293: *
294: * @return Returns the created date.
295: */
296: public Date created() {
297: return created;
298: }
299:
300: /**
301: * Set the created date
302: *
303: * @param date
304: */
305: public void setCreated(Date date) {
306: created = date;
307: }
308:
309: /**
310: * @return Returns the name.
311: */
312: public String getName() {
313: return name;
314: }
315:
316: /**
317: * Set the name of the file
318: *
319: * @param name name of file
320: */
321: public void setName(String name) {
322: this .name = name;
323: }
324:
325: /**
326: * @return Returns the owner.
327: */
328: public String getOwner() {
329: return owner;
330: }
331:
332: /**
333: * @return Returns the raw server string.
334: */
335: public String getRaw() {
336: return raw;
337: }
338:
339: /**
340: * @return Returns the size.
341: */
342: public long size() {
343: return size;
344: }
345:
346: public void setSize(long size) {
347: this .size = size;
348: }
349:
350: /**
351: * @return Returns the permissions.
352: */
353: public String getPermissions() {
354: return permissions;
355: }
356:
357: /**
358: * @return Returns true if file is a symlink
359: */
360: public boolean isLink() {
361: return isLink;
362: }
363:
364: /**
365: * @return Returns the number of links to the file
366: */
367: public int getLinkCount() {
368: return linkCount;
369: }
370:
371: /**
372: * @return Returns the linkedname.
373: */
374: public String getLinkedname() {
375: return linkedname;
376: }
377:
378: /**
379: * @param group The group to set.
380: */
381: public void setGroup(String group) {
382: this .group = group;
383: }
384:
385: /**
386: * @param isDir The isDir to set.
387: */
388: public void setDir(boolean isDir) {
389: this .isDir = isDir;
390: }
391:
392: /**
393: * @param isLink The isLink to set.
394: */
395: public void setLink(boolean isLink) {
396: this .isLink = isLink;
397: }
398:
399: /**
400: * @param linkedname The linked name to set.
401: */
402: public void setLinkedName(String linkedname) {
403: this .linkedname = linkedname;
404: }
405:
406: /**
407: * @param owner The owner to set.
408: */
409: public void setOwner(String owner) {
410: this .owner = owner;
411: }
412:
413: /**
414: * @param permissions The permissions to set.
415: */
416: public void setPermissions(String permissions) {
417: this .permissions = permissions;
418: }
419:
420: /**
421: * @param linkCount new link count
422: */
423: public void setLinkCount(int linkCount) {
424: this .linkCount = linkCount;
425: }
426:
427: /**
428: * @return string representation
429: */
430: public String toString() {
431: StringBuffer buf = new StringBuffer(raw);
432: buf.append("Name=").append(name).append(",").append("Size=")
433: .append(size).append(",").append("Permissions=")
434: .append(permissions).append(",").append("Owner=")
435: .append(owner).append(",").append("Group=").append(
436: group).append(",").append("Is link=").append(
437: isLink).append(",").append("Link count=")
438: .append(linkCount).append(".").append("Is dir=")
439: .append(isDir).append(",").append("Linked name=")
440: .append(linkedname).append(",")
441: .append("Last modified=").append(
442: lastModified != null ? formatter
443: .format(lastModified) : "null");
444: if (created != null)
445: buf.append(",").append("Created=").append(
446: formatter.format(created));
447: return buf.toString();
448: }
449:
450: public String getPath() {
451: return path;
452: }
453:
454: public void setPath(String path) {
455: this.path = path;
456: }
457: }
|