Class FTPTimestampParserImpl
- java.lang.Object
-
- org.apache.commons.net.ftp.parser.FTPTimestampParserImpl
-
- All Implemented Interfaces:
Configurable
,FTPTimestampParser
public class FTPTimestampParserImpl extends java.lang.Object implements FTPTimestampParser, Configurable
Default implementation of theFTPTimestampParser
interface also implements theConfigurable
interface to allow the parsing to be configured from the outside.- Since:
- 1.4
- See Also:
ConfigurableFTPFileEntryParserImpl
-
-
Field Summary
-
Fields inherited from interface org.apache.commons.net.ftp.parser.FTPTimestampParser
DEFAULT_RECENT_SDF, DEFAULT_SDF
-
-
Constructor Summary
Constructors Constructor Description FTPTimestampParserImpl()
The only constructor for this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(FTPClientConfig config)
Implementation of theConfigurable
interface.java.text.SimpleDateFormat
getDefaultDateFormat()
java.lang.String
getDefaultDateFormatString()
java.text.SimpleDateFormat
getRecentDateFormat()
java.lang.String
getRecentDateFormatString()
java.util.TimeZone
getServerTimeZone()
java.lang.String[]
getShortMonths()
java.util.Calendar
parseTimestamp(java.lang.String timestampStr)
Implements the onemethod
in theFTPTimestampParser
interface according to this algorithm: If the recentDateFormat member has been defined, try to parse the supplied string with that.java.util.Calendar
parseTimestamp(java.lang.String timestampStr, java.util.Calendar serverTime)
If the recentDateFormat member has been defined, try to parse the supplied string with that.
-
-
-
Method Detail
-
parseTimestamp
public java.util.Calendar parseTimestamp(java.lang.String timestampStr) throws java.text.ParseException
Implements the onemethod
in theFTPTimestampParser
interface according to this algorithm: If the recentDateFormat member has been defined, try to parse the supplied string with that. If that parse fails, or if the recentDateFormat member has not been defined, attempt to parse with the defaultDateFormat member. If that fails, throw a ParseException. This method assumes that the server time is the same as the local time.- Specified by:
parseTimestamp
in interfaceFTPTimestampParser
- Parameters:
timestampStr
- The timestamp to be parsed- Returns:
- a Calendar with the parsed timestamp
- Throws:
java.text.ParseException
- if none of the parser mechanisms belonging to the implementor can parse the input.- See Also:
parseTimestamp(String, Calendar)
-
parseTimestamp
public java.util.Calendar parseTimestamp(java.lang.String timestampStr, java.util.Calendar serverTime) throws java.text.ParseException
If the recentDateFormat member has been defined, try to parse the supplied string with that. If that parse fails, or if the recentDateFormat member has not been defined, attempt to parse with the defaultDateFormat member. If that fails, throw a ParseException. This method allows aCalendar
instance to be passed in which represents the current (system) time.- Parameters:
timestampStr
- The timestamp to be parsedserverTime
- The current time for the server- Returns:
- the calendar
- Throws:
java.text.ParseException
- if timestamp cannot be parsed- Since:
- 1.5
- See Also:
FTPTimestampParser.parseTimestamp(String)
-
getDefaultDateFormat
public java.text.SimpleDateFormat getDefaultDateFormat()
- Returns:
- Returns the defaultDateFormat.
-
getDefaultDateFormatString
public java.lang.String getDefaultDateFormatString()
- Returns:
- Returns the defaultDateFormat pattern string.
-
getRecentDateFormat
public java.text.SimpleDateFormat getRecentDateFormat()
- Returns:
- Returns the recentDateFormat.
-
getRecentDateFormatString
public java.lang.String getRecentDateFormatString()
- Returns:
- Returns the recentDateFormat.
-
getShortMonths
public java.lang.String[] getShortMonths()
- Returns:
- returns an array of 12 strings representing the short month names used by this parse.
-
getServerTimeZone
public java.util.TimeZone getServerTimeZone()
- Returns:
- Returns the serverTimeZone used by this parser.
-
configure
public void configure(FTPClientConfig config)
Implementation of theConfigurable
interface. Configures thisFTPTimestampParser
according to the following logic:Set up the
defaultDateFormat
and optionally therecentDateFormat
to values supplied in the config based on month names configured as follows:- If a
shortMonthString
has been supplied in theconfig
, use that to parse parse timestamps. - Otherwise, if a
serverLanguageCode
has been supplied in theconfig
, use the month names represented by thatlanguage
to parse timestamps. - otherwise use default English month names
Finally if a
serverTimeZoneId
has been supplied via the config, set that into all date formats that have been configured.- Specified by:
configure
in interfaceConfigurable
- Parameters:
config
- the object containing the configuration data
- If a
-
-