incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/util DateUtils.java EncryptUtils.java
Date Fri, 09 Sep 2005 11:24:00 GMT
rana_b      2005/09/09 04:24:00

  Modified:    src/java/org/apache/ftpserver/util DateUtils.java
                        EncryptUtils.java
  Log:
  made all the static methods final
  
  Revision  Changes    Path
  1.5       +54 -70    incubator-ftpserver/src/java/org/apache/ftpserver/util/DateUtils.java
  
  Index: DateUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/util/DateUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DateUtils.java	7 Sep 2005 05:01:17 -0000	1.4
  +++ DateUtils.java	9 Sep 2005 11:23:59 -0000	1.5
  @@ -16,11 +16,8 @@
    */
   package org.apache.ftpserver.util;
   
  -import java.text.DateFormat;
   import java.util.Calendar;
  -import java.util.Date;
   import java.util.GregorianCalendar;
  -import java.util.TimeZone;
   
   /**
    * Standard date related utility methods.
  @@ -48,7 +45,7 @@
       /**
        * Get unix style date string.
        */
  -    public static String getUnixDate(long millis) {
  +    public final static String getUnixDate(long millis) {
           if (millis < 0) {
               return "------------";
           }
  @@ -101,7 +98,7 @@
       /**
        * Get ISO 8601 timestamp.
        */
  -    public static String getISO8601Date(long millis) {
  +    public final static String getISO8601Date(long millis) {
           StringBuffer sb = new StringBuffer(19);
           Calendar cal = new GregorianCalendar();
           cal.setTimeInMillis(millis);
  @@ -153,74 +150,61 @@
       } 
       
       /**
  -     * Get the timezone specific string.
  +     * Get FTP date.
        */
  -    public static String getString(Date dt, DateFormat df, TimeZone to) {
  -        df.setTimeZone(to);
  -        return df.format(dt);
  -    }
  -
  -    /**
  -     * Get the timezone specific calendar.
  -     */
  -    public static Calendar getCalendar(Date dt, TimeZone to) {
  -        Calendar cal = Calendar.getInstance(to);
  -        cal.setTime(dt);
  -        return cal;
  -    }
  -
  -    /**
  -     * Get date object.
  -     */
  -    public static Date getDate(String str, DateFormat df, TimeZone from) 
  -    throws java.text.ParseException {
  -        df.setTimeZone(from);
  -        return df.parse(str);
  -    }
  -    
  -    /**
  -     * Get date difference => d1 - d2. 
  -     */
  -    public static String getDifference(Date d1, Date d2) {
  -        Calendar calendar = new GregorianCalendar();
  -        calendar.setTime(d2);
  -        int year2 = calendar.get(Calendar.YEAR);
  -        int day2 = calendar.get(Calendar.DAY_OF_YEAR);
  -        int hour2 = calendar.get(Calendar.HOUR_OF_DAY);
  -        int min2  = calendar.get(Calendar.MINUTE);
  -        
  -        calendar.setTime(d1);
  -        int year1 = calendar.get(Calendar.YEAR);
  -        int day1 = calendar.get(Calendar.DAY_OF_YEAR);
  -        int hour1 = calendar.get(Calendar.HOUR_OF_DAY);
  -        int min1  = calendar.get(Calendar.MINUTE);
  -        
  -        int leftDays = (day1-day2)+(year1-year2)*365;
  -        int leftHours = hour1-hour2;
  -        int leftMins  = min1 - min2;
  -        
  -        if(leftMins < 0) {
  -            leftMins += 60;
  -            --leftHours;
  -        }
  -        if(leftHours < 0) {
  -            leftHours += 24;
  -            --leftDays;
  -        }
  -        
  -        String interval = "";
  -        if(leftDays > 0) {
  -            interval = leftDays + " Days";
  +    public final static String getFtpDate(long millis) {
  +        StringBuffer sb = new StringBuffer(20);
  +        Calendar cal = new GregorianCalendar();
  +        cal.setTimeInMillis(millis);
  +        
  +        // year
  +        sb.append(cal.get(Calendar.YEAR));
  +        
  +        // month
  +        int month = cal.get(Calendar.MONTH) + 1;
  +        if(month < 10) {
  +            sb.append('0');
           }
  -        else if((leftHours > 0) && (leftDays == 0)) {
  -            interval = leftHours + " Hours";
  +        sb.append(month);
  +        
  +        // date
  +        int date = cal.get(Calendar.DATE);
  +        if(date < 10) {
  +            sb.append('0');
           }
  -        else if((leftMins > 0) && (leftHours == 0) && (leftDays == 0))
{
  -            interval = leftMins + " Minutes";
  +        sb.append(date);
  +        
  +        // hour
  +        int hour = cal.get(Calendar.HOUR_OF_DAY);
  +        if(hour < 10) {
  +            sb.append('0');
           }
  -        else {
  -            interval = "";
  +        sb.append(hour);
  +        
  +        // minute
  +        int min = cal.get(Calendar.MINUTE);
  +        if(min < 10) {
  +            sb.append('0');
           }
  -        return interval;
  +        sb.append(min);
  +        
  +        // second
  +        int sec = cal.get(Calendar.SECOND);
  +        if(sec < 10) {
  +            sb.append('0');
  +        }
  +        sb.append(sec);
  +        
  +        // millisecond
  +        sb.append('.');
  +        int milli = cal.get(Calendar.MILLISECOND);
  +        if(milli < 100) {
  +            sb.append('0');
  +        }
  +        if(milli < 10) {
  +            sb.append('0');
  +        }
  +        sb.append(milli);
  +        return sb.toString();
       }
   }
  
  
  
  1.5       +5 -5      incubator-ftpserver/src/java/org/apache/ftpserver/util/EncryptUtils.java
  
  Index: EncryptUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/util/EncryptUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EncryptUtils.java	7 Sep 2005 05:01:17 -0000	1.4
  +++ EncryptUtils.java	9 Sep 2005 11:24:00 -0000	1.5
  @@ -31,7 +31,7 @@
       /**
        * Encrypt byte array.
        */
  -    public static byte[] encrypt(byte[] source, String algorithm) throws NoSuchAlgorithmException
{
  +    public final static byte[] encrypt(byte[] source, String algorithm) throws NoSuchAlgorithmException
{
           MessageDigest md = MessageDigest.getInstance(algorithm);
           md.reset();
           md.update(source);
  @@ -41,7 +41,7 @@
       /**
        * Encrypt string
        */
  -    public static String encrypt(String source, String algorithm) throws NoSuchAlgorithmException
{
  +    public final static String encrypt(String source, String algorithm) throws NoSuchAlgorithmException
{
           byte[] resByteArray = encrypt(source.getBytes(), algorithm);
           return StringUtils.toHexString(resByteArray);
       }
  @@ -49,7 +49,7 @@
       /**
        * Encrypt string using MD5 algorithm
        */
  -    public static String encryptMD5(String source) {
  +    public final static String encryptMD5(String source) {
           if (source == null) {
               source = "";
           }
  @@ -67,7 +67,7 @@
       /**
        * Encrypt string using SHA algorithm
        */
  -    public static String encryptSHA(String source) {
  +    public final static String encryptSHA(String source) {
           if (source == null) {
               source = "";
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message