View Javadoc
1   package org.apache.commons.jcs.engine;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.jcs.engine.behavior.ICacheElementSerialized;
23  import org.apache.commons.jcs.engine.behavior.IElementAttributes;
24  
25  import java.util.Arrays;
26  
27  /** Either serialized value or the value should be null; */
28  public class CacheElementSerialized<K, V>
29      extends CacheElement<K, V>
30      implements ICacheElementSerialized<K, V>
31  {
32      /** Don't change. */
33      private static final long serialVersionUID = -7265084818647601874L;
34  
35      /** The serialized value. */
36      private final byte[] serializedValue;
37  
38      /**
39       * Constructs a usable wrapper.
40       * <p>
41       * @param cacheNameArg
42       * @param keyArg
43       * @param serializedValueArg
44       * @param elementAttributesArg
45       */
46      public CacheElementSerialized( String cacheNameArg, K keyArg, byte[] serializedValueArg,
47                                     IElementAttributes elementAttributesArg )
48      {
49          super(cacheNameArg, keyArg, null, elementAttributesArg);
50          this.serializedValue = serializedValueArg;
51      }
52  
53      /** @return byte[] */
54      @Override
55      public byte[] getSerializedValue()
56      {
57          return this.serializedValue;
58      }
59  
60      /**
61       * For debugging only.
62       * <p>
63       * @return debugging string.
64       */
65      @Override
66      public String toString()
67      {
68          StringBuilder buf = new StringBuilder();
69          buf.append( "\n CacheElementSerialized: " );
70          buf.append( "\n CacheName = [" + getCacheName() + "]" );
71          buf.append( "\n Key = [" + getKey() + "]" );
72          buf.append( "\n SerializedValue = " + Arrays.toString(getSerializedValue()) );
73          buf.append( "\n ElementAttributes = " + getElementAttributes() );
74          return buf.toString();
75      }
76  
77  }