001package org.apache.commons.jcs.engine; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.jcs.engine.behavior.ICacheElementSerialized; 023import org.apache.commons.jcs.engine.behavior.IElementAttributes; 024 025import java.util.Arrays; 026 027/** Either serialized value or the value should be null; */ 028public class CacheElementSerialized<K, V> 029 extends CacheElement<K, V> 030 implements ICacheElementSerialized<K, V> 031{ 032 /** Don't change. */ 033 private static final long serialVersionUID = -7265084818647601874L; 034 035 /** The serialized value. */ 036 private final byte[] serializedValue; 037 038 /** 039 * Constructs a usable wrapper. 040 * <p> 041 * @param cacheNameArg 042 * @param keyArg 043 * @param serializedValueArg 044 * @param elementAttributesArg 045 */ 046 public CacheElementSerialized( String cacheNameArg, K keyArg, byte[] serializedValueArg, 047 IElementAttributes elementAttributesArg ) 048 { 049 super(cacheNameArg, keyArg, null, elementAttributesArg); 050 this.serializedValue = serializedValueArg; 051 } 052 053 /** @return byte[] */ 054 @Override 055 public byte[] getSerializedValue() 056 { 057 return this.serializedValue; 058 } 059 060 /** 061 * For debugging only. 062 * <p> 063 * @return debugging string. 064 */ 065 @Override 066 public String toString() 067 { 068 StringBuilder buf = new StringBuilder(); 069 buf.append( "\n CacheElementSerialized: " ); 070 buf.append( "\n CacheName = [" + getCacheName() + "]" ); 071 buf.append( "\n Key = [" + getKey() + "]" ); 072 buf.append( "\n SerializedValue = " + Arrays.toString(getSerializedValue()) ); 073 buf.append( "\n ElementAttributes = " + getElementAttributes() ); 074 return buf.toString(); 075 } 076 077}