All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.pvm.internal.lob.ClobStrategyChopped Maven / Gradle / Ivy

package org.ow2.bonita.pvm.internal.lob;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ClobStrategyChopped implements ClobStrategy {

  int chopSize = 1024;

  public char[] get(Clob clob) {
    return glue(clob.getChops());
  }

  public void set(char[] chars, Clob clob) {
    clob.setChops(chop(chars));
  }

  public List chop(char[] chars) {
    List chops = null;
    if ((chars != null) && (chars.length > 0)) {
      chops = new ArrayList();
      int index = 0;
      while ((chars.length - index) > chopSize) {
        String chop = new String(chars, index, chopSize);
        chops.add(chop);
        index += chopSize;
      }
      // add remainder chop
      String chop = new String(chars, index, chars.length - index);
      chops.add(chop);
    }
    return chops;
  }

  public char[] glue(List chops) {
    if (chops != null) {
      StringWriter writer = new StringWriter();

      Iterator iter = chops.iterator();
      while (iter.hasNext()) {
        writer.write(iter.next());
      }

      return writer.toString().toCharArray();
    }

    return null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy