20 |
index = (DiffIndexType.Index)pool.getIndex(DiffIndexType.indexTypeURI); |
index = (DiffIndexType.Index)pool.getIndex(DiffIndexType.indexTypeURI); |
21 |
} |
} |
22 |
|
|
23 |
public Version load() throws IOException { |
/** |
24 |
return super.load(); |
public Version load(BlockId id) throws IOException { |
25 |
|
return load(id, new Header822[2]); |
26 |
} |
} |
27 |
|
|
28 |
public void save(Version v) throws IOException { |
public Version load(BlockId id, Header822 hdr[]) throws IOException { |
29 |
Version old = load(); |
try { |
30 |
if(old.equals(v)) return; |
return super.load(id); |
31 |
|
} catch(FileNotFoundException _) { |
32 |
|
Set diffs = index.getDiffsTo(id); |
33 |
|
if(diffs.isEmpty()) |
34 |
|
throw new FileNotFoundException("No diff path to: "+id); |
35 |
|
|
36 |
|
BlockId diffId = (BlockId)diffs.iterator().next(); |
37 |
|
Block diffBlock = pool.get(diffId); |
38 |
|
InputStream is = diffBlock.getInputStream(); |
39 |
|
Header822 fromHeader = Headers822.readHeader(is); |
40 |
|
Header822 toHeader = Headers822.readHeader(is); |
41 |
|
Version.Diff diff = format.readDiff(is); |
42 |
|
is.close(); |
43 |
|
|
44 |
|
BlockId fromId; |
45 |
|
try { |
46 |
|
String hex = diffBlock.getHeader().get("X-Gzz-Diff-From"); |
47 |
|
fromId = BlockId.getMediaserverId(hex); |
48 |
|
} catch(NoSuchElementException __) { |
49 |
|
fromId = null; |
50 |
|
} |
51 |
|
|
52 |
|
Version from; |
53 |
|
if(fromId != null) |
54 |
|
from = load(fromId); |
55 |
|
else |
56 |
|
from = emptyVersion; |
57 |
|
|
58 |
|
hdr[0] = fromHeader; |
59 |
|
hdr[1] = toHeader; |
60 |
|
return diff.applyTo(from); |
61 |
|
} |
62 |
|
} |
63 |
|
|
64 |
|
public void save(Version v) throws IOException { |
65 |
|
Version old; |
66 |
BlockId oldId = null; |
BlockId oldId = null; |
67 |
Header822 oldHeader = null; |
Header822 oldHeader = null; |
68 |
|
|
69 |
if(current != null) { |
if(current != null) { |
70 |
|
Header822[] old_hdrs = new Header822[2]; |
71 |
|
old = load(current.getTarget(), old_hdrs); |
72 |
oldId = current.getTarget(); |
oldId = current.getTarget(); |
73 |
oldHeader = pool.get(oldId).getHeader(); // XXX |
oldHeader = old_hdrs[1]; |
74 |
} else { |
} else { |
75 |
|
old = emptyVersion; |
76 |
oldHeader = new VerbatimHeader822(); // empty header |
oldHeader = new VerbatimHeader822(); // empty header |
77 |
} |
} |
78 |
|
|
79 |
|
if(old.equals(v)) return; |
80 |
|
|
81 |
Block newBlock = saveVersion(v); |
Block newBlock = saveVersion(v); |
82 |
|
|
|
/* |
|
83 |
BlockId newId = newBlock.getId(); |
BlockId newId = newBlock.getId(); |
84 |
Header822 newHeader = newBlock.getHeader(); |
Header822 newHeader = newBlock.getHeader(); |
85 |
|
|
88 |
Header822 hdr = new SortedHeader822(); |
Header822 hdr = new SortedHeader822(); |
89 |
hdr.add("Content-Type", diffContentType); |
hdr.add("Content-Type", diffContentType); |
90 |
hdr.add("Content-Transfer-Encoding", "binary"); |
hdr.add("Content-Transfer-Encoding", "binary"); |
91 |
if(old != null) |
if(oldId != null) |
92 |
hdr.add("X-Gzz-Diff-From", oldId.getHex()); |
hdr.add("X-Gzz-Diff-From", oldId.getHex()); |
93 |
hdr.add("X-Gzz-Diff-To", newId.getHex()); |
hdr.add("X-Gzz-Diff-To", newId.getHex()); |
94 |
|
|
95 |
BlockOutputStream bos = pool.getBlockOutputStream(hdr); |
BlockOutputStream bos = pool.getBlockOutputStream(hdr); |
96 |
if(old != null) |
oldHeader.writeTo(bos); |
|
oldHeader.writeTo(bos); |
|
|
else { |
|
|
bos.write((byte)'\r'); |
|
|
bos.write((byte)'\n'); |
|
|
} |
|
97 |
newHeader.writeTo(bos); |
newHeader.writeTo(bos); |
98 |
format.writeDiff(bos, diff); |
format.writeDiff(bos, diff); |
99 |
bos.close(); |
bos.close(); |
|
*/ |
|
100 |
|
|
101 |
//pool.delete(newBlock); |
//pool.delete(newBlock); |
102 |
} |
} |
103 |
|
*/ |
104 |
|
|
105 |
|
|
106 |
// should be simply named .Group |
// should be simply named .Group |