1 package org.simantics.acorn.lru;
3 import java.nio.file.Path;
4 import java.util.ArrayList;
5 import java.util.Arrays;
7 import org.simantics.acorn.exception.AcornAccessVerificationException;
8 import org.simantics.acorn.exception.IllegalAcornStateException;
9 import org.simantics.db.service.Bytes;
10 import org.simantics.utils.datastructures.Pair;
12 import gnu.trove.list.array.TByteArrayList;
14 public class ChangeSetInfo extends LRUObject<Long, ChangeSetInfo> {
16 private byte[] metadataBytes;
17 private ArrayList<String> clusterChangeSetIds;
20 public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, Path readDir, Long revision, int offset, int length) throws AcornAccessVerificationException {
21 super(LRU, revision, readDir, "clusterStream", offset, length, false, false);
26 public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, Long revision, byte[] bytes, ArrayList<String> clusterChangeSetIds) throws AcornAccessVerificationException {
27 super(LRU, revision, LRU.getDirectory(), "clusterStream", true, true);
28 this.metadataBytes = bytes;
29 this.metadataBytes = bytes;
30 this.clusterChangeSetIds = clusterChangeSetIds;
31 LRU.insert(this, accessTime);
34 public ArrayList<String> getCCSIds() throws AcornAccessVerificationException {
35 if(VERIFY) verifyAccess();
36 return clusterChangeSetIds;
39 public byte[] getMetadataBytes() throws AcornAccessVerificationException, IllegalAcornStateException {
47 private static void writeLE(TByteArrayList bytes, int value) {
49 bytes.add( (byte) (value & 0xFF));
50 bytes.add((byte) ((value >>> 8) & 0xFF));
51 bytes.add((byte) ((value >>> 16) & 0xFF));
52 bytes.add((byte) ((value >>> 24) & 0xFF));
57 protected Pair<byte[], Integer> toBytes() {
59 TByteArrayList result = new TByteArrayList();
60 writeLE(result, metadataBytes.length);
61 result.add(metadataBytes);
62 writeLE(result, clusterChangeSetIds.size());
63 for(String id : clusterChangeSetIds) {
64 byte[] bb = id.getBytes();
65 writeLE(result, bb.length);
71 byte[] ret = result.toArray();
73 return Pair.make(ret, ret.length);
79 clusterChangeSetIds = null;
84 public void fromFile(byte[] data) {
86 clusterChangeSetIds = new ArrayList<String>();
88 int metadataLength = Bytes.readLE4(data, 0);
89 metadataBytes = Arrays.copyOfRange(data, 4, 4+metadataLength);
90 int offset = 4+metadataLength;
91 int numberOfChangeSets = Bytes.readLE4(data, offset);
93 for(int i=0;i<numberOfChangeSets;i++) {
94 int length = Bytes.readLE4(data, offset);
96 String id = new String(Arrays.copyOfRange(data, offset, offset+length));
97 clusterChangeSetIds.add(id);
104 String getExtension() {
109 protected boolean overwrite() {