• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gephi / graphstore / #535

15 Mar 2026 09:46AM UTC coverage: 91.007% (-0.01%) from 91.02%
#535

push

mbastian
Fix tests

11719 of 12877 relevant lines covered (91.01%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.86
/src/main/java/org/gephi/graph/impl/Serialization.java
1
/*
2
 * Copyright 2012-2013 Gephi Consortium
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
15
 */
16
package org.gephi.graph.impl;
17

18
import java.util.BitSet;
19
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
20
import it.unimi.dsi.fastutil.booleans.BooleanOpenHashSet;
21
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
22
import it.unimi.dsi.fastutil.bytes.ByteArrayList;
23
import it.unimi.dsi.fastutil.bytes.ByteOpenHashSet;
24
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
25
import it.unimi.dsi.fastutil.chars.CharArrayList;
26
import it.unimi.dsi.fastutil.chars.CharOpenHashSet;
27
import it.unimi.dsi.fastutil.doubles.Double2IntMap;
28
import it.unimi.dsi.fastutil.doubles.Double2ObjectOpenHashMap;
29
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
30
import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet;
31
import it.unimi.dsi.fastutil.floats.Float2ObjectOpenHashMap;
32
import it.unimi.dsi.fastutil.floats.FloatArrayList;
33
import it.unimi.dsi.fastutil.floats.FloatOpenHashSet;
34
import it.unimi.dsi.fastutil.ints.Int2IntMap;
35
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
36
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
37
import it.unimi.dsi.fastutil.ints.IntArrayList;
38
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
39
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
40
import it.unimi.dsi.fastutil.longs.LongArrayList;
41
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
42
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
43
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
44
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
45
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
46
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
47
import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet;
48
import java.io.DataInput;
49
import java.io.DataOutput;
50
import java.io.EOFException;
51
import java.io.IOException;
52
import java.lang.reflect.Array;
53
import java.math.BigDecimal;
54
import java.math.BigInteger;
55
import java.time.Instant;
56
import java.time.ZoneId;
57
import java.util.Date;
58
import java.util.List;
59
import java.util.Locale;
60
import java.util.Map;
61
import java.util.Set;
62
import org.gephi.graph.api.Configuration;
63
import org.gephi.graph.api.Edge;
64
import org.gephi.graph.api.Estimator;
65
import org.gephi.graph.api.GraphModel;
66
import org.gephi.graph.api.Interval;
67
import org.gephi.graph.api.Node;
68
import org.gephi.graph.api.Origin;
69
import org.gephi.graph.api.TimeFormat;
70
import org.gephi.graph.api.TimeRepresentation;
71
import org.gephi.graph.api.types.IntervalBooleanMap;
72
import org.gephi.graph.api.types.IntervalByteMap;
73
import org.gephi.graph.api.types.IntervalCharMap;
74
import org.gephi.graph.api.types.IntervalDoubleMap;
75
import org.gephi.graph.api.types.IntervalFloatMap;
76
import org.gephi.graph.api.types.IntervalIntegerMap;
77
import org.gephi.graph.api.types.IntervalLongMap;
78
import org.gephi.graph.api.types.IntervalMap;
79
import org.gephi.graph.api.types.IntervalSet;
80
import org.gephi.graph.api.types.IntervalShortMap;
81
import org.gephi.graph.api.types.IntervalStringMap;
82
import org.gephi.graph.api.types.TimestampBooleanMap;
83
import org.gephi.graph.api.types.TimestampByteMap;
84
import org.gephi.graph.api.types.TimestampCharMap;
85
import org.gephi.graph.api.types.TimestampDoubleMap;
86
import org.gephi.graph.api.types.TimestampFloatMap;
87
import org.gephi.graph.api.types.TimestampIntegerMap;
88
import org.gephi.graph.api.types.TimestampLongMap;
89
import org.gephi.graph.api.types.TimestampMap;
90
import org.gephi.graph.api.types.TimestampSet;
91
import org.gephi.graph.api.types.TimestampShortMap;
92
import org.gephi.graph.api.types.TimestampStringMap;
93
import org.gephi.graph.impl.EdgeImpl.EdgePropertiesImpl;
94
import org.gephi.graph.impl.NodeImpl.NodePropertiesImpl;
95
import org.gephi.graph.impl.utils.DataInputOutput;
96
import org.gephi.graph.impl.utils.LongPacker;
97

98
// Greatly inspired from JDBM https://github.com/jankotek/JDBM3
99
public class Serialization {
100

101
    final static float VERSION = 0.5f;
102
    final static int NULL_ID = -1;
103
    final static int NULL = 0;
104
    final static int NORMAL = 1;
105
    final static int BOOLEAN_TRUE = 2;
106
    final static int BOOLEAN_FALSE = 3;
107
    final static int INTEGER_MINUS_1 = 4;
108
    final static int INTEGER_0 = 5;
109
    final static int INTEGER_1 = 6;
110
    final static int INTEGER_2 = 7;
111
    final static int INTEGER_3 = 8;
112
    final static int INTEGER_4 = 9;
113
    final static int INTEGER_5 = 10;
114
    final static int INTEGER_6 = 11;
115
    final static int INTEGER_7 = 12;
116
    final static int INTEGER_8 = 13;
117
    final static int INTEGER_255 = 14;
118
    final static int INTEGER_PACK_NEG = 15;
119
    final static int INTEGER_PACK = 16;
120
    final static int LONG_MINUS_1 = 17;
121
    final static int LONG_0 = 18;
122
    final static int LONG_1 = 19;
123
    final static int LONG_2 = 20;
124
    final static int LONG_3 = 21;
125
    final static int LONG_4 = 22;
126
    final static int LONG_5 = 23;
127
    final static int LONG_6 = 24;
128
    final static int LONG_7 = 25;
129
    final static int LONG_8 = 26;
130
    final static int LONG_PACK_NEG = 27;
131
    final static int LONG_PACK = 28;
132
    final static int LONG_255 = 29;
133
    final static int LONG_MINUS_MAX = 30;
134
    final static int SHORT_MINUS_1 = 31;
135
    final static int SHORT_0 = 32;
136
    final static int SHORT_1 = 33;
137
    final static int SHORT_255 = 34;
138
    final static int SHORT_FULL = 35;
139
    final static int BYTE_MINUS_1 = 36;
140
    final static int BYTE_0 = 37;
141
    final static int BYTE_1 = 38;
142
    final static int BYTE_FULL = 39;
143
    final static int CHAR = 40;
144
    final static int FLOAT_MINUS_1 = 41;
145
    final static int FLOAT_0 = 42;
146
    final static int FLOAT_1 = 43;
147
    final static int FLOAT_255 = 44;
148
    final static int FLOAT_SHORT = 45;
149
    final static int FLOAT_FULL = 46;
150
    final static int DOUBLE_MINUS_1 = 47;
151
    final static int DOUBLE_0 = 48;
152
    final static int DOUBLE_1 = 49;
153
    final static int DOUBLE_255 = 50;
154
    final static int DOUBLE_SHORT = 51;
155
    final static int DOUBLE_FULL = 52;
156
    final static int DOUBLE_ARRAY = 53;
157
    final static int BIGDECIMAL = 54;
158
    final static int BIGINTEGER = 55;
159
    final static int FLOAT_ARRAY = 56;
160
    final static int INTEGER_MINUS_MAX = 57;
161
    final static int SHORT_ARRAY = 58;
162
    final static int BOOLEAN_ARRAY = 59;
163
    final static int ARRAY_INT_B_255 = 60;
164
    final static int ARRAY_INT_B_INT = 61;
165
    final static int ARRAY_INT_S = 62;
166
    final static int ARRAY_INT_I = 63;
167
    final static int ARRAY_INT_PACKED = 64;
168
    final static int ARRAY_LONG_B = 65;
169
    final static int ARRAY_LONG_S = 66;
170
    final static int ARRAY_LONG_I = 67;
171
    final static int ARRAY_LONG_L = 68;
172
    final static int ARRAY_LONG_PACKED = 69;
173
    final static int CHAR_ARRAY = 70;
174
    final static int ARRAY_BYTE_INT = 71;
175
    final static int NOTUSED_ARRAY_OBJECT_255 = 72;
176
    final static int ARRAY_OBJECT = 73;
177
    final static int STRING_ARRAY = 74;
178
    final static int STRING_EMPTY = 101;
179
    final static int NOTUSED_STRING_255 = 102;
180
    final static int STRING = 103;
181
    final static int LOCALE = 124;
182
    final static int PROPERTIES = 125;
183
    final static int CLASS = 126;
184
    final static int DATE = 127;
185
    final static String EMPTY_STRING = "";
186
    // Specifics
187
    final static int NODE = 200;
188
    final static int EDGE = 201;
189
    final static int EDGETYPE_STORE = 202;
190
    final static int COLUMN_ORIGIN = 203;
191
    final static int TABLE = 204;
192
    final static int CONFIGURATION = 205;
193
    final static int GRAPH_STORE = 206;
194
    final static int GRAPH_FACTORY = 207;
195
    final static int GRAPH_VIEW_STORE = 208;
196
    final static int GRAPH_VIEW = 209;
197
    final static int BIT_VECTOR = 210;
198
    final static int GRAPH_STORE_CONFIGURATION = 211;
199
    final static int TIME_REPRESENTATION = 212;
200
    final static int GRAPH_VERSION = 213;
201
    final static int NODE_PROPERTIES = 214;
202
    final static int EDGE_PROPERTIES = 215;
203
    final static int TEXT_PROPERTIES = 216;
204
    final static int ESTIMATOR = 217;
205
    final static int GRAPH_ATTRIBUTES = 218;
206
    final static int TIMESTAMP_INDEX_STORE = 219;
207
    final static int INTERVAL_INDEX_STORE = 220;
208
    final static int TIME_FORMAT = 221;
209
    final static int TIME_STORE = 222;
210
    final static int TIMESTAMP_SET = 223;
211
    final static int INTERVAL_SET = 224;
212
    final static int TIMESTAMP_MAP = 225;
213
    final static int INTERVAL_MAP = 226;
214
    final static int TIME_ZONE = 227;
215
    final static int INTERVAL = 228;
216
    final static int LIST = 229;
217
    final static int SET = 230;
218
    final static int MAP = 231;
219
    final static int INSTANT = 232;
220
    // Store
221
    protected final Int2IntMap idMap;
222
    protected GraphModelImpl model;
223
    protected float readVersion = VERSION;
1✔
224
    // Deserialized configuration
225
    protected GraphStoreConfigurationVersion graphStoreConfigurationVersion;
226

227
    public Serialization() {
228
        this(null);
1✔
229
    }
1✔
230

231
    public Serialization(GraphModelImpl graphModel) {
1✔
232
        model = graphModel;
1✔
233
        idMap = new Int2IntOpenHashMap();
1✔
234
        idMap.defaultReturnValue(NULL_ID);
1✔
235
    }
1✔
236

237
    public void serializeGraphModel(DataOutput out, GraphModelImpl model) throws IOException {
238
        this.model = model;
1✔
239
        serialize(out, VERSION);
1✔
240
        serialize(out, model.configuration);
1✔
241
        serialize(out, model.store);
1✔
242
    }
1✔
243

244
    public GraphModelImpl deserializeGraphModel(DataInput is) throws IOException, ClassNotFoundException {
245
        readVersion = (Float) deserialize(is);
1✔
246
        ConfigurationImpl config = (ConfigurationImpl) deserialize(is);
1✔
247
        model = new GraphModelImpl(config.toConfiguration());
1✔
248
        deserialize(is);
1✔
249
        return model;
1✔
250
    }
251

252
    public GraphModelImpl deserializeGraphModel(DataInput is, GraphModel graphModel) throws IOException, ClassNotFoundException {
253
        model = (GraphModelImpl) graphModel;
1✔
254
        readVersion = (Float) deserialize(is);
1✔
255
        ConfigurationImpl config = (ConfigurationImpl) deserialize(is);
1✔
256
        verifyCompatibility(config, model.configuration);
1✔
257
        deserialize(is);
1✔
258
        return model;
1✔
259
    }
260

261
    private void verifyCompatibility(ConfigurationImpl readConfig, ConfigurationImpl modelConfig) {
262
        // Time representation
263
        if (!readConfig.getTimeRepresentation().equals(modelConfig.getTimeRepresentation())) {
1✔
264
            throw new RuntimeException("The time representations doesn't match, read: " + readConfig
×
265
                    .getTimeRepresentation() + ", model: " + modelConfig.getTimeRepresentation());
×
266
        }
267

268
        // Node id type
269
        if (!readConfig.getNodeIdType().equals(modelConfig.getNodeIdType())) {
1✔
270
            throw new RuntimeException("The node id type doesn't match, read: " + readConfig
×
271
                    .getNodeIdType() + ", model: " + modelConfig.getNodeIdType());
×
272
        }
273

274
        // Edge id type
275
        if (!readConfig.getEdgeIdType().equals(modelConfig.getEdgeIdType())) {
1✔
276
            throw new RuntimeException("The edge id type doesn't match, read: " + readConfig
×
277
                    .getEdgeIdType() + ", model: " + modelConfig.getEdgeIdType());
×
278
        }
279

280
        // Edge weight type
281
        if (!readConfig.getEdgeWeightType().equals(modelConfig.getEdgeWeightType())) {
1✔
282
            throw new RuntimeException("The edge weight type doesn't match, read: " + readConfig
×
283
                    .getEdgeWeightType() + ", model: " + modelConfig.getEdgeWeightType());
×
284
        }
285

286
        // Edge label type
287
        if (!readConfig.getEdgeLabelType().equals(modelConfig.getEdgeLabelType())) {
1✔
288
            throw new RuntimeException("The edge label type doesn't match, read: " + readConfig
×
289
                    .getEdgeLabelType() + ", model: " + modelConfig.getEdgeLabelType());
×
290
        }
291
    }
1✔
292

293
    public GraphModelImpl deserializeGraphModelWithoutVersionPrefix(DataInput is, float version) throws IOException, ClassNotFoundException {
294
        readVersion = version;
1✔
295
        ConfigurationImpl config = (ConfigurationImpl) deserialize(is);
1✔
296
        model = new GraphModelImpl(config.toConfiguration());
1✔
297
        deserialize(is);
1✔
298
        return model;
1✔
299
    }
300

301
    public void serializeGraphStore(DataOutput out, GraphStore store) throws IOException {
302
        // Configuration
303
        serializeGraphStoreConfiguration(out);
1✔
304

305
        // GraphVersion
306
        serialize(out, store.version);
1✔
307

308
        // Edge types
309
        EdgeTypeStore edgeTypeStore = store.edgeTypeStore;
1✔
310
        serialize(out, edgeTypeStore);
1✔
311

312
        // Column
313
        serialize(out, store.nodeTable);
1✔
314
        serialize(out, store.edgeTable);
1✔
315

316
        // Time store
317
        serialize(out, store.timeStore);
1✔
318

319
        // Factory
320
        serialize(out, store.factory);
1✔
321

322
        // Atts
323
        serialize(out, store.attributes);
1✔
324

325
        // TimeFormat
326
        serialize(out, store.timeFormat);
1✔
327

328
        // Time zone
329
        serialize(out, store.timeZone);
1✔
330

331
        // Nodes + Edges
332
        int nodesAndEdges = store.nodeStore.size() + store.edgeStore.size();
1✔
333
        serialize(out, nodesAndEdges);
1✔
334

335
        for (Node node : store.nodeStore) {
1✔
336
            serialize(out, node);
1✔
337
        }
1✔
338
        for (Edge edge : store.edgeStore) {
1✔
339
            serialize(out, edge);
1✔
340
        }
1✔
341

342
        // Views
343
        serialize(out, store.viewStore);
1✔
344
    }
1✔
345

346
    public GraphStore deserializeGraphStore(DataInput is) throws IOException, ClassNotFoundException {
347
        if (!model.store.nodeStore.isEmpty()) { // TODO test other stores
1✔
348
            throw new IOException("The store is not empty");
×
349
        }
350

351
        // Store Configuration
352
        deserialize(is);
1✔
353

354
        // Graph Version
355
        GraphVersion version = (GraphVersion) deserialize(is);
1✔
356
        model.store.version.nodeVersion = version.nodeVersion;
1✔
357
        model.store.version.edgeVersion = version.edgeVersion;
1✔
358

359
        // Edge types
360
        deserialize(is);
1✔
361

362
        // Columns
363
        deserialize(is);
1✔
364
        deserialize(is);
1✔
365

366
        // Time store
367
        deserialize(is);
1✔
368

369
        // Factory
370
        deserialize(is);
1✔
371

372
        // Atts
373
        GraphAttributesImpl attributes = (GraphAttributesImpl) deserialize(is);
1✔
374
        model.store.attributes.setGraphAttributes(attributes);
1✔
375

376
        // TimeFormat
377
        deserialize(is);
1✔
378

379
        // Time zone
380
        deserialize(is);
1✔
381

382
        // Nodes and edges
383
        int nodesAndEdges = (Integer) deserialize(is);
1✔
384
        for (int i = 0; i < nodesAndEdges; i++) {
1✔
385
            deserialize(is);
1✔
386
        }
387

388
        // ViewStore
389
        deserialize(is);
1✔
390

391
        return model.store;
1✔
392
    }
393

394
    private void serializeNode(DataOutput out, NodeImpl node) throws IOException {
395
        serialize(out, node.getId());
1✔
396
        serialize(out, node.storeId);
1✔
397
        serialize(out, node.attributes.attributes);
1✔
398
        serialize(out, node.properties);
1✔
399
    }
1✔
400

401
    private void serializeEdge(DataOutput out, EdgeImpl edge) throws IOException {
402
        serialize(out, edge.getId());
1✔
403
        serialize(out, edge.source.storeId);
1✔
404
        serialize(out, edge.target.storeId);
1✔
405
        serialize(out, edge.type);
1✔
406
        if (edge.graphStore != null && edge.hasDynamicWeight()) {
1✔
407
            serialize(out, edge.getWeight());
×
408
        } else {
409
            serialize(out, GraphStoreConfiguration.DEFAULT_EDGE_WEIGHT);
1✔
410
        }
411
        serialize(out, edge.isDirected());
1✔
412
        serialize(out, edge.attributes.attributes);
1✔
413
        serialize(out, edge.properties);
1✔
414
    }
1✔
415

416
    private NodeImpl deserializeNode(DataInput is) throws IOException, ClassNotFoundException {
417
        Object id = deserialize(is);
1✔
418
        int storeId = (Integer) deserialize(is);
1✔
419
        Object[] attributes = (Object[]) deserialize(is);
1✔
420
        NodePropertiesImpl properties = (NodePropertiesImpl) deserialize(is);
1✔
421

422
        NodeImpl node = (NodeImpl) model.store.factory.newNode(id);
1✔
423
        node.attributes.setBackingArray(attributes);
1✔
424
        if (node.properties != null) {
1✔
425
            node.setNodeProperties(properties);
1✔
426
        }
427
        model.store.nodeStore.add(node);
1✔
428

429
        idMap.put(storeId, node.storeId);
1✔
430

431
        return node;
1✔
432
    }
433

434
    private EdgeImpl deserializeEdge(DataInput is) throws IOException, ClassNotFoundException {
435
        Object id = deserialize(is);
1✔
436
        int sourceId = (Integer) deserialize(is);
1✔
437
        int targetId = (Integer) deserialize(is);
1✔
438
        int type = (Integer) deserialize(is);
1✔
439
        double weight = (Double) deserialize(is);
1✔
440
        boolean directed = (Boolean) deserialize(is);
1✔
441
        Object[] attributes = (Object[]) deserialize(is);
1✔
442
        EdgePropertiesImpl properties = (EdgePropertiesImpl) deserialize(is);
1✔
443

444
        int sourceNewId = idMap.get(sourceId);
1✔
445
        int targetNewId = idMap.get(targetId);
1✔
446

447
        if (sourceNewId == NULL_ID || targetNewId == NULL_ID) {
1✔
448
            throw new IOException("The edge source or target can't be found");
×
449
        }
450

451
        NodeImpl source = model.store.nodeStore.get(sourceNewId);
1✔
452
        NodeImpl target = model.store.nodeStore.get(targetNewId);
1✔
453

454
        EdgeImpl edge = (EdgeImpl) model.store.factory.newEdge(id, source, target, type, weight, directed);
1✔
455
        edge.attributes.setBackingArray(attributes);
1✔
456
        if (edge.properties != null) {
1✔
457
            edge.setEdgeProperties(properties);
1✔
458
        }
459

460
        model.store.edgeStore.add(edge);
1✔
461

462
        return edge;
1✔
463
    }
464

465
    private void serializeEdgeTypeStore(final DataOutput out) throws IOException {
466
        EdgeTypeStore edgeTypeStore = model.store.edgeTypeStore;
1✔
467
        int length = edgeTypeStore.length;
1✔
468
        serialize(out, length);
1✔
469
        short[] ids = edgeTypeStore.getIds();
1✔
470
        serialize(out, ids);
1✔
471
        Object[] labels = edgeTypeStore.getLabels();
1✔
472
        serialize(out, labels);
1✔
473
        short[] garbage = edgeTypeStore.getGarbage();
1✔
474
        serialize(out, garbage);
1✔
475
    }
1✔
476

477
    private EdgeTypeStore deserializeEdgeTypeStore(final DataInput is) throws IOException, ClassNotFoundException {
478
        int length = (Integer) deserialize(is);
1✔
479
        short[] ids = (short[]) deserialize(is);
1✔
480
        Object[] labels = (Object[]) deserialize(is);
1✔
481
        short[] garbage = (short[]) deserialize(is);
1✔
482

483
        EdgeTypeStore edgeTypeStore = model.store.edgeTypeStore;
1✔
484
        edgeTypeStore.length = length;
1✔
485
        for (int i = 0; i < ids.length; i++) {
1✔
486
            short id = ids[i];
1✔
487
            Object label = labels[i];
1✔
488
            edgeTypeStore.idMap.put(id, label);
1✔
489
            edgeTypeStore.labelMap.put(label, id);
1✔
490
        }
491
        for (int i = 0; i < garbage.length; i++) {
1✔
492
            edgeTypeStore.garbageQueue.add(garbage[i]);
1✔
493
        }
494
        return edgeTypeStore;
1✔
495
    }
496

497
    private void serializeTable(final DataOutput out, final TableImpl table) throws IOException {
498
        serialize(out, table.store.elementType);
1✔
499

500
        serializeColumnStore(out, table.store);
1✔
501
    }
1✔
502

503
    private TableImpl deserializeTable(final DataInput is) throws IOException, ClassNotFoundException {
504
        Class elementType = (Class) deserialize(is);
1✔
505

506
        TableImpl table = null;
1✔
507

508
        if (elementType.equals(Node.class)) {
1✔
509
            table = model.store.nodeTable;
1✔
510
        } else if (elementType.equals(Edge.class)) {
1✔
511
            table = model.store.edgeTable;
1✔
512
        } else {
513
            throw new RuntimeException("Not recognized column store");
×
514
        }
515

516
        deserializeColumnStore(is, table);
1✔
517

518
        return table;
1✔
519
    }
520

521
    private void serializeColumnStore(final DataOutput out, final ColumnStore columnStore) throws IOException {
522
        int length = columnStore.length;
1✔
523
        serialize(out, length);
1✔
524

525
        for (int i = 0; i < length; i++) {
1✔
526
            ColumnImpl col = columnStore.columns[i];
1✔
527
            serializeColumn(out, col);
1✔
528
        }
529

530
        serialize(out, columnStore.garbageQueue.toShortArray());
1✔
531
    }
1✔
532

533
    private ColumnStore deserializeColumnStore(final DataInput is, final TableImpl table) throws IOException, ClassNotFoundException {
534
        ColumnStore columnStore = table.store;
1✔
535
        int length = (Integer) deserialize(is);
1✔
536
        columnStore.length = length;
1✔
537

538
        for (int i = 0; i < length; i++) {
1✔
539
            ColumnImpl col = (ColumnImpl) deserializeColumn(is, table);
1✔
540
            if (col != null) {
1✔
541
                columnStore.columns[col.storeId] = col;
1✔
542
                columnStore.idMap.put(col.id, columnStore.intToShort(col.storeId));
1✔
543
                if (columnStore.indexStore != null) {
1✔
544
                    columnStore.indexStore.addColumn(col);
1✔
545
                }
546
            }
547
        }
548

549
        short[] garbage = (short[]) deserialize(is);
1✔
550
        for (int i = 0; i < garbage.length; i++) {
1✔
551
            columnStore.garbageQueue.add(garbage[i]);
1✔
552
        }
553
        return columnStore;
1✔
554
    }
555

556
    private void serializeColumn(final DataOutput out, final ColumnImpl column) throws IOException {
557
        if (column == null) {
1✔
558
            serialize(out, null);
1✔
559
            return;
1✔
560
        }
561
        serialize(out, column.id);
1✔
562
        serialize(out, column.title);
1✔
563
        serialize(out, column.origin);
1✔
564
        serialize(out, column.storeId);
1✔
565
        serialize(out, column.typeClass);
1✔
566
        serialize(out, column.defaultValue);
1✔
567
        serialize(out, column.indexed);
1✔
568
        serialize(out, column.readOnly);
1✔
569
        serialize(out, column.estimator);
1✔
570
    }
1✔
571

572
    private ColumnImpl deserializeColumn(final DataInput is, TableImpl table) throws IOException, ClassNotFoundException {
573
        String id = (String) deserialize(is);
1✔
574
        if (id == null) {
1✔
575
            return null;
1✔
576
        }
577
        String title = (String) deserialize(is);
1✔
578
        Origin origin = (Origin) deserialize(is);
1✔
579
        int storeId = (Integer) deserialize(is);
1✔
580
        Class typeClass = (Class) deserialize(is);
1✔
581
        Object defaultValue = deserialize(is);
1✔
582
        boolean indexed = (Boolean) deserialize(is);
1✔
583
        boolean readOnly = (Boolean) deserialize(is);
1✔
584
        Estimator estimator = (Estimator) deserialize(is);
1✔
585

586
        ColumnImpl column = model.store.defaultColumns.getColumn(table, storeId);
1✔
587
        if (column == null) {
1✔
588
            column = new ColumnImpl(table, (String) id, typeClass, title, defaultValue, origin, indexed, readOnly);
1✔
589
            column.storeId = storeId;
1✔
590
        }
591

592
        if (estimator != null) {
1✔
593
            column.setEstimator(estimator);
1✔
594
        }
595

596
        return column;
1✔
597
    }
598

599
    private void serializeGraphFactory(final DataOutput out) throws IOException {
600
        GraphFactoryImpl factory = model.store.factory;
1✔
601

602
        serialize(out, factory.getNodeCounter());
1✔
603
        serialize(out, factory.getEdgeCounter());
1✔
604
    }
1✔
605

606
    private GraphFactoryImpl deserializeGraphFactory(final DataInput is) throws IOException, ClassNotFoundException {
607
        GraphFactoryImpl graphFactory = model.store.factory;
1✔
608

609
        int nodeCounter = (Integer) deserialize(is);
1✔
610
        int edgeCounter = (Integer) deserialize(is);
1✔
611

612
        graphFactory.setNodeCounter(nodeCounter);
1✔
613
        graphFactory.setEdgeCounter(edgeCounter);
1✔
614

615
        return graphFactory;
1✔
616
    }
617

618
    private void serializeViewStore(final DataOutput out) throws IOException {
619
        GraphViewStore viewStore = model.store.viewStore;
1✔
620

621
        serialize(out, viewStore.length);
1✔
622
        serialize(out, viewStore.views);
1✔
623
        serialize(out, viewStore.garbageQueue.toIntArray());
1✔
624
    }
1✔
625

626
    private GraphViewStore deserializeViewStore(final DataInput is) throws IOException, ClassNotFoundException {
627
        GraphViewStore viewStore = model.store.viewStore;
1✔
628

629
        int length = (Integer) deserialize(is);
1✔
630
        Object[] views = (Object[]) deserialize(is);
1✔
631
        int[] garbages = (int[]) deserialize(is);
1✔
632

633
        viewStore.length = length;
1✔
634
        viewStore.views = new GraphViewImpl[views.length];
1✔
635
        System.arraycopy(views, 0, viewStore.views, 0, views.length);
1✔
636
        for (int i = 0; i < garbages.length; i++) {
1✔
637
            viewStore.garbageQueue.add(garbages[i]);
1✔
638
        }
639
        return viewStore;
1✔
640
    }
641

642
    private void serializeGraphView(final DataOutput out, final GraphViewImpl view) throws IOException {
643
        serialize(out, view.nodeView);
1✔
644
        serialize(out, view.edgeView);
1✔
645
        serialize(out, view.storeId);
1✔
646
        serialize(out, view.nodeCount);
1✔
647
        serialize(out, view.edgeCount);
1✔
648

649
        serialize(out, view.nodeBitVector);
1✔
650
        serialize(out, view.edgeBitVector);
1✔
651

652
        serialize(out, view.typeCounts);
1✔
653
        serialize(out, view.mutualEdgeTypeCounts);
1✔
654
        serialize(out, view.mutualEdgesCount);
1✔
655

656
        serialize(out, view.version);
1✔
657

658
        serialize(out, view.attributes);
1✔
659
        serialize(out, view.interval);
1✔
660
    }
1✔
661

662
    private GraphViewImpl deserializeGraphView(final DataInput is) throws IOException, ClassNotFoundException {
663
        boolean nodeView = (Boolean) deserialize(is);
1✔
664
        boolean edgeView = (Boolean) deserialize(is);
1✔
665
        GraphViewImpl view = new GraphViewImpl(model.store, nodeView, edgeView);
1✔
666

667
        int storeId = (Integer) deserialize(is);
1✔
668
        int nodeCount = (Integer) deserialize(is);
1✔
669
        int edgeCount = (Integer) deserialize(is);
1✔
670
        BitSet nodeCountVector = (BitSet) deserialize(is);
1✔
671
        BitSet edgeCountVector = (BitSet) deserialize(is);
1✔
672
        int[] typeCounts = (int[]) deserialize(is);
1✔
673
        int[] mutualEdgeTypeCounts = (int[]) deserialize(is);
1✔
674
        int mutualEdgesCount = (Integer) deserialize(is);
1✔
675
        GraphVersion version = (GraphVersion) deserialize(is);
1✔
676
        GraphAttributesImpl atts = (GraphAttributesImpl) deserialize(is);
1✔
677
        Interval interval = (Interval) deserialize(is);
1✔
678

679
        view.nodeCount = nodeCount;
1✔
680
        view.edgeCount = edgeCount;
1✔
681
        view.nodeBitVector = nodeCountVector;
1✔
682
        view.edgeBitVector = edgeCountVector;
1✔
683
        view.storeId = storeId;
1✔
684

685
        view.typeCounts = typeCounts;
1✔
686
        view.mutualEdgesCount = mutualEdgesCount;
1✔
687
        view.mutualEdgeTypeCounts = mutualEdgeTypeCounts;
1✔
688

689
        view.version.nodeVersion = version.nodeVersion;
1✔
690
        view.version.edgeVersion = version.edgeVersion;
1✔
691

692
        view.attributes.setGraphAttributes(atts);
1✔
693
        view.interval = interval;
1✔
694

695
        return view;
1✔
696
    }
697

698
    // Made compatible with legacy BitVector serialization, which was in place until
699
    // version 0.8.1
700
    public void serializeBitSet(final DataOutput out, final BitSet bitSet) throws IOException {
701
        // BitSet.length() returns the index of the highest set bit + 1
702
        // This gives us the logical size (0 if empty)
703
        int size = bitSet.length();
1✔
704

705
        serialize(out, size);
1✔
706

707
        // Get the long array from BitSet
708
        long[] words = bitSet.toLongArray();
1✔
709

710
        // Calculate how many longs BitVector would use for this size
711
        int requiredLongs = (size + 63) / 64;
1✔
712

713
        // Create array with the exact required size (matching BitVector format)
714
        long[] elements = new long[requiredLongs];
1✔
715

716
        // Copy the BitSet data
717
        System.arraycopy(words, 0, elements, 0, Math.min(words.length, requiredLongs));
1✔
718

719
        serialize(out, elements);
1✔
720
    }
1✔
721

722
    public BitSet deserializeBitSet(final DataInput is) throws IOException, ClassNotFoundException {
723
        int size = (Integer) deserialize(is);
1✔
724
        long[] elements = (long[]) deserialize(is);
1✔
725

726
        // BitSet.valueOf() handles the long array correctly
727
        return BitSet.valueOf(elements);
1✔
728
    }
729

730
    private void serializeGraphStoreConfiguration(final DataOutput out) throws IOException {
731
        out.write(GRAPH_STORE_CONFIGURATION);
1✔
732
        serialize(out, GraphStoreConfiguration.ENABLE_ELEMENT_LABEL);
1✔
733
        serialize(out, GraphStoreConfiguration.ENABLE_ELEMENT_TIME_SET);
1✔
734
        // Was GraphStoreConfiguration.ENABLE_NODE_PROPERTIES
735
        serialize(out, true);
1✔
736
        // Was GraphStoreConfiguration.ENABLE_EDGE_PROPERTIES
737
        serialize(out, true);
1✔
738
    }
1✔
739

740
    private GraphStoreConfigurationVersion deserializeGraphStoreConfiguration(final DataInput is) throws IOException, ClassNotFoundException {
741
        boolean enableElementLabel = (Boolean) deserialize(is);
1✔
742
        boolean enableElementTimestamp = (Boolean) deserialize(is);
1✔
743
        boolean enableNodeProperties = (Boolean) deserialize(is);
1✔
744
        boolean enableEdgeProperties = (Boolean) deserialize(is);
1✔
745

746
        graphStoreConfigurationVersion = new GraphStoreConfigurationVersion(enableElementLabel, enableElementTimestamp,
1✔
747
                enableNodeProperties, enableEdgeProperties);
748
        return graphStoreConfigurationVersion;
1✔
749
    }
750

751
    private void serializeGraphVersion(final DataOutput out, final GraphVersion graphVersion) throws IOException {
752
        serialize(out, graphVersion.nodeVersion);
1✔
753
        serialize(out, graphVersion.edgeVersion);
1✔
754
    }
1✔
755

756
    private GraphVersion deserializeGraphVersion(final DataInput is) throws IOException, ClassNotFoundException {
757
        GraphVersion graphVersion = new GraphVersion(null);
1✔
758

759
        int nodeVersion = (Integer) deserialize(is);
1✔
760
        int edgeVersion = (Integer) deserialize(is);
1✔
761

762
        graphVersion.nodeVersion = nodeVersion;
1✔
763
        graphVersion.edgeVersion = edgeVersion;
1✔
764

765
        return graphVersion;
1✔
766
    }
767

768
    private void serializeNodeProperties(final DataOutput out, final NodePropertiesImpl nodeProperties) throws IOException {
769
        serialize(out, nodeProperties.x);
1✔
770
        serialize(out, nodeProperties.y);
1✔
771
        serialize(out, nodeProperties.z);
1✔
772
        serialize(out, nodeProperties.rgba);
1✔
773
        serialize(out, nodeProperties.size);
1✔
774
        serialize(out, nodeProperties.fixed);
1✔
775
        serialize(out, nodeProperties.textProperties);
1✔
776
    }
1✔
777

778
    private NodePropertiesImpl deserializeNodeProperties(final DataInput is) throws IOException, ClassNotFoundException {
779
        float x = (Float) deserialize(is);
1✔
780
        float y = (Float) deserialize(is);
1✔
781
        float z = (Float) deserialize(is);
1✔
782
        int rgba = (Integer) deserialize(is);
1✔
783
        float size = (Float) deserialize(is);
1✔
784
        boolean fixed = (Boolean) deserialize(is);
1✔
785
        TextPropertiesImpl textProperties = (TextPropertiesImpl) deserialize(is);
1✔
786

787
        NodePropertiesImpl props = new NodePropertiesImpl();
1✔
788
        props.x = x;
1✔
789
        props.y = y;
1✔
790
        props.z = z;
1✔
791
        props.rgba = rgba;
1✔
792
        props.size = size;
1✔
793
        props.fixed = fixed;
1✔
794
        props.setTextProperties(textProperties);
1✔
795

796
        return props;
1✔
797
    }
798

799
    private void serializeEdgeProperties(final DataOutput out, final EdgePropertiesImpl edgeProperties) throws IOException {
800
        serialize(out, edgeProperties.rgba);
1✔
801
        serialize(out, edgeProperties.textProperties);
1✔
802
    }
1✔
803

804
    private EdgePropertiesImpl deserializeEdgeProperties(final DataInput is) throws IOException, ClassNotFoundException {
805
        int rgba = (Integer) deserialize(is);
1✔
806
        TextPropertiesImpl textProperties = (TextPropertiesImpl) deserialize(is);
1✔
807

808
        EdgePropertiesImpl props = new EdgePropertiesImpl();
1✔
809
        props.rgba = rgba;
1✔
810
        props.setTextProperties(textProperties);
1✔
811

812
        // Gephi versions before 0.11 used zero alpha to indicate that the element has no color
813
        // Override this to avoid hidden elements
814
        if (props.alpha() <= 0f) {
815
            props.setAlpha(1f);
1✔
816
        }
×
817

818
        return props;
819
    }
1✔
820

821
    private void serializeTextProperties(final DataOutput out, final TextPropertiesImpl textProperties) throws IOException {
822
        serialize(out, textProperties.size);
823
        serialize(out, textProperties.rgba);
1✔
824
        serialize(out, textProperties.visible);
1✔
825
        serialize(out, textProperties.text);
1✔
826
        serialize(out, textProperties.width);
1✔
827
        serialize(out, textProperties.height);
1✔
828
    }
1✔
829

1✔
830
    private TextPropertiesImpl deserializeTextProperties(final DataInput is) throws IOException, ClassNotFoundException {
831
        float size = (Float) deserialize(is);
832
        int rgba = (Integer) deserialize(is);
1✔
833
        boolean visible = (Boolean) deserialize(is);
1✔
834
        String text = (String) deserialize(is);
1✔
835
        float width = (Float) deserialize(is);
1✔
836
        float height = (Float) deserialize(is);
1✔
837

1✔
838
        TextPropertiesImpl props = new TextPropertiesImpl();
839
        props.size = size;
1✔
840
        props.rgba = rgba;
1✔
841
        props.visible = visible;
1✔
842
        props.text = text;
1✔
843
        props.width = width;
1✔
844
        props.height = height;
1✔
845

1✔
846
        // Gephi versions before 0.11 used zero alpha to indicate that the element has no color
847
        // Override this to avoid hidden elements
848
        if (props.getAlpha() <= 0f) {
849
            props.setAlpha(1f);
850
        }
1✔
851

×
852
        return props;
853
    }
854

1✔
855
    private void serializeTimestampSet(final DataOutput out, final TimestampSet timestampSet) throws IOException {
856
        serialize(out, timestampSet.toPrimitiveArray());
857
    }
858

1✔
859
    private TimestampSet deserializeTimestampSet(DataInput is) throws IOException, ClassNotFoundException {
1✔
860
        double[] r = (double[]) deserialize(is);
861

862
        return new TimestampSet(r);
1✔
863
    }
864

1✔
865
    private void serializeIntervalSet(final DataOutput out, final IntervalSet intervalSet) throws IOException {
866
        serialize(out, intervalSet.getIntervals());
867
    }
868

1✔
869
    private IntervalSet deserializeIntervalSet(DataInput is) throws IOException, ClassNotFoundException {
1✔
870
        double[] r = (double[]) deserialize(is);
871

872
        return new IntervalSet(r);
1✔
873
    }
874

1✔
875
    private void serializeTimestampMap(final DataOutput out, final TimestampMap timestampMap) throws IOException {
876
        serialize(out, timestampMap.getTimestamps());
877
        Class mapClass = timestampMap.getClass();
878
        if (mapClass.equals(TimestampBooleanMap.class)) {
1✔
879
            serialize(out, ((TimestampBooleanMap) timestampMap).toBooleanArray());
1✔
880
        } else if (mapClass.equals(TimestampByteMap.class)) {
1✔
881
            serialize(out, ((TimestampByteMap) timestampMap).toByteArray());
1✔
882
        } else if (mapClass.equals(TimestampCharMap.class)) {
1✔
883
            serialize(out, ((TimestampCharMap) timestampMap).toCharacterArray());
1✔
884
        } else if (mapClass.equals(TimestampDoubleMap.class)) {
1✔
885
            serialize(out, ((TimestampDoubleMap) timestampMap).toDoubleArray());
1✔
886
        } else if (mapClass.equals(TimestampFloatMap.class)) {
1✔
887
            serialize(out, ((TimestampFloatMap) timestampMap).toFloatArray());
1✔
888
        } else if (mapClass.equals(TimestampIntegerMap.class)) {
1✔
889
            serialize(out, ((TimestampIntegerMap) timestampMap).toIntegerArray());
1✔
890
        } else if (mapClass.equals(TimestampLongMap.class)) {
1✔
891
            serialize(out, ((TimestampLongMap) timestampMap).toLongArray());
1✔
892
        } else if (mapClass.equals(TimestampShortMap.class)) {
1✔
893
            serialize(out, ((TimestampShortMap) timestampMap).toShortArray());
1✔
894
        } else if (mapClass.equals(TimestampStringMap.class)) {
1✔
895
            serialize(out, timestampMap.toValuesArray());
1✔
896
        } else {
1✔
897
            throw new RuntimeException("Unrecognized timestamp map class");
1✔
898
        }
899
    }
×
900

901
    private TimestampMap deserializeTimestampMap(final DataInput is) throws IOException, ClassNotFoundException {
1✔
902
        double[] timeStamps = (double[]) deserialize(is);
903
        Object values = deserialize(is);
904

1✔
905
        Class mapClass = values.getClass();
1✔
906
        TimestampMap valueSet;
907
        if (mapClass.equals(boolean[].class)) {
1✔
908
            valueSet = new TimestampBooleanMap(timeStamps, (boolean[]) values);
909
        } else if (mapClass.equals(byte[].class)) {
1✔
910
            valueSet = new TimestampByteMap(timeStamps, (byte[]) values);
1✔
911
        } else if (mapClass.equals(char[].class)) {
1✔
912
            valueSet = new TimestampCharMap(timeStamps, (char[]) values);
1✔
913
        } else if (mapClass.equals(double[].class)) {
1✔
914
            valueSet = new TimestampDoubleMap(timeStamps, (double[]) values);
1✔
915
        } else if (mapClass.equals(float[].class)) {
1✔
916
            valueSet = new TimestampFloatMap(timeStamps, (float[]) values);
1✔
917
        } else if (mapClass.equals(int[].class)) {
1✔
918
            valueSet = new TimestampIntegerMap(timeStamps, (int[]) values);
1✔
919
        } else if (mapClass.equals(long[].class)) {
1✔
920
            valueSet = new TimestampLongMap(timeStamps, (long[]) values);
1✔
921
        } else if (mapClass.equals(short[].class)) {
1✔
922
            valueSet = new TimestampShortMap(timeStamps, (short[]) values);
1✔
923
        } else if (mapClass.equals(String[].class)) {
1✔
924
            valueSet = new TimestampStringMap(timeStamps, (String[]) values);
1✔
925
        } else {
1✔
926
            throw new RuntimeException("Unrecognized timestamp map class");
1✔
927
        }
928
        return valueSet;
×
929
    }
930

1✔
931
    private void serializeIntervalMap(final DataOutput out, final IntervalMap intervalMap) throws IOException {
932
        serialize(out, intervalMap.getIntervals());
933
        Class mapClass = intervalMap.getClass();
934
        if (mapClass.equals(IntervalBooleanMap.class)) {
1✔
935
            serialize(out, ((IntervalBooleanMap) intervalMap).toBooleanArray());
1✔
936
        } else if (mapClass.equals(IntervalByteMap.class)) {
1✔
937
            serialize(out, ((IntervalByteMap) intervalMap).toByteArray());
1✔
938
        } else if (mapClass.equals(IntervalCharMap.class)) {
1✔
939
            serialize(out, ((IntervalCharMap) intervalMap).toCharacterArray());
1✔
940
        } else if (mapClass.equals(IntervalDoubleMap.class)) {
1✔
941
            serialize(out, ((IntervalDoubleMap) intervalMap).toDoubleArray());
1✔
942
        } else if (mapClass.equals(IntervalFloatMap.class)) {
1✔
943
            serialize(out, ((IntervalFloatMap) intervalMap).toFloatArray());
1✔
944
        } else if (mapClass.equals(IntervalIntegerMap.class)) {
1✔
945
            serialize(out, ((IntervalIntegerMap) intervalMap).toIntegerArray());
1✔
946
        } else if (mapClass.equals(IntervalLongMap.class)) {
1✔
947
            serialize(out, ((IntervalLongMap) intervalMap).toLongArray());
1✔
948
        } else if (mapClass.equals(IntervalShortMap.class)) {
1✔
949
            serialize(out, ((IntervalShortMap) intervalMap).toShortArray());
1✔
950
        } else if (mapClass.equals(IntervalStringMap.class)) {
1✔
951
            serialize(out, intervalMap.toValuesArray());
1✔
952
        } else {
1✔
953
            throw new RuntimeException("Unrecognized interval map class");
1✔
954
        }
955
    }
×
956

957
    private IntervalMap deserializeIntervalMap(final DataInput is) throws IOException, ClassNotFoundException {
1✔
958
        double[] intervals = (double[]) deserialize(is);
959
        Object values = deserialize(is);
960

1✔
961
        Class mapClass = values.getClass();
1✔
962
        IntervalMap valueSet;
963
        if (mapClass.equals(boolean[].class)) {
1✔
964
            valueSet = new IntervalBooleanMap(intervals, (boolean[]) values);
965
        } else if (mapClass.equals(byte[].class)) {
1✔
966
            valueSet = new IntervalByteMap(intervals, (byte[]) values);
1✔
967
        } else if (mapClass.equals(char[].class)) {
1✔
968
            valueSet = new IntervalCharMap(intervals, (char[]) values);
1✔
969
        } else if (mapClass.equals(double[].class)) {
1✔
970
            valueSet = new IntervalDoubleMap(intervals, (double[]) values);
1✔
971
        } else if (mapClass.equals(float[].class)) {
1✔
972
            valueSet = new IntervalFloatMap(intervals, (float[]) values);
1✔
973
        } else if (mapClass.equals(int[].class)) {
1✔
974
            valueSet = new IntervalIntegerMap(intervals, (int[]) values);
1✔
975
        } else if (mapClass.equals(long[].class)) {
1✔
976
            valueSet = new IntervalLongMap(intervals, (long[]) values);
1✔
977
        } else if (mapClass.equals(short[].class)) {
1✔
978
            valueSet = new IntervalShortMap(intervals, (short[]) values);
1✔
979
        } else if (mapClass.equals(String[].class)) {
1✔
980
            valueSet = new IntervalStringMap(intervals, (String[]) values);
1✔
981
        } else {
1✔
982
            throw new RuntimeException("Unrecognized interval map class");
1✔
983
        }
984
        return valueSet;
×
985
    }
986

1✔
987
    private void serializeTimestampIndexStore(final DataOutput out, final TimestampIndexStore timestampIndexStore) throws IOException {
988
        serialize(out, timestampIndexStore.elementType);
989

990
        serialize(out, timestampIndexStore.length);
1✔
991
        serialize(out, timestampIndexStore.getMap().keySet().toDoubleArray());
992
        serialize(out, timestampIndexStore.getMap().values().toIntArray());
1✔
993
        serialize(out, timestampIndexStore.garbageQueue.toIntArray());
1✔
994
        serialize(out, timestampIndexStore.countMap);
1✔
995
    }
1✔
996

1✔
997
    private TimestampIndexStore deserializeTimestampIndexStore(final DataInput is) throws IOException, ClassNotFoundException {
1✔
998
        TimestampIndexStore timestampIndexStore;
999

1000
        Class cls = (Class) deserialize(is);
1001
        if (cls.equals(Node.class)) {
1002
            timestampIndexStore = (TimestampIndexStore) model.store.timeStore.nodeIndexStore;
1✔
1003
        } else {
1✔
1004
            timestampIndexStore = (TimestampIndexStore) model.store.timeStore.edgeIndexStore;
1✔
1005
        }
1006

1✔
1007
        int length = (Integer) deserialize(is);
1008
        double[] doubles = (double[]) deserialize(is);
1009
        int[] ints = (int[]) deserialize(is);
1✔
1010
        int[] garbage = (int[]) deserialize(is);
1✔
1011
        int[] counts = (int[]) deserialize(is);
1✔
1012

1✔
1013
        timestampIndexStore.length = length;
1✔
1014
        for (int i : garbage) {
1015
            timestampIndexStore.garbageQueue.add(i);
1✔
1016
        }
1✔
1017
        Double2IntMap m = timestampIndexStore.getMap();
1✔
1018
        for (int i = 0; i < ints.length; i++) {
1019
            m.put(doubles[i], ints[i]);
1✔
1020
        }
1✔
1021
        timestampIndexStore.countMap = counts;
1✔
1022
        return timestampIndexStore;
1023
    }
1✔
1024

1✔
1025
    private void serializeIntervalIndexStore(final DataOutput out, final IntervalIndexStore intervalIndexStore) throws IOException {
1026
        serialize(out, intervalIndexStore.elementType);
1027

1028
        serialize(out, intervalIndexStore.length);
1✔
1029
        serialize(out, intervalIndexStore.getMap().size());
1030
        for (Map.Entry<Interval, Integer> entry : intervalIndexStore.getMap().entrySet()) {
1✔
1031
            serialize(out, entry.getKey());
1✔
1032
            serialize(out, entry.getValue());
1✔
1033
        }
1✔
1034
        serialize(out, intervalIndexStore.garbageQueue.toIntArray());
1✔
1035
        serialize(out, intervalIndexStore.countMap);
1✔
1036
    }
1✔
1037

1✔
1038
    private IntervalIndexStore deserializeIntervalIndexStore(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1039
        IntervalIndexStore intervalIndexStore;
1040

1041
        Class cls = (Class) deserialize(is);
1042
        if (cls.equals(Node.class)) {
1043
            intervalIndexStore = (IntervalIndexStore) model.store.timeStore.nodeIndexStore;
1✔
1044
        } else {
1✔
1045
            intervalIndexStore = (IntervalIndexStore) model.store.timeStore.edgeIndexStore;
1✔
1046
        }
1047

1✔
1048
        int length = (Integer) deserialize(is);
1049
        int mapSize = (Integer) deserialize(is);
1050

1✔
1051
        Interval2IntTreeMap map = intervalIndexStore.getMap();
1✔
1052
        for (int i = 0; i < mapSize; i++) {
1053
            Interval key = (Interval) deserialize(is);
1✔
1054
            Integer value = (Integer) deserialize(is);
1✔
1055
            map.put(key, value);
1✔
1056
        }
1✔
1057
        int[] garbage = (int[]) deserialize(is);
1✔
1058
        int[] counts = (int[]) deserialize(is);
1059

1✔
1060
        intervalIndexStore.length = length;
1✔
1061
        for (int i : garbage) {
1062
            intervalIndexStore.garbageQueue.add(i);
1✔
1063
        }
1✔
1064
        intervalIndexStore.countMap = counts;
1✔
1065
        return intervalIndexStore;
1066
    }
1✔
1067

1✔
1068
    private void serializeInstant(final DataOutput out, final Instant instant) throws IOException {
1069
        serialize(out, instant.getEpochSecond());
1070
        serialize(out, instant.getNano());
1071
    }
1✔
1072

1✔
1073
    private Instant deserializeInstant(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1074
        long epochSecond = (long) deserialize(is);
1075
        int nano = (int) deserialize(is);
1076
        return Instant.ofEpochSecond(epochSecond, nano);
1✔
1077
    }
1✔
1078

1✔
1079
    private void serializeGraphAttributes(final DataOutput out, final GraphAttributesImpl graphAttributes) throws IOException {
1080
        serialize(out, graphAttributes.attributes.size());
1081
        for (Map.Entry<String, Object> entry : graphAttributes.attributes.entrySet()) {
1082
            serialize(out, entry.getKey());
1✔
1083
            serialize(out, entry.getValue());
1✔
1084
        }
1✔
1085
    }
1✔
1086

1✔
1087
    private GraphAttributesImpl deserializeGraphAttributes(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1088
        GraphAttributesImpl attributes = new GraphAttributesImpl();
1089
        int size = (Integer) deserialize(is);
1090
        for (int i = 0; i < size; i++) {
1✔
1091
            String key = (String) deserialize(is);
1✔
1092
            Object value = deserialize(is);
1✔
1093
            attributes.attributes.put(key, value);
1✔
1094
        }
1✔
1095
        return attributes;
1✔
1096
    }
1097

1✔
1098
    private void serializeTimeFormat(final DataOutput out, final TimeFormat timeFormat) throws IOException {
1099
        serialize(out, timeFormat.name());
1100
    }
1101

1✔
1102
    private TimeFormat deserializeTimeFormat(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1103
        String name = (String) deserialize(is);
1104

1105
        TimeFormat tf = TimeFormat.valueOf(name);
1✔
1106
        model.store.timeFormat = tf;
1107

1✔
1108
        return tf;
1✔
1109
    }
1110

1✔
1111
    private void serializeTimeZone(final DataOutput out, final ZoneId timeZone) throws IOException {
1112
        serialize(out, timeZone.getId());
1113
    }
1114

1✔
1115
    private ZoneId deserializeTimeZone(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1116
        String id = (String) deserialize(is);
1117

1118
        ZoneId tz = ZoneId.of(id);
1✔
1119
        model.store.timeZone = tz;
1120

1✔
1121
        return tz;
1✔
1122
    }
1123

1✔
1124
    private void serializeTimeStore(final DataOutput out) throws IOException {
1125
        TimeStore timeStore = model.store.timeStore;
1126

1127
        serialize(out, timeStore.nodeIndexStore);
1✔
1128
        serialize(out, timeStore.edgeIndexStore);
1129
    }
1✔
1130

1✔
1131
    private void serializeInterval(final DataOutput out, final Interval interval) throws IOException {
1✔
1132
        serialize(out, interval.getLow());
1133
        serialize(out, interval.getHigh());
1134
    }
1✔
1135

1✔
1136
    private Interval deserializeInterval(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1137
        double start = (Double) deserialize(is);
1138
        double end = (Double) deserialize(is);
1139
        return new Interval(start, end);
1✔
1140
    }
1✔
1141

1✔
1142
    private TimeStore deserializeTimeStore(final DataInput is) throws IOException, ClassNotFoundException {
1143
        TimeStore timeStore = model.store.timeStore;
1144

1145
        deserialize(is);
1✔
1146
        deserialize(is);
1147

1✔
1148
        return timeStore;
1✔
1149
    }
1150

1✔
1151
    private void serializeConfiguration(final DataOutput out) throws IOException {
1152
        ConfigurationImpl config = model.configuration;
1153

1154
        serialize(out, config.getNodeIdType());
1✔
1155
        serialize(out, config.getEdgeIdType());
1156
        serialize(out, config.getEdgeLabelType());
1✔
1157
        serialize(out, config.getEdgeWeightType());
1✔
1158
        serialize(out, config.getTimeRepresentation());
1✔
1159
        serialize(out, config.isEdgeWeightColumn());
1✔
1160
    }
1✔
1161

1✔
1162
    private ConfigurationImpl deserializeConfiguration(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1163
        Configuration.Builder config = Configuration.builder();
1164

1165
        Class nodeIdType = (Class) deserialize(is);
1✔
1166
        Class edgeIdType = (Class) deserialize(is);
1167
        Class edgeLabelType = (Class) deserialize(is);
1✔
1168
        Class edgeWeightType = (Class) deserialize(is);
1✔
1169
        TimeRepresentation timeRepresentation = (TimeRepresentation) deserialize(is);
1✔
1170

1✔
1171
        config.nodeIdType(nodeIdType);
1✔
1172
        config.edgeIdType(edgeIdType);
1173
        config.edgeLabelType(edgeLabelType);
1✔
1174
        config.edgeWeightType(edgeWeightType);
1✔
1175
        config.timeRepresentation(timeRepresentation);
1✔
1176
        if (readVersion >= 0.5) {
1✔
1177
            Boolean edgeColumn = (Boolean) deserialize(is);
1✔
1178
            config.edgeWeightColumn(edgeColumn);
1✔
1179
        }
1✔
1180

1✔
1181
        return new ConfigurationImpl(config.build());
1182
    }
1183

1✔
1184
    private void serializeList(final DataOutput out, final List list) throws IOException {
1185
        Class oCls = list.getClass();
1186
        if (oCls.equals(IntArrayList.class)) {
1187
            serialize(out, ((IntArrayList) list).toIntArray());
1✔
1188
        } else if (oCls.equals(FloatArrayList.class)) {
1✔
1189
            serialize(out, ((FloatArrayList) list).toFloatArray());
1✔
1190
        } else if (oCls.equals(DoubleArrayList.class)) {
1✔
1191
            serialize(out, ((DoubleArrayList) list).toDoubleArray());
1✔
1192
        } else if (oCls.equals(ShortArrayList.class)) {
1✔
1193
            serialize(out, ((ShortArrayList) list).toShortArray());
1✔
1194
        } else if (oCls.equals(ByteArrayList.class)) {
1✔
1195
            serialize(out, ((ByteArrayList) list).toByteArray());
1✔
1196
        } else if (oCls.equals(LongArrayList.class)) {
1✔
1197
            serialize(out, ((LongArrayList) list).toLongArray());
1✔
1198
        } else if (oCls.equals(BooleanArrayList.class)) {
1✔
1199
            serialize(out, ((BooleanArrayList) list).toBooleanArray());
1✔
1200
        } else if (oCls.equals(CharArrayList.class)) {
1✔
1201
            serialize(out, ((CharArrayList) list).toCharArray());
1✔
1202
        } else {
1✔
1203
            serialize(out, list.size());
1✔
1204
            for (Object obj : list) {
1205
                serialize(out, obj);
1✔
1206
            }
1✔
1207
        }
1✔
1208
    }
1✔
1209

1210
    private List deserializeList(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1211
        Object h = deserialize(is);
1212
        Class oCls = h.getClass();
1213
        if (oCls.equals(Integer.class)) {
1✔
1214
            int size = (Integer) h;
1✔
1215
            ObjectArrayList list = new ObjectArrayList(size);
1✔
1216
            for (int i = 0; i < size; i++) {
1✔
1217
                list.add(deserialize(is));
1✔
1218
            }
1✔
1219
            return list;
1✔
1220
        } else if (oCls.equals(int[].class)) {
1221
            return new IntArrayList((int[]) h);
1✔
1222
        } else if (oCls.equals(float[].class)) {
1✔
1223
            return new FloatArrayList((float[]) h);
1✔
1224
        } else if (oCls.equals(double[].class)) {
1✔
1225
            return new DoubleArrayList((double[]) h);
1✔
1226
        } else if (oCls.equals(short[].class)) {
1✔
1227
            return new ShortArrayList((short[]) h);
1✔
1228
        } else if (oCls.equals(byte[].class)) {
1✔
1229
            return new ByteArrayList((byte[]) h);
1✔
1230
        } else if (oCls.equals(long[].class)) {
1✔
1231
            return new LongArrayList((long[]) h);
1✔
1232
        } else if (oCls.equals(boolean[].class)) {
1✔
1233
            return new BooleanArrayList((boolean[]) h);
1✔
1234
        } else if (oCls.equals(char[].class)) {
1✔
1235
            return new CharArrayList((char[]) h);
1✔
1236
        }
1✔
1237
        throw new EOFException();
1✔
1238
    }
1239

×
1240
    private void serializeSet(final DataOutput out, final Set set) throws IOException {
1241
        Class oCls = set.getClass();
1242
        if (oCls.equals(IntOpenHashSet.class)) {
1243
            serialize(out, ((IntOpenHashSet) set).toIntArray());
1✔
1244
        } else if (oCls.equals(FloatOpenHashSet.class)) {
1✔
1245
            serialize(out, ((FloatOpenHashSet) set).toFloatArray());
1✔
1246
        } else if (oCls.equals(DoubleOpenHashSet.class)) {
1✔
1247
            serialize(out, ((DoubleOpenHashSet) set).toDoubleArray());
1✔
1248
        } else if (oCls.equals(ShortOpenHashSet.class)) {
1✔
1249
            serialize(out, ((ShortOpenHashSet) set).toShortArray());
1✔
1250
        } else if (oCls.equals(ByteOpenHashSet.class)) {
1✔
1251
            serialize(out, ((ByteOpenHashSet) set).toByteArray());
1✔
1252
        } else if (oCls.equals(LongOpenHashSet.class)) {
1✔
1253
            serialize(out, ((LongOpenHashSet) set).toLongArray());
1✔
1254
        } else if (oCls.equals(BooleanOpenHashSet.class)) {
1✔
1255
            serialize(out, ((BooleanOpenHashSet) set).toBooleanArray());
1✔
1256
        } else if (oCls.equals(CharOpenHashSet.class)) {
1✔
1257
            serialize(out, ((CharOpenHashSet) set).toCharArray());
1✔
1258
        } else {
1✔
1259
            serialize(out, set.size());
1✔
1260
            for (Object obj : set) {
1261
                serialize(out, obj);
1✔
1262
            }
1✔
1263
        }
1✔
1264
    }
1✔
1265

1266
    private Set deserializeSet(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1267
        Object h = deserialize(is);
1268
        Class oCls = h.getClass();
1269
        if (oCls.equals(Integer.class)) {
1✔
1270
            int size = (Integer) h;
1✔
1271
            ObjectOpenHashSet set = new ObjectOpenHashSet(size);
1✔
1272
            for (int i = 0; i < size; i++) {
1✔
1273
                set.add(deserialize(is));
1✔
1274
            }
1✔
1275
            return set;
1✔
1276
        } else if (oCls.equals(int[].class)) {
1277
            return new IntOpenHashSet((int[]) h);
1✔
1278
        } else if (oCls.equals(float[].class)) {
1✔
1279
            return new FloatOpenHashSet((float[]) h);
1✔
1280
        } else if (oCls.equals(double[].class)) {
1✔
1281
            return new DoubleOpenHashSet((double[]) h);
1✔
1282
        } else if (oCls.equals(short[].class)) {
1✔
1283
            return new ShortOpenHashSet((short[]) h);
1✔
1284
        } else if (oCls.equals(byte[].class)) {
1✔
1285
            return new ByteOpenHashSet((byte[]) h);
1✔
1286
        } else if (oCls.equals(long[].class)) {
1✔
1287
            return new LongOpenHashSet((long[]) h);
1✔
1288
        } else if (oCls.equals(boolean[].class)) {
1✔
1289
            return new BooleanOpenHashSet((boolean[]) h);
1✔
1290
        } else if (oCls.equals(char[].class)) {
1✔
1291
            return new CharOpenHashSet((char[]) h);
1✔
1292
        }
1✔
1293
        throw new EOFException();
1✔
1294
    }
1295

×
1296
    private void serializeMap(final DataOutput out, final Map map) throws IOException {
1297
        Class oCls = map.getClass();
1298
        if (oCls.equals(Int2ObjectOpenHashMap.class)) {
1299
            serialize(out, ((Int2ObjectOpenHashMap) map).keySet().toIntArray());
1✔
1300
            serialize(out, map.values().toArray());
1✔
1301
        } else if (oCls.equals(Float2ObjectOpenHashMap.class)) {
1✔
1302
            serialize(out, ((Float2ObjectOpenHashMap) map).keySet().toFloatArray());
1✔
1303
            serialize(out, map.values().toArray());
1✔
1304
        } else if (oCls.equals(Double2ObjectOpenHashMap.class)) {
1✔
1305
            serialize(out, ((Double2ObjectOpenHashMap) map).keySet().toDoubleArray());
1✔
1306
            serialize(out, map.values().toArray());
1✔
1307
        } else if (oCls.equals(Short2ObjectOpenHashMap.class)) {
1✔
1308
            serialize(out, ((Short2ObjectOpenHashMap) map).keySet().toShortArray());
1✔
1309
            serialize(out, map.values().toArray());
1✔
1310
        } else if (oCls.equals(Long2ObjectOpenHashMap.class)) {
1✔
1311
            serialize(out, ((Long2ObjectOpenHashMap) map).keySet().toLongArray());
1✔
1312
            serialize(out, map.values().toArray());
1✔
1313
        } else if (oCls.equals(Byte2ObjectOpenHashMap.class)) {
1✔
1314
            serialize(out, ((Byte2ObjectOpenHashMap) map).keySet().toByteArray());
1✔
1315
            serialize(out, map.values().toArray());
1✔
1316
        } else if (oCls.equals(Char2ObjectOpenHashMap.class)) {
1✔
1317
            serialize(out, ((Char2ObjectOpenHashMap) map).keySet().toCharArray());
1✔
1318
            serialize(out, map.values().toArray());
1✔
1319
        } else {
1✔
1320
            serialize(out, map.size());
1✔
1321

1322
            Set<Map.Entry<Object, Object>> entrySet = map.entrySet();
1✔
1323
            for (Map.Entry entry : entrySet) {
1324
                serialize(out, entry.getKey());
1✔
1325
                serialize(out, entry.getValue());
1✔
1326
            }
1✔
1327
        }
1✔
1328
    }
1✔
1329

1330
    private Map deserializeMap(final DataInput is) throws IOException, ClassNotFoundException {
1✔
1331
        Object h = deserialize(is);
1332
        Class oCls = h.getClass();
1333
        if (oCls.equals(Integer.class)) {
1✔
1334
            int size = (Integer) h;
1✔
1335
            Object2ObjectOpenHashMap set = new Object2ObjectOpenHashMap(size);
1✔
1336
            for (int i = 0; i < size; i++) {
1✔
1337
                set.put(deserialize(is), deserialize(is));
1✔
1338
            }
1✔
1339
            return set;
1✔
1340
        } else if (oCls.equals(int[].class)) {
1341
            return new Int2ObjectOpenHashMap((int[]) h, (Object[]) deserialize(is));
1✔
1342
        } else if (oCls.equals(float[].class)) {
1✔
1343
            return new Float2ObjectOpenHashMap((float[]) h, (Object[]) deserialize(is));
1✔
1344
        } else if (oCls.equals(double[].class)) {
1✔
1345
            return new Double2ObjectOpenHashMap((double[]) h, (Object[]) deserialize(is));
1✔
1346
        } else if (oCls.equals(short[].class)) {
1✔
1347
            return new Short2ObjectOpenHashMap((short[]) h, (Object[]) deserialize(is));
1✔
1348
        } else if (oCls.equals(byte[].class)) {
1✔
1349
            return new Byte2ObjectOpenHashMap((byte[]) h, (Object[]) deserialize(is));
1✔
1350
        } else if (oCls.equals(long[].class)) {
1✔
1351
            return new Long2ObjectOpenHashMap((long[]) h, (Object[]) deserialize(is));
1✔
1352
        } else if (oCls.equals(char[].class)) {
1✔
1353
            return new Char2ObjectOpenHashMap((char[]) h, (Object[]) deserialize(is));
1✔
1354
        }
1✔
1355
        throw new EOFException();
1✔
1356
    }
1357

×
1358
    // SERIALIZE PRIMITIVES
1359
    protected byte[] serialize(Object obj) throws IOException {
1360
        DataInputOutput ba = new DataInputOutput();
1361

1362
        serialize(ba, obj);
1✔
1363

1364
        return ba.toByteArray();
1✔
1365
    }
1366

1✔
1367
    protected void serialize(final DataOutput out, final Object obj) throws IOException {
1368
        final Class clazz = obj != null ? obj.getClass() : null;
1369

1370
        if (obj == null) {
1✔
1371
            out.write(NULL);
1372

1✔
1373
        } else if (clazz == Boolean.class) {
1✔
1374
            if (((Boolean) obj)) {
1375
                out.write(BOOLEAN_TRUE);
1✔
1376
            } else {
1✔
1377
                out.write(BOOLEAN_FALSE);
1✔
1378

1379
            }
1✔
1380
        } else if (clazz == Integer.class) {
1381
            final int val = (Integer) obj;
1382
            writeInteger(out, val);
1✔
1383

1✔
1384
        } else if (clazz == Double.class) {
1✔
1385
            double v = (Double) obj;
1386
            if (v == -1d) {
1✔
1387
                out.write(DOUBLE_MINUS_1);
1✔
1388
            } else if (v == 0d) {
1✔
1389
                out.write(DOUBLE_0);
1✔
1390
            } else if (v == 1d) {
1✔
1391
                out.write(DOUBLE_1);
1✔
1392
            } else if (v >= 0 && v <= 255 && (int) v == v) {
1✔
1393
                out.write(DOUBLE_255);
1✔
1394
                out.write((int) v);
1✔
1395
            } else if (v >= Short.MIN_VALUE && v <= Short.MAX_VALUE && (short) v == v) {
1✔
1396
                out.write(DOUBLE_SHORT);
1✔
1397
                out.writeShort((int) v);
1✔
1398
            } else {
1✔
1399
                out.write(DOUBLE_FULL);
1✔
1400
                out.writeDouble(v);
1401

1✔
1402
            }
1✔
1403
        } else if (clazz == Float.class) {
1404
            float v = (Float) obj;
1405
            if (v == -1f) {
1✔
1406
                out.write(FLOAT_MINUS_1);
1✔
1407
            } else if (v == 0f) {
1✔
1408
                out.write(FLOAT_0);
1✔
1409
            } else if (v == 1f) {
1✔
1410
                out.write(FLOAT_1);
1✔
1411
            } else if (v >= 0 && v <= 255 && (int) v == v) {
1✔
1412
                out.write(FLOAT_255);
1✔
1413
                out.write((int) v);
1✔
1414
            } else if (v >= Short.MIN_VALUE && v <= Short.MAX_VALUE && (short) v == v) {
1✔
1415
                out.write(FLOAT_SHORT);
1✔
1416
                out.writeShort((int) v);
1✔
1417

1✔
1418
            } else {
1✔
1419
                out.write(FLOAT_FULL);
1420
                out.writeFloat(v);
1421

1✔
1422
            }
1✔
1423
        } else if (clazz == Long.class) {
1424
            final long val = (Long) obj;
1425
            writeLong(out, val);
1✔
1426

1✔
1427
        } else if (clazz == BigInteger.class) {
1✔
1428
            out.write(BIGINTEGER);
1429
            byte[] buf = ((BigInteger) obj).toByteArray();
1✔
1430
            serializeByteArrayInt(out, buf);
1✔
1431

1✔
1432
        } else if (clazz == BigDecimal.class) {
1✔
1433
            out.write(BIGDECIMAL);
1434
            BigDecimal d = (BigDecimal) obj;
1✔
1435
            serializeByteArrayInt(out, d.unscaledValue().toByteArray());
1✔
1436
            LongPacker.packInt(out, d.scale());
1✔
1437

1✔
1438
        } else if (clazz == Short.class) {
1✔
1439
            short val = (Short) obj;
1440
            if (val == -1) {
1✔
1441
                out.write(SHORT_MINUS_1);
1✔
1442
            } else if (val == 0) {
1✔
1443
                out.write(SHORT_0);
1✔
1444
            } else if (val == 1) {
1✔
1445
                out.write(SHORT_1);
1✔
1446
            } else if (val > 0 && val < 255) {
1✔
1447
                out.write(SHORT_255);
1✔
1448
                out.write(val);
1✔
1449
            } else {
1✔
1450
                out.write(SHORT_FULL);
1✔
1451
                out.writeShort(val);
1452

1✔
1453
            }
1✔
1454
        } else if (clazz == Byte.class) {
1455
            byte val = (Byte) obj;
1456
            if (val == -1) {
1✔
1457
                out.write(BYTE_MINUS_1);
1✔
1458
            } else if (val == 0) {
1✔
1459
                out.write(BYTE_0);
1✔
1460
            } else if (val == 1) {
1✔
1461
                out.write(BYTE_1);
1✔
1462
            } else {
1✔
1463
                out.write(BYTE_FULL);
1✔
1464
                out.writeByte(val);
1465

1✔
1466
            }
1✔
1467
        } else if (clazz == Character.class) {
1468
            out.write(CHAR);
1469
            out.writeChar((Character) obj);
1✔
1470

1✔
1471
        } else if (clazz == String.class) {
1✔
1472
            String s = (String) obj;
1473
            if (s.length() == 0) {
1✔
1474
                out.write(STRING_EMPTY);
1✔
1475
            } else {
1✔
1476
                out.write(STRING);
1✔
1477
                serializeString(out, s);
1478
            }
1✔
1479
        } else if (obj instanceof Class) {
1✔
1480
            out.write(CLASS);
1481
            serialize(out, ((Class) obj).getName());
1✔
1482
        } else if (obj instanceof int[]) {
1✔
1483
            writeIntArray(out, (int[]) obj);
1✔
1484
        } else if (obj instanceof long[]) {
1✔
1485
            writeLongArray(out, (long[]) obj);
1✔
1486
        } else if (obj instanceof short[]) {
1✔
1487
            out.write(SHORT_ARRAY);
1✔
1488
            short[] a = (short[]) obj;
1✔
1489
            LongPacker.packInt(out, a.length);
1✔
1490
            for (short s : a) {
1✔
1491
                out.writeShort(s);
1✔
1492
            }
1✔
1493
        } else if (obj instanceof boolean[]) {
1✔
1494
            out.write(BOOLEAN_ARRAY);
1495
            boolean[] a = (boolean[]) obj;
1✔
1496
            LongPacker.packInt(out, a.length);
1✔
1497
            for (boolean s : a) {
1✔
1498
                out.writeBoolean(s); // TODO pack 8 booleans to single byte
1✔
1499
            }
1✔
1500
        } else if (obj instanceof double[]) {
1✔
1501
            out.write(DOUBLE_ARRAY);
1502
            double[] a = (double[]) obj;
1✔
1503
            LongPacker.packInt(out, a.length);
1✔
1504
            for (double s : a) {
1✔
1505
                out.writeDouble(s);
1✔
1506
            }
1✔
1507
        } else if (obj instanceof float[]) {
1✔
1508
            out.write(FLOAT_ARRAY);
1509
            float[] a = (float[]) obj;
1✔
1510
            LongPacker.packInt(out, a.length);
1✔
1511
            for (float s : a) {
1✔
1512
                out.writeFloat(s);
1✔
1513
            }
1✔
1514
        } else if (obj instanceof char[]) {
1✔
1515
            out.write(CHAR_ARRAY);
1516
            char[] a = (char[]) obj;
1✔
1517
            LongPacker.packInt(out, a.length);
1✔
1518
            for (char s : a) {
1✔
1519
                out.writeChar(s);
1✔
1520
            }
1✔
1521
        } else if (obj instanceof byte[]) {
1✔
1522
            byte[] b = (byte[]) obj;
1523
            out.write(ARRAY_BYTE_INT);
1✔
1524
            serializeByteArrayInt(out, b);
1✔
1525

1✔
1526
        } else if (clazz == Date.class) {
1✔
1527
            out.write(DATE);
1528
            out.writeLong(((Date) obj).getTime());
1✔
1529

1✔
1530
        } else if (clazz == Locale.class) {
1✔
1531
            out.write(LOCALE);
1532
            Locale l = (Locale) obj;
1✔
1533
            out.writeUTF(l.getLanguage());
1✔
1534
            out.writeUTF(l.getCountry());
1✔
1535
            out.writeUTF(l.getVariant());
1✔
1536
        } else if (obj instanceof String[]) {
1✔
1537
            String[] b = (String[]) obj;
1✔
1538
            out.write(STRING_ARRAY);
1✔
1539
            LongPacker.packInt(out, b.length);
1✔
1540
            for (String s : b) {
1✔
1541
                serializeString(out, s);
1✔
1542
            }
1✔
1543
        } else if (obj instanceof Object[]) {
1✔
1544
            Object[] b = (Object[]) obj;
1545
            out.write(ARRAY_OBJECT);
1✔
1546
            LongPacker.packInt(out, b.length);
1✔
1547
            for (Object o : b) {
1✔
1548
                serialize(out, o);
1✔
1549
            }
1✔
1550
        } else if (obj instanceof TimestampSet) {
1✔
1551
            TimestampSet b = (TimestampSet) obj;
1552
            out.write(TIMESTAMP_SET);
1✔
1553
            serializeTimestampSet(out, b);
1✔
1554
        } else if (obj instanceof IntervalSet) {
1✔
1555
            IntervalSet b = (IntervalSet) obj;
1✔
1556
            out.write(INTERVAL_SET);
1✔
1557
            serializeIntervalSet(out, b);
1✔
1558
        } else if (obj instanceof NodeImpl) {
1✔
1559
            NodeImpl b = (NodeImpl) obj;
1✔
1560
            out.write(NODE);
1✔
1561
            serializeNode(out, b);
1✔
1562
        } else if (obj instanceof EdgeImpl) {
1✔
1563
            EdgeImpl b = (EdgeImpl) obj;
1✔
1564
            out.write(EDGE);
1✔
1565
            serializeEdge(out, b);
1✔
1566
        } else if (obj instanceof EdgeTypeStore) {
1✔
1567
            EdgeTypeStore b = (EdgeTypeStore) obj;
1✔
1568
            out.write(EDGETYPE_STORE);
1✔
1569
            serializeEdgeTypeStore(out);
1✔
1570
        } else if (obj instanceof Origin) {
1✔
1571
            Origin b = (Origin) obj;
1✔
1572
            out.write(COLUMN_ORIGIN);
1✔
1573
            serialize(out, b.name());
1✔
1574
        } else if (obj instanceof TableImpl) {
1✔
1575
            TableImpl b = (TableImpl) obj;
1✔
1576
            out.write(TABLE);
1✔
1577
            serializeTable(out, b);
1✔
1578
        } else if (obj instanceof GraphStore) {
1✔
1579
            GraphStore b = (GraphStore) obj;
1✔
1580
            out.write(GRAPH_STORE);
1✔
1581
            serializeGraphStore(out, b);
1✔
1582
        } else if (obj instanceof GraphFactoryImpl) {
1✔
1583
            GraphFactoryImpl b = (GraphFactoryImpl) obj;
1✔
1584
            out.write(GRAPH_FACTORY);
1✔
1585
            serializeGraphFactory(out);
1✔
1586
        } else if (obj instanceof GraphViewStore) {
1✔
1587
            GraphViewStore b = (GraphViewStore) obj;
1✔
1588
            out.write(GRAPH_VIEW_STORE);
1✔
1589
            serializeViewStore(out);
1✔
1590
        } else if (obj instanceof GraphViewImpl) {
1✔
1591
            GraphViewImpl b = (GraphViewImpl) obj;
1✔
1592
            out.write(GRAPH_VIEW);
1✔
1593
            serializeGraphView(out, b);
1✔
1594
        } else if (obj instanceof BitSet) {
1✔
1595
            BitSet bs = (BitSet) obj;
1✔
1596
            out.write(BIT_VECTOR);
1✔
1597
            serializeBitSet(out, bs);
1✔
1598
        } else if (obj instanceof GraphVersion) {
1✔
1599
            GraphVersion b = (GraphVersion) obj;
1✔
1600
            out.write(GRAPH_VERSION);
1✔
1601
            serializeGraphVersion(out, b);
1✔
1602
        } else if (obj instanceof NodePropertiesImpl) {
1✔
1603
            NodePropertiesImpl b = (NodePropertiesImpl) obj;
1✔
1604
            out.write(NODE_PROPERTIES);
1✔
1605
            serializeNodeProperties(out, b);
1✔
1606
        } else if (obj instanceof EdgePropertiesImpl) {
1✔
1607
            EdgePropertiesImpl b = (EdgePropertiesImpl) obj;
1✔
1608
            out.write(EDGE_PROPERTIES);
1✔
1609
            serializeEdgeProperties(out, b);
1✔
1610
        } else if (obj instanceof TextPropertiesImpl) {
1✔
1611
            TextPropertiesImpl b = (TextPropertiesImpl) obj;
1✔
1612
            out.write(TEXT_PROPERTIES);
1✔
1613
            serializeTextProperties(out, b);
1✔
1614
        } else if (obj instanceof Estimator) {
1✔
1615
            Estimator b = (Estimator) obj;
1✔
1616
            out.write(ESTIMATOR);
1✔
1617
            serializeString(out, b.name());
1✔
1618
        } else if (obj instanceof TimeRepresentation) {
1✔
1619
            TimeRepresentation b = (TimeRepresentation) obj;
1✔
1620
            out.write(TIME_REPRESENTATION);
1✔
1621
            serializeString(out, b.name());
1✔
1622
        } else if (obj instanceof TimestampMap) {
1✔
1623
            TimestampMap b = (TimestampMap) obj;
1✔
1624
            out.write(TIMESTAMP_MAP);
1✔
1625
            serializeTimestampMap(out, b);
1✔
1626
        } else if (obj instanceof IntervalMap) {
1✔
1627
            IntervalMap b = (IntervalMap) obj;
1✔
1628
            out.write(INTERVAL_MAP);
1✔
1629
            serializeIntervalMap(out, b);
1✔
1630
        } else if (obj instanceof TimestampIndexStore) {
1✔
1631
            TimestampIndexStore b = (TimestampIndexStore) obj;
1✔
1632
            out.write(TIMESTAMP_INDEX_STORE);
1✔
1633
            serializeTimestampIndexStore(out, b);
1✔
1634
        } else if (obj instanceof IntervalIndexStore) {
1✔
1635
            IntervalIndexStore b = (IntervalIndexStore) obj;
1✔
1636
            out.write(INTERVAL_INDEX_STORE);
1✔
1637
            serializeIntervalIndexStore(out, b);
1✔
1638
        } else if (obj instanceof GraphAttributesImpl) {
1✔
1639
            GraphAttributesImpl b = (GraphAttributesImpl) obj;
1✔
1640
            out.write(GRAPH_ATTRIBUTES);
1✔
1641
            serializeGraphAttributes(out, b);
1✔
1642
        } else if (obj instanceof TimeFormat) {
1✔
1643
            TimeFormat b = (TimeFormat) obj;
1✔
1644
            out.write(TIME_FORMAT);
1✔
1645
            serializeTimeFormat(out, b);
1✔
1646
        } else if (obj instanceof ZoneId) {
1✔
1647
            ZoneId b = (ZoneId) obj;
1✔
1648
            out.write(TIME_ZONE);
1✔
1649
            serializeTimeZone(out, b);
1✔
1650
        } else if (obj instanceof TimeStore) {
1✔
1651
            TimeStore b = (TimeStore) obj;
1✔
1652
            out.write(TIME_STORE);
1✔
1653
            serializeTimeStore(out);
1✔
1654
        } else if (obj instanceof ConfigurationImpl) {
1✔
1655
            ConfigurationImpl b = (ConfigurationImpl) obj;
1✔
1656
            out.write(CONFIGURATION);
1✔
1657
            serializeConfiguration(out);
1✔
1658
        } else if (obj instanceof Interval) {
1✔
1659
            Interval b = (Interval) obj;
1✔
1660
            out.write(INTERVAL);
1✔
1661
            serializeInterval(out, b);
1✔
1662
        } else if (obj instanceof List) {
1✔
1663
            List b = (List) obj;
1✔
1664
            out.write(LIST);
1✔
1665
            serializeList(out, b);
1✔
1666
        } else if (obj instanceof Set) {
1✔
1667
            Set b = (Set) obj;
1✔
1668
            out.write(SET);
1✔
1669
            serializeSet(out, b);
1✔
1670
        } else if (obj instanceof Map) {
1✔
1671
            Map b = (Map) obj;
1✔
1672
            out.write(MAP);
1✔
1673
            serializeMap(out, b);
1✔
1674
        } else if (obj instanceof Instant) {
1✔
1675
            Instant i = (Instant) obj;
1✔
1676
            out.write(INSTANT);
1✔
1677
            serializeInstant(out, i);
1✔
1678
        } else {
1✔
1679
            throw new IOException("No serialization handler for this class: " + clazz.getName());
1✔
1680
        }
1✔
1681
    }
×
1682

1683
    public static void serializeString(DataOutput out, String obj) throws IOException {
1✔
1684
        final int len = obj.length();
1685
        LongPacker.packInt(out, len);
1686
        for (int i = 0; i < len; i++) {
1✔
1687
            int c = (int) obj.charAt(i); // TODO investigate if c could be
1✔
1688
            // negative here
1✔
1689
            LongPacker.packInt(out, c);
1✔
1690
        }
1691
    }
1✔
1692

1693
    private void serializeByteArrayInt(DataOutput out, byte[] b) throws IOException {
1✔
1694
        LongPacker.packInt(out, b.length);
1695
        out.write(b);
1696
    }
1✔
1697

1✔
1698
    private void writeLongArray(DataOutput da, long[] obj) throws IOException {
1✔
1699
        long max = Long.MIN_VALUE;
1700
        long min = Long.MAX_VALUE;
1701
        for (long i : obj) {
1✔
1702
            max = Math.max(max, i);
1✔
1703
            min = Math.min(min, i);
1✔
1704
        }
1✔
1705

1✔
1706
        if (0 <= min && max <= 255) {
1707
            da.write(ARRAY_LONG_B);
1708
            LongPacker.packInt(da, obj.length);
1✔
1709
            for (long l : obj) {
1✔
1710
                da.write((int) l);
1✔
1711
            }
1✔
1712
        } else if (0 <= min && max <= Long.MAX_VALUE) {
1✔
1713
            da.write(ARRAY_LONG_PACKED);
1714
            LongPacker.packInt(da, obj.length);
1✔
1715
            for (long l : obj) {
1✔
1716
                LongPacker.packLong(da, l);
1✔
1717
            }
1✔
1718
        } else if (Short.MIN_VALUE <= min && max <= Short.MAX_VALUE) {
1✔
1719
            da.write(ARRAY_LONG_S);
1720
            LongPacker.packInt(da, obj.length);
1✔
1721
            for (long l : obj) {
1✔
1722
                da.writeShort((short) l);
1✔
1723
            }
1✔
1724
        } else if (Integer.MIN_VALUE <= min && max <= Integer.MAX_VALUE) {
1✔
1725
            da.write(ARRAY_LONG_I);
1726
            LongPacker.packInt(da, obj.length);
1✔
1727
            for (long l : obj) {
1✔
1728
                da.writeInt((int) l);
1✔
1729
            }
1✔
1730
        } else {
1✔
1731
            da.write(ARRAY_LONG_L);
1732
            LongPacker.packInt(da, obj.length);
1733
            for (long l : obj) {
1✔
1734
                da.writeLong(l);
1✔
1735
            }
1✔
1736
        }
1✔
1737
    }
1738

1739
    private void writeIntArray(DataOutput da, int[] obj) throws IOException {
1✔
1740
        int max = Integer.MIN_VALUE;
1741
        int min = Integer.MAX_VALUE;
1742
        for (int i : obj) {
1✔
1743
            max = Math.max(max, i);
1✔
1744
            min = Math.min(min, i);
1✔
1745
        }
1✔
1746

1✔
1747
        boolean fitsInByte = 0 <= min && max <= 255;
1748
        boolean fitsInShort = min >= Short.MIN_VALUE && max <= Short.MAX_VALUE;
1749

1✔
1750
        if (obj.length <= 255 && fitsInByte) {
1✔
1751
            da.write(ARRAY_INT_B_255);
1752
            da.write(obj.length);
1✔
1753
            for (int i : obj) {
1✔
1754
                da.write(i);
1✔
1755
            }
1✔
1756
        } else if (fitsInByte) {
1✔
1757
            da.write(ARRAY_INT_B_INT);
1758
            LongPacker.packInt(da, obj.length);
1✔
1759
            for (int i : obj) {
1✔
1760
                da.write(i);
1✔
1761
            }
1✔
1762
        } else if (0 <= min && max <= Integer.MAX_VALUE) {
1✔
1763
            da.write(ARRAY_INT_PACKED);
1764
            LongPacker.packInt(da, obj.length);
1✔
1765
            for (int l : obj) {
1✔
1766
                LongPacker.packInt(da, l);
1✔
1767
            }
1✔
1768
        } else if (fitsInShort) {
1✔
1769
            da.write(ARRAY_INT_S);
1770
            LongPacker.packInt(da, obj.length);
1✔
1771
            for (int i : obj) {
1✔
1772
                da.writeShort(i);
1✔
1773
            }
1✔
1774
        } else {
1✔
1775
            da.write(ARRAY_INT_I);
1776
            LongPacker.packInt(da, obj.length);
1777
            for (int i : obj) {
1✔
1778
                da.writeInt(i);
1✔
1779
            }
1✔
1780
        }
1✔
1781

1782
    }
1783

1784
    private void writeInteger(DataOutput da, final int val) throws IOException {
1✔
1785
        if (val == -1) {
1786
            da.write(INTEGER_MINUS_1);
1787
        } else if (val == 0) {
1✔
1788
            da.write(INTEGER_0);
1✔
1789
        } else if (val == 1) {
1✔
1790
            da.write(INTEGER_1);
1✔
1791
        } else if (val == 2) {
1✔
1792
            da.write(INTEGER_2);
1✔
1793
        } else if (val == 3) {
1✔
1794
            da.write(INTEGER_3);
1✔
1795
        } else if (val == 4) {
1✔
1796
            da.write(INTEGER_4);
1✔
1797
        } else if (val == 5) {
1✔
1798
            da.write(INTEGER_5);
1✔
1799
        } else if (val == 6) {
1✔
1800
            da.write(INTEGER_6);
1✔
1801
        } else if (val == 7) {
1✔
1802
            da.write(INTEGER_7);
1✔
1803
        } else if (val == 8) {
1✔
1804
            da.write(INTEGER_8);
1✔
1805
        } else if (val == Integer.MIN_VALUE) {
1✔
1806
            da.write(INTEGER_MINUS_MAX);
1✔
1807
        } else if (val > 0 && val < 255) {
1✔
1808
            da.write(INTEGER_255);
1✔
1809
            da.write(val);
1✔
1810
        } else if (val < 0) {
1✔
1811
            da.write(INTEGER_PACK_NEG);
1✔
1812
            LongPacker.packInt(da, -val);
1✔
1813
        } else {
1✔
1814
            da.write(INTEGER_PACK);
1✔
1815
            LongPacker.packInt(da, val);
1816
        }
1✔
1817
    }
1✔
1818

1819
    private void writeLong(DataOutput da, final long val) throws IOException {
1✔
1820
        if (val == -1) {
1821
            da.write(LONG_MINUS_1);
1822
        } else if (val == 0) {
1✔
1823
            da.write(LONG_0);
1✔
1824
        } else if (val == 1) {
1✔
1825
            da.write(LONG_1);
1✔
1826
        } else if (val == 2) {
1✔
1827
            da.write(LONG_2);
1✔
1828
        } else if (val == 3) {
1✔
1829
            da.write(LONG_3);
1✔
1830
        } else if (val == 4) {
1✔
1831
            da.write(LONG_4);
1✔
1832
        } else if (val == 5) {
1✔
1833
            da.write(LONG_5);
1✔
1834
        } else if (val == 6) {
1✔
1835
            da.write(LONG_6);
1✔
1836
        } else if (val == 7) {
1✔
1837
            da.write(LONG_7);
1✔
1838
        } else if (val == 8) {
1✔
1839
            da.write(LONG_8);
1✔
1840
        } else if (val == Long.MIN_VALUE) {
1✔
1841
            da.write(LONG_MINUS_MAX);
1✔
1842
        } else if (val > 0 && val < 255) {
1✔
1843
            da.write(LONG_255);
1✔
1844
            da.write((int) val);
1✔
1845
        } else if (val < 0) {
1✔
1846
            da.write(LONG_PACK_NEG);
1✔
1847
            LongPacker.packLong(da, -val);
1✔
1848
        } else {
1✔
1849
            da.write(LONG_PACK);
1✔
1850
            LongPacker.packLong(da, val);
1851
        }
1✔
1852
    }
1✔
1853

1854
    // DESERIALIZE PRIMITIVES
1✔
1855
    protected Object deserialize(byte[] buf) throws ClassNotFoundException, IOException {
1856
        DataInputOutput bs = new DataInputOutput(buf);
1857
        Object ret = deserialize(bs);
1858
        if (bs.available() != 0) {
1✔
1859
            throw new RuntimeException("bytes left: " + bs.available());
1✔
1860
        }
1✔
1861

×
1862
        return ret;
1863
    }
1864

1✔
1865
    protected Object deserialize(DataInput is) throws IOException, ClassNotFoundException {
1866
        Object ret = null;
1867

1868
        final int head = is.readUnsignedByte();
1✔
1869

1870
        switch (head) {
1✔
1871
            case NULL:
1872
                break;
1✔
1873
            case BOOLEAN_TRUE:
1874
                ret = Boolean.TRUE;
1✔
1875
                break;
1876
            case BOOLEAN_FALSE:
1✔
1877
                ret = Boolean.FALSE;
1✔
1878
                break;
1879
            case INTEGER_MINUS_1:
1✔
1880
                ret = -1;
1✔
1881
                break;
1882
            case INTEGER_0:
1✔
1883
                ret = 0;
1✔
1884
                break;
1885
            case INTEGER_1:
1✔
1886
                ret = 1;
1✔
1887
                break;
1888
            case INTEGER_2:
1✔
1889
                ret = 2;
1✔
1890
                break;
1891
            case INTEGER_3:
1✔
1892
                ret = 3;
1✔
1893
                break;
1894
            case INTEGER_4:
1✔
1895
                ret = 4;
1✔
1896
                break;
1897
            case INTEGER_5:
1✔
1898
                ret = 5;
1✔
1899
                break;
1900
            case INTEGER_6:
1✔
1901
                ret = 6;
1✔
1902
                break;
1903
            case INTEGER_7:
1✔
1904
                ret = 7;
1✔
1905
                break;
1906
            case INTEGER_8:
1✔
1907
                ret = 8;
1✔
1908
                break;
1909
            case INTEGER_MINUS_MAX:
1✔
1910
                ret = Integer.MIN_VALUE;
1✔
1911
                break;
1912
            case INTEGER_255:
1✔
1913
                ret = is.readUnsignedByte();
1✔
1914
                break;
1915
            case INTEGER_PACK_NEG:
1✔
1916
                ret = -LongPacker.unpackInt(is);
1✔
1917
                break;
1918
            case INTEGER_PACK:
1✔
1919
                ret = LongPacker.unpackInt(is);
1✔
1920
                break;
1921
            case LONG_MINUS_1:
1✔
1922
                ret = Long.valueOf(-1);
1✔
1923
                break;
1924
            case LONG_0:
1✔
1925
                ret = Long.valueOf(0);
1✔
1926
                break;
1927
            case LONG_1:
1✔
1928
                ret = Long.valueOf(1);
1✔
1929
                break;
1930
            case LONG_2:
1✔
1931
                ret = Long.valueOf(2);
1✔
1932
                break;
1933
            case LONG_3:
1✔
1934
                ret = Long.valueOf(3);
1✔
1935
                break;
1936
            case LONG_4:
1✔
1937
                ret = Long.valueOf(4);
1✔
1938
                break;
1939
            case LONG_5:
1✔
1940
                ret = Long.valueOf(5);
1✔
1941
                break;
1942
            case LONG_6:
1✔
1943
                ret = Long.valueOf(6);
1✔
1944
                break;
1945
            case LONG_7:
1✔
1946
                ret = Long.valueOf(7);
1✔
1947
                break;
1948
            case LONG_8:
1✔
1949
                ret = Long.valueOf(8);
1✔
1950
                break;
1951
            case LONG_255:
1✔
1952
                ret = Long.valueOf(is.readUnsignedByte());
1✔
1953
                break;
1954
            case LONG_PACK_NEG:
1✔
1955
                ret = -LongPacker.unpackLong(is);
1✔
1956
                break;
1957
            case LONG_PACK:
1✔
1958
                ret = LongPacker.unpackLong(is);
1✔
1959
                break;
1960
            case LONG_MINUS_MAX:
1✔
1961
                ret = Long.MIN_VALUE;
1✔
1962
                break;
1963
            case SHORT_MINUS_1:
1✔
1964
                ret = ((short) -1);
1✔
1965
                break;
1966
            case SHORT_0:
1✔
1967
                ret = ((short) 0);
1✔
1968
                break;
1969
            case SHORT_1:
1✔
1970
                ret = ((short) 1);
1✔
1971
                break;
1972
            case SHORT_255:
1✔
1973
                ret = ((short) is.readUnsignedByte());
1✔
1974
                break;
1975
            case SHORT_FULL:
1✔
1976
                ret = is.readShort();
1✔
1977
                break;
1978
            case BYTE_MINUS_1:
1✔
1979
                ret = ((byte) -1);
1✔
1980
                break;
1981
            case BYTE_0:
1✔
1982
                ret = ((byte) 0);
1✔
1983
                break;
1984
            case BYTE_1:
1✔
1985
                ret = ((byte) 1);
1✔
1986
                break;
1987
            case BYTE_FULL:
1✔
1988
                ret = (is.readByte());
1✔
1989
                break;
1990
            case SHORT_ARRAY:
1✔
1991
                int size = LongPacker.unpackInt(is);
1✔
1992
                ret = new short[size];
1993
                for (int i = 0; i < size; i++) {
1✔
1994
                    ((short[]) ret)[i] = is.readShort();
1✔
1995
                }
1✔
1996
                break;
1✔
1997
            case BOOLEAN_ARRAY:
1998
                size = LongPacker.unpackInt(is);
1✔
1999
                ret = new boolean[size];
2000
                for (int i = 0; i < size; i++) {
1✔
2001
                    ((boolean[]) ret)[i] = is.readBoolean();
1✔
2002
                }
1✔
2003
                break;
1✔
2004
            case DOUBLE_ARRAY:
2005
                size = LongPacker.unpackInt(is);
1✔
2006
                ret = new double[size];
2007
                for (int i = 0; i < size; i++) {
1✔
2008
                    ((double[]) ret)[i] = is.readDouble();
1✔
2009
                }
1✔
2010
                break;
1✔
2011
            case FLOAT_ARRAY:
2012
                size = LongPacker.unpackInt(is);
1✔
2013
                ret = new float[size];
2014
                for (int i = 0; i < size; i++) {
1✔
2015
                    ((float[]) ret)[i] = is.readFloat();
1✔
2016
                }
1✔
2017
                break;
1✔
2018
            case CHAR_ARRAY:
2019
                size = LongPacker.unpackInt(is);
1✔
2020
                ret = new char[size];
2021
                for (int i = 0; i < size; i++) {
1✔
2022
                    ((char[]) ret)[i] = is.readChar();
1✔
2023
                }
1✔
2024
                break;
1✔
2025
            case CHAR:
2026
                ret = is.readChar();
1✔
2027
                break;
2028
            case FLOAT_MINUS_1:
1✔
2029
                ret = Float.valueOf(-1);
1✔
2030
                break;
2031
            case FLOAT_0:
1✔
2032
                ret = Float.valueOf(0);
1✔
2033
                break;
2034
            case FLOAT_1:
1✔
2035
                ret = Float.valueOf(1);
1✔
2036
                break;
2037
            case FLOAT_255:
1✔
2038
                ret = Float.valueOf(is.readUnsignedByte());
1✔
2039
                break;
2040
            case FLOAT_SHORT:
1✔
2041
                ret = Float.valueOf(is.readShort());
1✔
2042
                break;
2043
            case FLOAT_FULL:
1✔
2044
                ret = is.readFloat();
1✔
2045
                break;
2046
            case DOUBLE_MINUS_1:
1✔
2047
                ret = Double.valueOf(-1);
1✔
2048
                break;
2049
            case DOUBLE_0:
1✔
2050
                ret = Double.valueOf(0);
1✔
2051
                break;
2052
            case DOUBLE_1:
1✔
2053
                ret = Double.valueOf(1);
1✔
2054
                break;
2055
            case DOUBLE_255:
1✔
2056
                ret = Double.valueOf(is.readUnsignedByte());
1✔
2057
                break;
2058
            case DOUBLE_SHORT:
1✔
2059
                ret = Double.valueOf(is.readShort());
1✔
2060
                break;
2061
            case DOUBLE_FULL:
1✔
2062
                ret = is.readDouble();
1✔
2063
                break;
2064
            case BIGINTEGER:
1✔
2065
                ret = new BigInteger(deserializeArrayByteInt(is));
1✔
2066
                break;
2067
            case BIGDECIMAL:
1✔
2068
                ret = new BigDecimal(new BigInteger(deserializeArrayByteInt(is)), LongPacker.unpackInt(is));
1✔
2069
                break;
2070
            case STRING:
1✔
2071
                ret = deserializeString(is);
1✔
2072
                break;
2073
            case STRING_EMPTY:
1✔
2074
                ret = EMPTY_STRING;
1✔
2075
                break;
2076
            case CLASS:
1✔
2077
                ret = deserializeClass(is);
1✔
2078
                break;
2079
            case DATE:
1✔
2080
                ret = new Date(is.readLong());
1✔
2081
                break;
2082
            case ARRAY_INT_B_255:
1✔
2083
                ret = deserializeArrayIntB255(is);
1✔
2084
                break;
2085
            case ARRAY_INT_B_INT:
1✔
2086
                ret = deserializeArrayIntBInt(is);
1✔
2087
                break;
2088
            case ARRAY_INT_S:
1✔
2089
                ret = deserializeArrayIntSInt(is);
1✔
2090
                break;
2091
            case ARRAY_INT_I:
1✔
2092
                ret = deserializeArrayIntIInt(is);
1✔
2093
                break;
2094
            case ARRAY_INT_PACKED:
1✔
2095
                ret = deserializeArrayIntPack(is);
1✔
2096
                break;
2097
            case ARRAY_LONG_B:
1✔
2098
                ret = deserializeArrayLongB(is);
1✔
2099
                break;
2100
            case ARRAY_LONG_S:
1✔
2101
                ret = deserializeArrayLongS(is);
1✔
2102
                break;
2103
            case ARRAY_LONG_I:
1✔
2104
                ret = deserializeArrayLongI(is);
1✔
2105
                break;
2106
            case ARRAY_LONG_L:
1✔
2107
                ret = deserializeArrayLongL(is);
1✔
2108
                break;
2109
            case ARRAY_LONG_PACKED:
1✔
2110
                ret = deserializeArrayLongPack(is);
1✔
2111
                break;
2112
            case ARRAY_BYTE_INT:
1✔
2113
                ret = deserializeArrayByteInt(is);
1✔
2114
                break;
2115
            case LOCALE:
1✔
2116
                ret = new Locale(is.readUTF(), is.readUTF(), is.readUTF());
1✔
2117
                break;
2118
            case STRING_ARRAY:
1✔
2119
                ret = deserializeStringArray(is);
1✔
2120
                break;
2121
            case ARRAY_OBJECT:
1✔
2122
                ret = deserializeArrayObject(is);
1✔
2123
                break;
2124
            case TIMESTAMP_SET:
1✔
2125
                ret = deserializeTimestampSet(is);
1✔
2126
                break;
2127
            case INTERVAL_SET:
1✔
2128
                ret = deserializeIntervalSet(is);
1✔
2129
                break;
2130
            case NODE:
1✔
2131
                ret = deserializeNode(is);
1✔
2132
                break;
2133
            case EDGE:
1✔
2134
                ret = deserializeEdge(is);
1✔
2135
                break;
2136
            case EDGETYPE_STORE:
1✔
2137
                ret = deserializeEdgeTypeStore(is);
1✔
2138
                break;
2139
            case COLUMN_ORIGIN:
1✔
2140
                ret = Origin.valueOf((String) deserialize(is));
1✔
2141
                break;
2142
            case TABLE:
1✔
2143
                ret = deserializeTable(is);
1✔
2144
                break;
2145
            case GRAPH_STORE:
1✔
2146
                ret = deserializeGraphStore(is);
1✔
2147
                break;
2148
            case GRAPH_FACTORY:
1✔
2149
                ret = deserializeGraphFactory(is);
1✔
2150
                break;
2151
            case GRAPH_VIEW_STORE:
1✔
2152
                ret = deserializeViewStore(is);
1✔
2153
                break;
2154
            case GRAPH_VIEW:
1✔
2155
                ret = deserializeGraphView(is);
1✔
2156
                break;
2157
            case BIT_VECTOR:
1✔
2158
                ret = deserializeBitSet(is);
1✔
2159
                break;
2160
            case GRAPH_STORE_CONFIGURATION:
1✔
2161
                ret = deserializeGraphStoreConfiguration(is);
1✔
2162
                break;
2163
            case GRAPH_VERSION:
1✔
2164
                ret = deserializeGraphVersion(is);
1✔
2165
                break;
2166
            case NODE_PROPERTIES:
1✔
2167
                ret = deserializeNodeProperties(is);
1✔
2168
                break;
2169
            case EDGE_PROPERTIES:
1✔
2170
                ret = deserializeEdgeProperties(is);
1✔
2171
                break;
2172
            case TEXT_PROPERTIES:
1✔
2173
                ret = deserializeTextProperties(is);
1✔
2174
                break;
2175
            case ESTIMATOR:
1✔
2176
                ret = Estimator.valueOf(deserializeString(is));
1✔
2177
                break;
2178
            case TIME_REPRESENTATION:
1✔
2179
                ret = TimeRepresentation.valueOf(deserializeString(is));
1✔
2180
                break;
2181
            case TIMESTAMP_MAP:
1✔
2182
                ret = deserializeTimestampMap(is);
1✔
2183
                break;
2184
            case INTERVAL_MAP:
1✔
2185
                ret = deserializeIntervalMap(is);
1✔
2186
                break;
2187
            case TIMESTAMP_INDEX_STORE:
1✔
2188
                ret = deserializeTimestampIndexStore(is);
1✔
2189
                break;
2190
            case INTERVAL_INDEX_STORE:
1✔
2191
                ret = deserializeIntervalIndexStore(is);
1✔
2192
                break;
2193
            case GRAPH_ATTRIBUTES:
1✔
2194
                ret = deserializeGraphAttributes(is);
1✔
2195
                break;
2196
            case TIME_FORMAT:
1✔
2197
                ret = deserializeTimeFormat(is);
1✔
2198
                break;
2199
            case TIME_ZONE:
1✔
2200
                ret = deserializeTimeZone(is);
1✔
2201
                break;
2202
            case TIME_STORE:
1✔
2203
                ret = deserializeTimeStore(is);
1✔
2204
                break;
2205
            case CONFIGURATION:
1✔
2206
                ret = deserializeConfiguration(is);
1✔
2207
                break;
2208
            case INTERVAL:
1✔
2209
                ret = deserializeInterval(is);
1✔
2210
                break;
2211
            case LIST:
1✔
2212
                ret = deserializeList(is);
1✔
2213
                break;
2214
            case SET:
1✔
2215
                ret = deserializeSet(is);
1✔
2216
                break;
2217
            case MAP:
1✔
2218
                ret = deserializeMap(is);
1✔
2219
                break;
2220
            case INSTANT:
1✔
2221
                ret = deserializeInstant(is);
1✔
2222
                break;
2223
            case -1:
1✔
2224
                throw new EOFException();
1✔
2225

2226
        }
×
2227
        return ret;
2228
    }
2229

1✔
2230
    public static String deserializeString(DataInput buf) throws IOException {
2231
        int len = LongPacker.unpackInt(buf);
2232
        char[] b = new char[len];
2233
        for (int i = 0; i < len; i++) {
1✔
2234
            b[i] = (char) LongPacker.unpackInt(buf);
1✔
2235
        }
1✔
2236

1✔
2237
        return new String(b);
2238
    }
2239

1✔
2240
    private Class deserializeClass(DataInput is) throws IOException, ClassNotFoundException {
2241
        String className = (String) deserialize(is);
2242
        Class cls = Class.forName(className);
2243
        return cls;
1✔
2244
    }
1✔
2245

1✔
2246
    private byte[] deserializeArrayByteInt(DataInput is) throws IOException {
2247
        int size = LongPacker.unpackInt(is);
2248
        byte[] b = new byte[size];
2249
        is.readFully(b);
1✔
2250
        return b;
1✔
2251
    }
1✔
2252

1✔
2253
    private long[] deserializeArrayLongL(DataInput is) throws IOException {
2254
        int size = LongPacker.unpackInt(is);
2255
        long[] ret = new long[size];
2256
        for (int i = 0; i < size; i++) {
1✔
2257
            ret[i] = is.readLong();
1✔
2258
        }
1✔
2259
        return ret;
1✔
2260
    }
2261

1✔
2262
    private long[] deserializeArrayLongI(DataInput is) throws IOException {
2263
        int size = LongPacker.unpackInt(is);
2264
        long[] ret = new long[size];
2265
        for (int i = 0; i < size; i++) {
1✔
2266
            ret[i] = is.readInt();
1✔
2267
        }
1✔
2268
        return ret;
1✔
2269
    }
2270

1✔
2271
    private long[] deserializeArrayLongS(DataInput is) throws IOException {
2272
        int size = LongPacker.unpackInt(is);
2273
        long[] ret = new long[size];
2274
        for (int i = 0; i < size; i++) {
1✔
2275
            ret[i] = is.readShort();
1✔
2276
        }
1✔
2277
        return ret;
1✔
2278
    }
2279

1✔
2280
    private long[] deserializeArrayLongB(DataInput is) throws IOException {
2281
        int size = LongPacker.unpackInt(is);
2282
        long[] ret = new long[size];
2283
        for (int i = 0; i < size; i++) {
1✔
2284
            ret[i] = is.readUnsignedByte();
1✔
2285
            if (ret[i] < 0) {
1✔
2286
                throw new EOFException();
1✔
2287
            }
1✔
2288
        }
×
2289
        return ret;
2290
    }
2291

1✔
2292
    private int[] deserializeArrayIntIInt(DataInput is) throws IOException {
2293
        int size = LongPacker.unpackInt(is);
2294
        int[] ret = new int[size];
2295
        for (int i = 0; i < size; i++) {
1✔
2296
            ret[i] = is.readInt();
1✔
2297
        }
1✔
2298
        return ret;
1✔
2299
    }
2300

1✔
2301
    private int[] deserializeArrayIntSInt(DataInput is) throws IOException {
2302
        int size = LongPacker.unpackInt(is);
2303
        int[] ret = new int[size];
2304
        for (int i = 0; i < size; i++) {
1✔
2305
            ret[i] = is.readShort();
1✔
2306
        }
1✔
2307
        return ret;
1✔
2308
    }
2309

1✔
2310
    private int[] deserializeArrayIntBInt(DataInput is) throws IOException {
2311
        int size = LongPacker.unpackInt(is);
2312
        int[] ret = new int[size];
2313
        for (int i = 0; i < size; i++) {
1✔
2314
            ret[i] = is.readUnsignedByte();
1✔
2315
            if (ret[i] < 0) {
1✔
2316
                throw new EOFException();
1✔
2317
            }
1✔
2318
        }
×
2319
        return ret;
2320
    }
2321

1✔
2322
    private int[] deserializeArrayIntPack(DataInput is) throws IOException {
2323
        int size = LongPacker.unpackInt(is);
2324
        if (size < 0) {
2325
            throw new EOFException();
1✔
2326
        }
1✔
2327

×
2328
        int[] ret = new int[size];
2329
        for (int i = 0; i < size; i++) {
2330
            ret[i] = LongPacker.unpackInt(is);
1✔
2331
        }
1✔
2332
        return ret;
1✔
2333
    }
2334

1✔
2335
    private long[] deserializeArrayLongPack(DataInput is) throws IOException {
2336
        int size = LongPacker.unpackInt(is);
2337
        if (size < 0) {
2338
            throw new EOFException();
1✔
2339
        }
1✔
2340

×
2341
        long[] ret = new long[size];
2342
        for (int i = 0; i < size; i++) {
2343
            ret[i] = LongPacker.unpackLong(is);
1✔
2344
        }
1✔
2345
        return ret;
1✔
2346
    }
2347

1✔
2348
    private int[] deserializeArrayIntB255(DataInput is) throws IOException {
2349
        int size = is.readUnsignedByte();
2350
        if (size < 0) {
2351
            throw new EOFException();
1✔
2352
        }
1✔
2353

×
2354
        int[] ret = new int[size];
2355
        for (int i = 0; i < size; i++) {
2356
            ret[i] = is.readUnsignedByte();
1✔
2357
            if (ret[i] < 0) {
1✔
2358
                throw new EOFException();
1✔
2359
            }
1✔
2360
        }
×
2361
        return ret;
2362
    }
2363

1✔
2364
    private String[] deserializeStringArray(DataInput is) throws IOException, ClassNotFoundException {
2365
        int size = LongPacker.unpackInt(is);
2366

2367
        String[] s = (String[]) Array.newInstance(String.class, size);
1✔
2368
        for (int i = 0; i < size; i++) {
2369
            s[i] = deserializeString(is);
1✔
2370
        }
1✔
2371
        return s;
1✔
2372

2373
    }
1✔
2374

2375
    private Object[] deserializeArrayObject(DataInput is) throws IOException, ClassNotFoundException {
2376
        int size = LongPacker.unpackInt(is);
2377

2378
        Object[] s = (Object[]) Array.newInstance(Object.class, size);
1✔
2379
        for (int i = 0; i < size; i++) {
2380
            s[i] = deserialize(is);
1✔
2381
        }
1✔
2382
        return s;
1✔
2383

2384
    }
1✔
2385

2386
    protected static class GraphStoreConfigurationVersion {
2387

2388
        protected final boolean enableElementLabel;
2389
        protected final boolean enableElementTimestamp;
2390
        protected final boolean enableNodeProperties;
2391
        protected final boolean enableEdgeProperties;
2392

2393
        public GraphStoreConfigurationVersion(boolean enableElementLabel, boolean enableElementTimestamp, boolean enableNodeProperties, boolean enableEdgeProperties) {
2394
            this.enableElementLabel = enableElementLabel;
2395
            this.enableElementTimestamp = enableElementTimestamp;
1✔
2396
            this.enableNodeProperties = enableNodeProperties;
1✔
2397
            this.enableEdgeProperties = enableEdgeProperties;
1✔
2398
        }
1✔
2399
    }
1✔
2400
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc