+ static @NonNull JournalSegmentFile createNew(final String name, final File directory,
+ final JournalSegmentDescriptor descriptor) throws IOException {
+ final var file = createSegmentFile(name, directory, descriptor.id());
+ try (var raf = new RandomAccessFile(file, "rw")) {
+ raf.setLength(descriptor.maxSegmentSize());
+ raf.write(descriptor.toArray());
+ }
+ return new JournalSegmentFile(file.toPath(), descriptor);
+ }
+
+ static @NonNull JournalSegmentFile openExisting(final Path path) throws IOException {
+ // read the descriptor
+ final var descriptor = JournalSegmentDescriptor.readFrom(path);
+ return new JournalSegmentFile(path, descriptor);
+ }
+