Please note that this documentation is not final and is subject to change.

Java™ Platform
Standard Ed. 7

DRAFT internal-b00

java.net
Class FtpFile

java.lang.Object
  extended by java.net.FtpFile

public class FtpFile
extends Object

An FtpFile is a structure containing all the information that the FTP client can gather from the server by doing a LST (or NLST) command and parsing the output. It will typically contain the name, type, size, last modification lastModified, owner and group of the file, although some of these could be unavailable due to the FTP server limitation.

Since:
1.7
See Also:
java.net.ftp.FtpFileParser

Nested Class Summary
static class FtpFile.Permission
           
static class FtpFile.Type
           
 
Constructor Summary
FtpFile(String name)
          Creates an FtpFile instance with only the name being set.
 
Method Summary
 FtpFile addFact(String fact, String value)
          Adds a 'fact', as defined in RFC 3659, to the list of facts of this file.
 boolean canExexcute(FtpFile.Permission p)
          Returns whether execute access is granted for a specific permission.
 boolean canRead(FtpFile.Permission p)
          Returns whether read access is granted for a specific permission.
 boolean canWrite(FtpFile.Permission p)
          Returns whether write access is granted for a specific permission.
 Date getCreated()
          Returns the creation time of the file, when provided by the server.
 String getFact(String fact)
          Returns the requested 'fact', as defined in RFC 3659, if available.
 String getGroup()
          Returns the group name of the file as returned by the FTP server, if provided.
 Date getLastModified()
          Returns the last modification time of the remote file as it was returned by the FTP server, if provided, null otherwise.
 String getName()
          Returns the name of the remote file.
 long getSize()
          Returns the size of the remote file as it was returned by the FTP server, if provided.
 FtpFile.Type getType()
          Returns the type of the remote file as it was returned by the FTP server, if provided.
 String getUser()
          Returns the user name of the owner of the file as returned by the FTP server, if provided.
 FtpFile setCreated(Date created)
          Sets the creation time for that file.
 FtpFile setGroup(String group)
          Sets the name of the group to which the file belong.
 FtpFile setLastModified(Date lastModified)
          Sets the last modification time of the file.
 FtpFile setPermissions(boolean[][] permissions)
           
 FtpFile setSize(long size)
          Sets the size of that file.
 FtpFile setType(FtpFile.Type type)
          Sets the type of the file.
 FtpFile setUser(String user)
          Sets the user name of the owner of the file.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FtpFile

public FtpFile(String name)
Creates an FtpFile instance with only the name being set.

Parameters:
name - The name of the file
Method Detail

getName

public String getName()
Returns the name of the remote file.

Returns:
a String containing the name of the remote file.

getUser

public String getUser()
Returns the user name of the owner of the file as returned by the FTP server, if provided. This could be a name or a user id (number).

Returns:
a String containing the user name or null if that information is not available.

setUser

public FtpFile setUser(String user)
Sets the user name of the owner of the file. Intended mostly to be used from inside a FtpFileParser implementation.

Parameters:
user - The user name of the owner of the file, or null if that information is not available.
Returns:
this FtpFile

getGroup

public String getGroup()
Returns the group name of the file as returned by the FTP server, if provided. This could be a name or a group id (number).

Returns:
a String containing the group name or null if that information is not available.

setGroup

public FtpFile setGroup(String group)
Sets the name of the group to which the file belong. Intended mostly to be used from inside a FtpFileParser implementation.

Parameters:
group - The name of the group to which the file belong, or null if that information is not available.
Returns:
this FtpFile

getSize

public long getSize()
Returns the size of the remote file as it was returned by the FTP server, if provided.

Returns:
the size of the file or -1 if that information is not available.

setSize

public FtpFile setSize(long size)
Sets the size of that file. Intended mostly to be used from inside an FtpFileParser implementation.

Parameters:
size - The size, in bytes, of that file. or -1 if unknown.
Returns:
this FtpFile

getType

public FtpFile.Type getType()
Returns the type of the remote file as it was returned by the FTP server, if provided. It returns a FtpFile.Type enum and the values can be: - FtpFile.Type.FILE for a normal file - FtpFile.Type.DIR for a directory - FtpFile.Type.LINK for a symbolic link

Returns:
a FtpFile.Type describing the type of the file or null if that information is not available.

setType

public FtpFile setType(FtpFile.Type type)
Sets the type of the file. Intended mostly to be used from inside an FtpFileParser implementation.

Parameters:
type - the type of this file or null if that information is not available.
Returns:
this FtpFile

getLastModified

public Date getLastModified()
Returns the last modification time of the remote file as it was returned by the FTP server, if provided, null otherwise.

Returns:
a Date representing the last time the file was modified on the server, or null if that information is not available.

setLastModified

public FtpFile setLastModified(Date lastModified)
Sets the last modification time of the file. Intended mostly to be used from inside an FtpFileParser implementation.

Parameters:
lastModified - The Date representing the last modification time, or null if that information is not available.
Returns:
this FtpFile

canRead

public boolean canRead(FtpFile.Permission p)
Returns whether read access is granted for a specific permission.

Parameters:
p - the Permission (user, group, others) to check.
Returns:
true if read access is granted.

canWrite

public boolean canWrite(FtpFile.Permission p)
Returns whether write access is granted for a specific permission.

Parameters:
p - the Permission (user, group, others) to check.
Returns:
true if write access is granted.

canExexcute

public boolean canExexcute(FtpFile.Permission p)
Returns whether execute access is granted for a specific permission.

Parameters:
p - the Permission (user, group, others) to check.
Returns:
true if execute access is granted.

setPermissions

public FtpFile setPermissions(boolean[][] permissions)

addFact

public FtpFile addFact(String fact,
                       String value)
Adds a 'fact', as defined in RFC 3659, to the list of facts of this file. Intended mostly to be used from inside a FtpFileParser implementation.

Parameters:
fact - the name of the fact (e.g. "Media-Type"). It is not case-sensitive.
value - the value associated with this fact.
Returns:

getFact

public String getFact(String fact)
Returns the requested 'fact', as defined in RFC 3659, if available.

Parameters:
fact - The name of the fact *e.g. "Media-Type"). It is not case sensitive.
Returns:
The value of the fact or, null if that fact wasn't provided by the server.

getCreated

public Date getCreated()
Returns the creation time of the file, when provided by the server.

Returns:
The Date representing the creation time, or null if the server didn't provide that information.

setCreated

public FtpFile setCreated(Date created)
Sets the creation time for that file. Intended mostly to be used from inside a FtpFileParser implementation.

Parameters:
created - the Date representing the creation time for that file, or null if that information is not available.
Returns:
this FtpFile

toString

public String toString()
Returns a string representation of the object. The toString method for class FtpFile returns a string consisting of the name of the file, followed by its type between brackets, followed by the user and group between parenthesis, then size between '{', and, finally, the lastModified of last modification if it's available.

Overrides:
toString in class Object
Returns:
a string representation of the object.

Java™ Platform
Standard Ed. 7

DRAFT internal-b00

Submit a bug or feature

Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.