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

gephi / graphstore / #543

21 Apr 2026 06:16PM UTC coverage: 90.973% (+0.02%) from 90.95%
#543

push

mbastian
Enable spatial index by default #270

11731 of 12895 relevant lines covered (90.97%)

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
813
        // no color
814
        // Override this to avoid hidden elements
815
        if (props.alpha() <= 0f) {
1✔
816
            props.setAlpha(1f);
×
817
        }
818

819
        return props;
1✔
820
    }
821

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

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

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

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

854
        return props;
1✔
855
    }
856

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

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

864
        return new TimestampSet(r);
1✔
865
    }
866

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

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

874
        return new IntervalSet(r);
1✔
875
    }
876

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

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

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

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

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

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

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

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

999
    private TimestampIndexStore deserializeTimestampIndexStore(final DataInput is) throws IOException, ClassNotFoundException {
1000
        TimestampIndexStore timestampIndexStore;
1001

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

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

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

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

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

1040
    private IntervalIndexStore deserializeIntervalIndexStore(final DataInput is) throws IOException, ClassNotFoundException {
1041
        IntervalIndexStore intervalIndexStore;
1042

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

1050
        int length = (Integer) deserialize(is);
1✔
1051
        int mapSize = (Integer) deserialize(is);
1✔
1052

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

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

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

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

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

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

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

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

1107
        TimeFormat tf = TimeFormat.valueOf(name);
1✔
1108
        model.store.timeFormat = tf;
1✔
1109

1110
        return tf;
1✔
1111
    }
1112

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

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

1120
        ZoneId tz = ZoneId.of(id);
1✔
1121
        model.store.timeZone = tz;
1✔
1122

1123
        return tz;
1✔
1124
    }
1125

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

1129
        serialize(out, timeStore.nodeIndexStore);
1✔
1130
        serialize(out, timeStore.edgeIndexStore);
1✔
1131
    }
1✔
1132

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

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

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

1147
        deserialize(is);
1✔
1148
        deserialize(is);
1✔
1149

1150
        return timeStore;
1✔
1151
    }
1152

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

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

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

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

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

1183
        return new ConfigurationImpl(config.build());
1✔
1184
    }
1185

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

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

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

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

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

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

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

1360
    // SERIALIZE PRIMITIVES
1361
    protected byte[] serialize(Object obj) throws IOException {
1362
        DataInputOutput ba = new DataInputOutput();
1✔
1363

1364
        serialize(ba, obj);
1✔
1365

1366
        return ba.toByteArray();
1✔
1367
    }
1368

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

1372
        if (obj == null) {
1✔
1373
            out.write(NULL);
1✔
1374

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1784
    }
1✔
1785

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

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

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

1864
        return ret;
1✔
1865
    }
1866

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

1870
        final int head = is.readUnsignedByte();
1✔
1871

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

2228
        }
2229
        return ret;
1✔
2230
    }
2231

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

2239
        return new String(b);
1✔
2240
    }
2241

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2375
    }
2376

2377
    private Object[] deserializeArrayObject(DataInput is) throws IOException, ClassNotFoundException {
2378
        int size = LongPacker.unpackInt(is);
1✔
2379

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

2386
    }
2387

2388
    protected static class GraphStoreConfigurationVersion {
2389

2390
        protected final boolean enableElementLabel;
2391
        protected final boolean enableElementTimestamp;
2392
        protected final boolean enableNodeProperties;
2393
        protected final boolean enableEdgeProperties;
2394

2395
        public GraphStoreConfigurationVersion(boolean enableElementLabel, boolean enableElementTimestamp, boolean enableNodeProperties, boolean enableEdgeProperties) {
1✔
2396
            this.enableElementLabel = enableElementLabel;
1✔
2397
            this.enableElementTimestamp = enableElementTimestamp;
1✔
2398
            this.enableNodeProperties = enableNodeProperties;
1✔
2399
            this.enableEdgeProperties = enableEdgeProperties;
1✔
2400
        }
1✔
2401
    }
2402
}
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