<commit_before>package com.zakgof.db.sqlkvs;

import java.io.ByteArrayInputStream;
import java.util.Map.Entry;

import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.LockMode;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.Transaction;
import com.zakgof.db.kvs.ITransactionalKvs;
import com.zakgof.serialize.ZeSerializer;
import com.zakgof.tools.Buffer;

public class BerkeleyKvs implements ITransactionalKvs {

  private Database berkeley;
  private Transaction txn;

  public BerkeleyKvs(Database berkeley, Transaction txn) {
    this.berkeley = berkeley;
    this.txn = txn;
  }

  @Override
  public <T> T get(Class<T> clazz, Object key) {
    ZeSerializer serializer = new ZeSerializer();
    byte[] keyBytes = serializer.serialize(key);
    DatabaseEntry keyEntry = new DatabaseEntry(keyBytes);
    DatabaseEntry valueEntry = new DatabaseEntry();
    try {
      OperationStatus status = berkeley.get(txn, keyEntry, valueEntry, LockMode.DEFAULT);
      if (status == OperationStatus.NOTFOUND)
        return null;
      byte[] data = valueEntry.getData();
      reads++;
      readBytes += data.length;
      T value = serializer.deserialize(new ByteArrayInputStream(data), clazz);
      return value;
    } catch (DatabaseException e) {
      throw new RuntimeException(e);
    }
  }

  @Override
  public <T> void put(Object key, T value) {
    ZeSerializer serializer = new ZeSerializer();
    byte[] keyBytes = serializer.serialize(key);
    DatabaseEntry keyEntry = new DatabaseEntry(keyBytes);
    byte[] valueBytes = serializer.serialize(key);
    DatabaseEntry valueEntry = new DatabaseEntry(valueBytes);    
    try {
      berkeley.put(txn, keyEntry, valueEntry);
      writes++;<commit_msg>fixed fatal type in saving bytes<commit_after>package com.zakgof.db.sqlkvs;

import java.io.ByteArrayInputStream;
import java.util.Map.Entry;

import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.LockMode;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.Transaction;
import com.zakgof.db.kvs.ITransactionalKvs;
import com.zakgof.serialize.ZeSerializer;
import com.zakgof.tools.Buffer;

public class BerkeleyKvs implements ITransactionalKvs {

  private Database berkeley;
  private Transaction txn;

  public BerkeleyKvs(Database berkeley, Transaction txn) {
    this.berkeley = berkeley;
    this.txn = txn;
  }

  @Override
  public <T> T get(Class<T> clazz, Object key) {
    ZeSerializer serializer = new ZeSerializer();
    byte[] keyBytes = serializer.serialize(key);
    DatabaseEntry keyEntry = new DatabaseEntry(keyBytes);
    DatabaseEntry valueEntry = new DatabaseEntry();
    try {
      OperationStatus status = berkeley.get(txn, keyEntry, valueEntry, LockMode.DEFAULT);
      if (status == OperationStatus.NOTFOUND)
        return null;
      byte[] data = valueEntry.getData();
      reads++;
      readBytes += data.length;
      T value = serializer.deserialize(new ByteArrayInputStream(data), clazz);
      return value;
    } catch (DatabaseException e) {
      throw new RuntimeException(e);
    }
  }

  @Override
  public <T> void put(Object key, T value) {
    ZeSerializer serializer = new ZeSerializer();
    byte[] keyBytes = serializer.serialize(key);
    DatabaseEntry keyEntry = new DatabaseEntry(keyBytes);
    byte[] valueBytes = serializer.serialize(value);
    DatabaseEntry valueEntry = new DatabaseEntry(valueBytes);    
    try {
      berkeley.put(txn, keyEntry, valueEntry);
      writes++;
{'fraction_non_alphanumeric': 0.10101564644523744, 'fraction_numerical': 0.0, 'mean_word_length': 4.019283746556474, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6535498', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1095, 'n_words': 262}