001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.remotefile;
019:
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.List;
023:
024: /**
025: * Creates a single RemoteFile object that is not linked to any other objects.
026: *
027: * @author mog
028: * @version $Id: StaticRemoteFile.java 1513 2006-10-13 22:41:08Z tdsoul $
029: */
030: public class StaticRemoteFile extends AbstractRemoteFile {
031: private long _checkSum;
032: private String _groupname;
033: private long _lastModified;
034: private long _length;
035: private String _link = null;
036: private String _name;
037: private List _rslaves;
038: private String _username;
039: private long _xfertime;
040:
041: public StaticRemoteFile(List rslaves, String name, long size) {
042: this (rslaves, name, null, null, size, System
043: .currentTimeMillis());
044: }
045:
046: /**
047: * @param _rslave
048: * @param string
049: * @param string2
050: * @param string3
051: * @param i
052: */
053: public StaticRemoteFile(List rslaves, String name, String user,
054: String group, int size) {
055: this (rslaves, name, user, group, size, System
056: .currentTimeMillis());
057: }
058:
059: /**
060: * @param rslaves null indicates that this is a directory.
061: */
062: public StaticRemoteFile(List rslaves, String name, String owner,
063: String group, long size, long lastModified) {
064: _rslaves = rslaves;
065: _name = name;
066:
067: // if(name.indexOf("/") != -1) {
068: // throw new IllegalArgumentException("constructor only does files and not paths");
069: // }
070: _username = owner;
071: _groupname = group;
072: _length = size;
073: _lastModified = lastModified;
074: }
075:
076: public StaticRemoteFile(List rslaves, String name, String owner,
077: String group, long size, long lastModified, long checkSum) {
078: this (rslaves, name, owner, group, size, lastModified);
079: _checkSum = checkSum;
080: }
081:
082: public StaticRemoteFile(String name) {
083: _length = 0;
084: _lastModified = System.currentTimeMillis();
085: _name = name;
086: if (_name.indexOf("\\") != -1) {
087: throw new RuntimeException(
088: "Cannot create a filename with \\ in the path");
089: }
090: }
091:
092: public StaticRemoteFile(String name, List rslaves) {
093: this (name);
094: _rslaves = rslaves;
095: }
096:
097: public StaticRemoteFile(String name, List rslaves, String link) {
098: this (name, rslaves);
099: _link = link;
100: }
101:
102: public long getCheckSumCached() {
103: return _checkSum;
104: }
105:
106: /**
107: * StaticRemoteFile cannot be linked
108: * @return java.util.Collections.EMPTY_LIST
109: */
110: public List getFiles() {
111: return Collections.EMPTY_LIST;
112: }
113:
114: public String getGroupname() {
115: return _groupname;
116: }
117:
118: public String getLinkPath() {
119: return _link;
120: }
121:
122: public String getName() {
123: return _name;
124: }
125:
126: public String getParent() {
127: throw new UnsupportedOperationException(
128: "getParent() does not exist in StaticRemoteFile");
129: }
130:
131: public String getPath() {
132: throw new UnsupportedOperationException();
133: }
134:
135: public Collection getSlaves() {
136: return _rslaves;
137: }
138:
139: public String getUsername() {
140: return _username;
141: }
142:
143: public long getXfertime() {
144: return _xfertime;
145: }
146:
147: public boolean isDirectory() {
148: return _rslaves == null;
149: }
150:
151: public boolean isFile() {
152: return _rslaves != null;
153: }
154:
155: public boolean isLink() {
156: return _link != null;
157: }
158:
159: public long lastModified() {
160: return _lastModified;
161: }
162:
163: public long length() {
164: return _length;
165: }
166:
167: /**
168: * Sets the checkSum.
169: * @param checkSum The checkSum to set
170: */
171: public void setCheckSum(long checkSum) {
172: _checkSum = checkSum;
173: }
174:
175: public void setGroupname(String groupname) {
176: _groupname = groupname;
177: }
178:
179: public void setLastModified(long lastmodified) {
180: _lastModified = lastmodified;
181: }
182:
183: public void setLength(long length) {
184: _length = length;
185: }
186:
187: public void setLink(String link) {
188: _link = link;
189: }
190:
191: public void setRSlaves(List rslaves) {
192: _rslaves = rslaves;
193: }
194:
195: public void setUsername(String username) {
196: _username = username;
197: }
198:
199: public void setXfertime(long xfertime) {
200: _xfertime = xfertime;
201: }
202:
203: public String toString() {
204: StringBuffer ret = new StringBuffer();
205: ret.append(getClass().getName() + "[");
206:
207: if (isDirectory()) {
208: ret.append("[isDirectory(): true]");
209: }
210:
211: if (isFile()) {
212: ret.append("[isFile(): true]");
213: }
214:
215: ret.append("[length(): " + length() + "]");
216: ret.append(getName());
217: ret.append("]");
218: ret.append("[rslaves:" + _rslaves + "]");
219:
220: return ret.toString();
221: }
222: }
|