defaultindexkeycreator.java

来自「短信开发用于文件交换处理转发的类模块」· Java 代码 · 共 35 行

JAVA
35
字号
package com.pub.berkeleydb;

import com.sleepycat.je.DatabaseEntry;
import org.apache.mina.common.*;
//import java.nio.ByteBuffer;

/**
 *
 */
public abstract class DefaultIndexKeyCreator implements IIndexCreator {
  //index key ByteBuffer
  private static ThreadLocal tlIKB = new ThreadLocal(){
    protected Object initialValue() {
      return ByteBuffer.allocate(256,false).setAutoExpand( true );
    }
  };
  public static ByteBuffer tmpIKB(){return (ByteBuffer)tlIKB.get();}

  public boolean toIndexKey(Object r, DatabaseEntry idxKey) {

      ByteBuffer out = tmpIKB();
      out.clear();

      toIndexKey(out,r);
      out.flip();
      idxKey.setData(out.array(), out.position(), out.remaining());

      out = null;

      return true;
  }

  protected abstract void toIndexKey(ByteBuffer out, Object o);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?