You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by hc...@apache.org on 2005/01/27 11:59:20 UTC

cvs commit: jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/file CacheFileContentType.java

hchar       2005/01/27 02:59:20

  Modified:    sandbox/yajcache/src/org/apache/jcs/yajcache/file
                        CacheFileContentType.java
  Log:
  add serialize/deserialize
  
  Revision  Changes    Path
  1.2       +28 -5     jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/file/CacheFileContentType.java
  
  Index: CacheFileContentType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/file/CacheFileContentType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CacheFileContentType.java	24 Jan 2005 10:29:45 -0000	1.1
  +++ CacheFileContentType.java	27 Jan 2005 10:59:20 -0000	1.2
  @@ -17,7 +17,9 @@
   
   package org.apache.jcs.yajcache.file;
   
  -import org.apache.jcs.yajcache.annotate.*;
  +import java.io.Serializable;
  +import org.apache.commons.lang.SerializationUtils;
  +import org.apache.jcs.yajcache.lang.annotation.*;
   
   /**
    * Cache File Content Type.  A cache file represents the file persistence
  @@ -27,7 +29,8 @@
    *
    * @author Hanson Char
    */
  -@CopyRightApache
  +// @CopyRightApache
  +// http://www.netbeans.org/issues/show_bug.cgi?id=53704
   public enum CacheFileContentType {
       JAVA_SERIALIZATION,
       XML_ENCODER;
  @@ -40,15 +43,15 @@
               case XML_ENCODER:
                   return 1;
               default:
  -                throw new IllegalStateException("Should never happen");
  +                throw new AssertionError(this);
           }
       }
       /** 
        * Returns the corresponding CacheFileContentType enum instance 
        * from the given byte value. 
        */
  -    @NonNullable 
  -    public static CacheFileContentType fromByte(byte b) {
  +    
  +    public static @NonNullable CacheFileContentType fromByte(byte b) {
           switch(b) {
               case 0:
                   return JAVA_SERIALIZATION;
  @@ -58,4 +61,24 @@
                   throw new IllegalArgumentException("Unsupported b="+b);
           }
       }
  +    public byte[] serialize(Object obj) {
  +        switch(this) {
  +            case JAVA_SERIALIZATION:
  +                return SerializationUtils.serialize((Serializable)obj);
  +            case XML_ENCODER:
  +                return org.apache.jcs.yajcache.util.BeanUtils.inst.toXmlByteArray(obj);
  +            default:
  +                throw new AssertionError(this);
  +        }
  +    }
  +    public Object deserialize(byte[] ba) {
  +        switch(this) {
  +            case JAVA_SERIALIZATION:
  +                return SerializationUtils.deserialize(ba);
  +            case XML_ENCODER:
  +                return org.apache.jcs.yajcache.util.BeanUtils.inst.fromXmlByteArray(ba);
  +            default:
  +                throw new AssertionError(this);
  +        }
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org