DataExternalizer<Collection<Integer>> () { return new DataExternalizer<>() { @Override public void save(@NotNull DataOutput out, @NotNull Collection<Integer> value) throws IOException { final int numberOfValues = value.size(); int[] buffer = SPARE_BUFFER_LOCAL.getBuffer(numberOfValues); int ptr = 0; for (Integer i : value) { buffer[ptr++] = i; } Arrays.sort(buffer, 0, numberOfValues); DataInputOutputUtil.writeINT(out, numberOfValues); int prev = 0; for (ptr = 0; ptr < numberOfValues; ++ptr) { DataInputOutputUtil.writeLONG(out, (long)buffer[ptr] - prev); prev = buffer[ptr]; } } @Override public @NotNull Collection<Integer> read(@NotNull DataInput in) throws IOException { int size = DataInputOutputUtil.readINT(in); List<Integer> result = new ArrayList<>(size); int prev = 0; while (size-- > 0) { int l = (int)(DataInputOutputUtil.readLONG(in) + prev); result.add(l); prev = l; } return result; } }; }