Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/rsi/ipstat/Formater.java


1   /*
2   
3   This software is open-source and is distributed under the terms of the GNU
4   General Public License.
5   
6   Copyright (c) 2000-2002 Sergey I. Rotar <rsi@isp.od.ua>
7    
8   */
9   
10  package com.rsi.ipstat;
11  
12  import java.util.*;
13  
14  public class Formater {
15  
16    public static String Encode(String str)
17    {
18      try {
19        return new String(str.getBytes(), "KOI8-R");
20      }
21      catch (java.io.UnsupportedEncodingException e) {
22        return str;
23      }
24    }
25    
26    public static String Decode(String str)
27        {
28      try {
29        return new String(str.getBytes("KOI8-R"));
30      }
31      catch (java.io.UnsupportedEncodingException e) {
32        return str;
33      }
34       }
35  
36    public static String Date(Calendar cal) 
37    {
38      int c;
39      c = cal.get(Calendar.DAY_OF_MONTH);
40      String date = (c > 9) ? new Integer(c).toString() : "0" + (new Integer(c)).toString();
41      c = cal.get(Calendar.MONTH)+1;
42      date += "." + ((c > 9) ? new Integer(c).toString() : "0" + (new Integer(c)).toString());
43      date += "." + (new Integer(cal.get(Calendar.YEAR)).toString());
44      return date;
45    }
46  
47    public static String Date_YYYYMMDD(Calendar cal) 
48    {
49      int c;
50      String date = new Integer(cal.get(Calendar.YEAR)).toString();
51      c = cal.get(Calendar.MONTH)+1;
52      date += "." + ((c > 9) ? new Integer(c).toString() : "0" + (new Integer(c)).toString());
53      c = cal.get(Calendar.DAY_OF_MONTH);
54      date += "." + ((c > 9) ? new Integer(c).toString() : "0" + (new Integer(c)).toString());
55      return date;
56    }
57  
58    public static String Date(int year, int month) 
59    {
60      String date = (month > 9) ? new Integer(month).toString() : "0" + (new Integer(month)).toString(); 
61      date += "." + (new Integer(year).toString());
62      return date;
63    }
64  
65    public static String NiceByteCount(long bytecount) 
66    {
67      int n = 0;
68      String fbyte_str;    
69      String byte_str = new String();    
70  
71      fbyte_str = new Long(bytecount).toString();
72    
73      for (int j = fbyte_str.length()-1; j > -1; j--)
74        byte_str += fbyte_str.charAt(j);
75    
76      fbyte_str = new String();
77    
78      for (int j = 0; j < byte_str.length(); j++) {
79        if (n == 3) {
80          fbyte_str = byte_str.charAt(j) + "." + fbyte_str;
81          n = 0;
82        }
83        else fbyte_str = byte_str.charAt(j) + fbyte_str;
84        n++;
85      }
86   
87      return fbyte_str;
88    }
89  
90    public static MaxSum getMaxSum(UserStat us) 
91    {
92      MaxSum ms = new MaxSum(); 
93      for (int i = 0; i < us.realLength; i++) {
94        ms.sumin += us.bytein[i];
95        ms.maxin = Math.max(ms.maxin, us.bytein[i]);
96        ms.sumout += us.byteout[i];
97        ms.maxout = Math.max(ms.maxout, us.byteout[i]);
98      }
99   
100     return ms;
101   }
102  
103 }