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
51
52
53
package org.jbpm.pvm.internal.lob;
 
import java.util.ArrayList;
import java.util.List;
 
public class BlobStrategyChopped implements BlobStrategy {
 
  int chopSize = 1024;
 
  public void set(byte[] bytes, Lob lob) {
    lob.bytesChops = chop(bytes);
  }
 
  public byte[] get(Lob lob) {
    return glue(lob.bytesChops);
  }
 
  public List<BytesChop> chop(byte[] bytes) {
    List<BytesChop> chops = null;
    if ( (bytes!=null)
         && (bytes.length>0) ){
      chops = new ArrayList<BytesChop>();
      int index = 0;
      while ( (bytes.length-index) > chopSize ) {
        byte[] byteBlock = new byte[chopSize];
        System.arraycopy(bytes, index, byteBlock, 0, chopSize);
        chops.add(new BytesChop(byteBlock));
        index+=chopSize;
      }
      byte[] byteBlock = new byte[bytes.length-index];
      System.arraycopy(bytes, index, byteBlock, 0, bytes.length-index);
      chops.add(new BytesChop(byteBlock));
    }
    return chops;
  }
 
  public byte[] glue(List<BytesChop> bytesChops) {
    byte[] bytes = null;
    if (bytesChops!=null) {
      for (BytesChop bytesChop: bytesChops) {
        if (bytes==null) {
          bytes = bytesChop.getBytes();
        } else {
          byte[] oldValue = bytes;
          bytes = new byte[bytes.length+bytesChop.getBytes().length];
          System.arraycopy(oldValue, 0, bytes, 0, oldValue.length);
          System.arraycopy(bytesChop.getBytes(), 0, bytes, oldValue.length, bytesChop.getBytes().length);
        }
      }
    }
    return bytes;
  }
}