Java tutorial
/** * Copyright 2012 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.comcast.cereal.convert; import org.apache.commons.codec.binary.Base64; import com.comcast.cereal.CerealException; import com.comcast.cereal.Cerealizer; import com.comcast.cereal.ObjectCache; /** * This is a common and default cerealizer for converting byte arrays (<code>byte[]</code>) to and * from base64-encoded strings. * * @author <a href="mailto:cmalmgren@gmail.com">Clark Malmgren</a> */ public class ByteArrayCerealizer implements Cerealizer<byte[], String> { /* * (non-Javadoc) * @see com.comcast.cereal.Cerealizer#deCerealize(java.lang.Object) */ public byte[] deCerealize(String cereal, ObjectCache objectCache) throws CerealException { return Base64.decodeBase64(cereal); } /* * (non-Javadoc) * @see com.comcast.cereal.Cerealizer#cerealize(java.lang.Object) */ public String cerealize(byte[] object, ObjectCache objectCache) throws CerealException { return new String(Base64.encodeBase64(object, false)); } }