use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.
the class FileSourceSplitSerializer method deserializeV1.
private static FileSourceSplit deserializeV1(byte[] serialized) throws IOException {
final DataInputDeserializer in = new DataInputDeserializer(serialized);
final String id = in.readUTF();
final Path path = new Path();
path.read(in);
final long offset = in.readLong();
final long len = in.readLong();
final long modificationTime = in.readLong();
final long fileSize = in.readLong();
final String[] hosts = readStringArray(in);
final CheckpointedPosition readerPosition = in.readBoolean() ? new CheckpointedPosition(in.readLong(), in.readLong()) : null;
// instantiate a new split and cache the serialized form
return new FileSourceSplit(id, path, offset, len, modificationTime, fileSize, hosts, readerPosition, serialized);
}
use of org.apache.flink.connector.file.src.util.CheckpointedPosition in project flink by apache.
the class FileSourceSplitSerializer method serialize.
@Override
public byte[] serialize(FileSourceSplit split) throws IOException {
checkArgument(split.getClass() == FileSourceSplit.class, "Cannot serialize subclasses of FileSourceSplit");
// optimization: the splits lazily cache their own serialized form
if (split.serializedFormCache != null) {
return split.serializedFormCache;
}
final DataOutputSerializer out = SERIALIZER_CACHE.get();
out.writeUTF(split.splitId());
split.path().write(out);
out.writeLong(split.offset());
out.writeLong(split.length());
out.writeLong(split.fileModificationTime());
out.writeLong(split.fileSize());
writeStringArray(out, split.hostnames());
final Optional<CheckpointedPosition> readerPosition = split.getReaderPosition();
out.writeBoolean(readerPosition.isPresent());
if (readerPosition.isPresent()) {
out.writeLong(readerPosition.get().getOffset());
out.writeLong(readerPosition.get().getRecordsAfterOffset());
}
final byte[] result = out.getCopyOfBuffer();
out.clear();
// optimization: cache the serialized from, so we avoid the byte work during repeated
// serialization
split.serializedFormCache = result;
return result;
}
Aggregations