FileDocCategorySizeDatePackage
x_time.javaAPI DocExample2123Sun Dec 12 10:55:56 GMT 2004com.macfaq.net.www.content.application

x_time

public class x_time extends ContentHandler

Fields Summary
Constructors Summary
Methods Summary
public java.lang.ObjectgetContent(java.net.URLConnection uc)


    Class[] classes = new Class[1];
    classes[0] = Date.class;
    return this.getContent(uc, classes); 

  
public java.lang.ObjectgetContent(java.net.URLConnection uc, java.lang.Class[] classes)

    
    InputStream in = uc.getInputStream();
    for (int i = 0; i < classes.length; i++) {
      if (classes[i] == InputStream.class) {
        return in;  
      } 
      else if (classes[i] == Long.class) {
        long secondsSince1900 = readSecondsSince1900(in);
        return new Long(secondsSince1900);
      }
      else if (classes[i] == Date.class) {
        long secondsSince1900 = readSecondsSince1900(in);
        Date time = shiftEpochs(secondsSince1900);
        return time;
      }
      else if (classes[i] == Calendar.class) {
        long secondsSince1900 = readSecondsSince1900(in);
        Date time = shiftEpochs(secondsSince1900);
        Calendar c = Calendar.getInstance();
        c.setTime(time);
        return c;
      }
      else if (classes[i] == String.class) {
        long secondsSince1900 = readSecondsSince1900(in);
        Date time = shiftEpochs(secondsSince1900);
        return time.toString();
      }      
    }
    
    return null; // no requested type available
    
  
private longreadSecondsSince1900(java.io.InputStream in)

    
    long secondsSince1900 = 0;
    for (int j = 0; j < 4; j++) {
      secondsSince1900 = (secondsSince1900 << 8) | in.read();
    }
    return secondsSince1900;
    
  
private java.util.DateshiftEpochs(long secondsSince1900)

  
    // The time protocol sets the epoch at 1900, the Java Date class
    //  at 1970. This number converts between them.
    long differenceBetweenEpochs = 2208988800L;
    
    long secondsSince1970 = secondsSince1900 - differenceBetweenEpochs;       
    long msSince1970 = secondsSince1970 * 1000;
    Date time = new Date(msSince1970);
    return time;