KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > magicStore > IDTableNodeLeaf


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package org.ozoneDB.core.storage.magicStore;
10
11 import java.io.*;
12
13 import org.ozoneDB.DxLib.*;
14 import org.ozoneDB.core.ObjectID;
15 import org.ozoneDB.core.storage.ClusterID;
16
17
18 /**
19  * This extension of the DxDiskHashNodeLeaf class assumes that the key and data
20  * member of the stored DxKayData pairs are ObjectIDs. Thus is casts and writes
21  * them directly to the stream for better performance.
22  */

23 class IDTableNodeLeaf extends DxDiskHashNodeLeaf implements Externalizable {
24
25     final static long serialVersionUID = 1L;
26
27
28     public IDTableNodeLeaf(DxDiskHashMap _grandParent) {
29         super(_grandParent);
30     }
31
32
33     public void writeExternal(ObjectOutput out) throws IOException {
34         byte c = 0;
35         for (DxKeyData elem = element; elem != null; elem = elem.next) {
36             c++;
37         }
38         out.writeByte(c);
39
40         DxKeyData elem = element;
41         while (elem != null) {
42             ((ObjectID) elem.key).writeExternal(out);
43             ((ObjectID) elem.data).writeExternal(out);
44             elem = elem.next;
45         }
46     }
47
48
49     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException JavaDoc {
50         byte c = in.readByte();
51
52         ObjectID key = ((IDTable) grandParent).newObjectID();
53         key.readExternal(in);
54         ClusterID data = ((IDTable) grandParent).newClusterID();
55         data.readExternal(in);
56         element = grandParent.newKeyData();
57         element.set(key, data);
58
59         DxKeyData elem = element;
60         for (int i = 1; i < c; i++) {
61             key = ((IDTable) grandParent).newObjectID();
62             key.readExternal(in);
63             data = ((IDTable) grandParent).newClusterID();
64             data.readExternal(in);
65             elem.next = grandParent.newKeyData();
66             elem.next.set(key, data);
67             elem = elem.next;
68         }
69     }
70 }
71
Popular Tags