/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * 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 org.codehaus.activemq.store.bdbn;

import com.sleepycat.bdb.bind.DataBinding;
import com.sleepycat.bdb.bind.DataBuffer;
import com.sleepycat.bdb.bind.DataFormat;

import java.io.IOException;

/**
 * A DataBinding for a simple String serialiation
 *
 * @version $Revision: 1.1 $
 */
public class StringDataBinding implements DataBinding {
    private static StringDataFormat format = new StringDataFormat();

    public Object dataToObject(DataBuffer buffer) throws IOException {
        return new String(buffer.getDataBytes(), buffer.getDataOffset(), buffer.getDataLength());
    }

    public void objectToData(Object object, DataBuffer buffer) throws IOException {
        String text = (String) object;
        byte[] data = text.getBytes();
        buffer.setData(data, 0, data.length);
    }

    public DataFormat getDataFormat() {
        return format;
    }
}
