ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.jbpm.pvm.internal.lob;
 
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
 
public class ClobStrategyChopped implements ClobStrategy {
  
  int chopSize = 1024;
  
  public char[] get(Lob lob) {
    return glue(lob.charChops);
  }
 
  public void set(char[] chars, Lob lob) {
    lob.charChops = chop(chars);
  }
 
  public List<CharChop> chop(char[] chars) {
    List<CharChop> charChops = null;
    if ( (chars!=null)
         && (chars.length>0) ){
      charChops = new ArrayList<CharChop>();
      int index = 0;
      while ( (chars.length-index) > chopSize ) {
        String chop = new String(chars, index, chopSize);
        charChops.add(new CharChop(chop));
        index+=chopSize;
      }
      // add remainder chop
      String chop = new String(chars, index, chars.length-index);
      charChops.add(new CharChop(chop));
    }
    return charChops;
  }
 
  public char[] glue(List<CharChop> charChops) {
    if (charChops!=null) {
      StringWriter writer = new StringWriter();
      
      for (CharChop charChop: charChops) {
        writer.write(charChop.getText());
      }
      
      return writer.toString().toCharArray();
    }
 
    return null;
  }
}