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.FileCache;
8 import org.simantics.acorn.exception.AcornAccessVerificationException;
9 import org.simantics.acorn.exception.IllegalAcornStateException;
10 import org.simantics.db.service.Bytes;
11 import org.simantics.utils.datastructures.Pair;
13 import gnu.trove.list.array.TByteArrayList;
15 public class ChangeSetInfo extends LRUObject<Long, ChangeSetInfo> {
17 private byte[] metadataBytes;
18 private ArrayList<String> clusterChangeSetIds;
21 public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, FileCache fileCache, Path readDir, Long revision, int offset, int length) throws AcornAccessVerificationException {
22 super(LRU, fileCache, revision, readDir, "clusterStream", offset, length, false, false);
27 public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, FileCache fileCache, Long revision, byte[] bytes, ArrayList<String> clusterChangeSetIds) throws AcornAccessVerificationException {
28 super(LRU, fileCache, revision, LRU.getDirectory(), "clusterStream", true, true);
29 this.metadataBytes = bytes;
30 this.metadataBytes = bytes;
31 this.clusterChangeSetIds = clusterChangeSetIds;
32 LRU.insert(this, accessTime);
35 public ArrayList<String> getCCSIds() throws AcornAccessVerificationException {
36 if(VERIFY) verifyAccess();
37 return clusterChangeSetIds;
40 public byte[] getMetadataBytes() throws AcornAccessVerificationException, IllegalAcornStateException {
48 private static void writeLE(TByteArrayList bytes, int value) {
50 bytes.add( (byte) (value & 0xFF));
51 bytes.add((byte) ((value >>> 8) & 0xFF));
52 bytes.add((byte) ((value >>> 16) & 0xFF));
53 bytes.add((byte) ((value >>> 24) & 0xFF));
58 protected Pair<byte[], Integer> toBytes() {
60 TByteArrayList result = new TByteArrayList();
61 writeLE(result, metadataBytes.length);
62 result.add(metadataBytes);
63 writeLE(result, clusterChangeSetIds.size());
64 for(String id : clusterChangeSetIds) {
65 byte[] bb = id.getBytes();
66 writeLE(result, bb.length);
72 byte[] ret = result.toArray();
74 return Pair.make(ret, ret.length);
80 clusterChangeSetIds = null;
85 public void fromFile(byte[] data) {
87 clusterChangeSetIds = new ArrayList<String>();
89 int metadataLength = Bytes.readLE4(data, 0);
90 metadataBytes = Arrays.copyOfRange(data, 4, 4+metadataLength);
91 int offset = 4+metadataLength;
92 int numberOfChangeSets = Bytes.readLE4(data, offset);
94 for(int i=0;i<numberOfChangeSets;i++) {
95 int length = Bytes.readLE4(data, offset);
97 String id = new String(Arrays.copyOfRange(data, offset, offset+length));
98 clusterChangeSetIds.add(id);
105 String getExtension() {
110 protected boolean overwrite() {