-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLTBlock.java
More file actions
104 lines (96 loc) · 3.03 KB
/
LTBlock.java
File metadata and controls
104 lines (96 loc) · 3.03 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright 2012 Bill La Forge
*
* This file is part of AgileWiki and is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License (LGPL) as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* or navigate to the following url http://www.gnu.org/licenses/lgpl-2.1.txt
*
* Note however that only Scala, Java and JavaScript files are being covered by LGPL.
* All other files are covered by the Common Public License (CPL).
* A copy of this license is also included and can be
* found as well at http://www.opensource.org/licenses/cpl1.0.txt
*/
package org.agilewiki.jfile.block;
import org.agilewiki.jid.AppendableBytes;
import org.agilewiki.jid.Util;
import org.agilewiki.jid.scalar.vlens.actor.RootJid;
/**
* A block with a length and a timestamp in the header.
*/
public class LTBlock extends LBlock {
long timestamp;
/**
* Reset the block and assign the RootJid.
*
* @param rootJid The RootJid to be assigned.
*/
@Override
public void setRootJid(RootJid rootJid) {
super.setRootJid(rootJid);
timestamp = 0L;
}
/**
* The length of the header which prefaces the actual data on disk.
*
* @return The header length.
*/
@Override
public int headerLength() {
return super.headerLength() + Util.LONG_LENGTH;
}
/**
* Provides the raw header information to be written to disk.
*
* @param ab Append the data to this.
* @param l The length of the data.
*/
@Override
protected void saveHeader(AppendableBytes ab, int l)
throws Exception {
if (timestamp == 0)
throw new IllegalStateException("timestamp not set");
super.saveHeader(ab, l);
ab.writeLong(timestamp);
}
/**
* Provides the raw header information read from disk.
*
* @param bytes The header bytes read from disk.
* @return The length of the data following the header on disk.
*/
@Override
public int setHeaderBytes(byte[] bytes) {
int l = super.setHeaderBytes(bytes);
timestamp = rb.readLong();
return l;
}
/**
* Returns the timestamp.
*
* @return The timestamp.
*/
@Override
public long getTimestamp() {
return timestamp;
}
/**
* Assigns the timestamp.
*
* @param timestamp The timestamp.
*/
@Override
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}