29
29
import java .security .AccessController ;
30
30
import java .security .PrivilegedAction ;
31
31
import java .text .DateFormat ;
32
- import java .text .ParseException ;
33
- import java .text .SimpleDateFormat ;
32
+ import java .time .ZoneOffset ;
33
+ import java .time .ZonedDateTime ;
34
+ import java .time .format .DateTimeFormatter ;
35
+ import java .time .format .DateTimeParseException ;
34
36
import java .util .ArrayList ;
35
37
import java .util .Base64 ;
36
38
import java .util .Calendar ;
37
39
import java .util .Date ;
38
40
import java .util .Iterator ;
39
41
import java .util .List ;
40
- import java .util .TimeZone ;
41
42
import java .util .Vector ;
42
43
import java .util .regex .Matcher ;
43
44
import java .util .regex .Pattern ;
@@ -1739,19 +1740,8 @@ public long getSize(String path) throws sun.net.ftp.FtpProtocolException, IOExce
1739
1740
return -1 ;
1740
1741
}
1741
1742
1742
- private static final SimpleDateFormat [] dateFormats ;
1743
-
1744
- static {
1745
- String [] formats = {
1746
- "yyyyMMddHHmmss.SSS" ,
1747
- "yyyyMMddHHmmss"
1748
- };
1749
- dateFormats = new SimpleDateFormat [formats .length ];
1750
- for (int i = 0 ; i < formats .length ; ++i ) {
1751
- dateFormats [i ] = new SimpleDateFormat (formats [i ]);
1752
- dateFormats [i ].setTimeZone (TimeZone .getTimeZone ("GMT" ));
1753
- }
1754
- }
1743
+ private static final DateTimeFormatter RFC3659_DATETIME_FORMAT = DateTimeFormatter .ofPattern ("yyyyMMddHHmmss[.SSS]" )
1744
+ .withZone (ZoneOffset .UTC );
1755
1745
1756
1746
/**
1757
1747
* Issues the MDTM [path] command to the server to get the modification
@@ -1768,24 +1758,20 @@ public long getSize(String path) throws sun.net.ftp.FtpProtocolException, IOExce
1768
1758
public Date getLastModified (String path ) throws sun .net .ftp .FtpProtocolException , IOException {
1769
1759
issueCommandCheck ("MDTM " + path );
1770
1760
if (lastReplyCode == FtpReplyCode .FILE_STATUS ) {
1771
- String s = getResponseString (). substring ( 4 ) ;
1772
- return parseRfc3659TimeValue (s );
1761
+ String s = getResponseString ();
1762
+ return parseRfc3659TimeValue (s . substring ( 4 , s . length () - 1 ) );
1773
1763
}
1774
1764
return null ;
1775
1765
}
1776
1766
1777
1767
private static Date parseRfc3659TimeValue (String s ) {
1778
- Date d = null ;
1779
- for (SimpleDateFormat dateFormat : dateFormats ) {
1780
- try {
1781
- d = dateFormat .parse (s );
1782
- } catch (ParseException ex ) {
1783
- }
1784
- if (d != null ) {
1785
- return d ;
1786
- }
1768
+ Date result = null ;
1769
+ try {
1770
+ var d = ZonedDateTime .parse (s , RFC3659_DATETIME_FORMAT );
1771
+ result = Date .from (d .toInstant ());
1772
+ } catch (DateTimeParseException ex ) {
1787
1773
}
1788
- return d ;
1774
+ return result ;
1789
1775
}
1790
1776
1791
1777
/**
0 commit comments