org.nocrala.tools.database.sentinel.plugin.ShowSnapshotOperation Maven / Gradle / Ivy
The newest version!
package org.nocrala.tools.database.sentinel.plugin;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import org.nocrala.tools.database.sentinel.BuildInformation;
import org.nocrala.tools.database.sentinel.Snapshot;
import org.nocrala.tools.database.sentinel.SnapshotRenderer;
import org.nocrala.tools.database.sentinel.util.XUtil;
public class ShowSnapshotOperation {
private File snapshotfile = null;
public ShowSnapshotOperation(final File snapshotfile) {
this.snapshotfile = snapshotfile;
}
public void execute(final Feedback feedback) throws Exception {
feedback.info("Sentinel " + BuildInformation.VERSION + " - build " + BuildInformation.BUILD_ID);
// 1. Load the snapshot
Snapshot s = null;
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(this.snapshotfile))) {
s = Snapshot.readFrom(bis);
} catch (Throwable e) {
throw new Exception("Could not load snapshot: " + XUtil.renderThrowable(e));
}
// 2. Display snapshot's summary
SnapshotRenderer r = new SnapshotRenderer();
feedback.info("Snapshot file: " + this.snapshotfile.getPath());
s.renderHeader().stream().forEach(l -> feedback.info(l));
r.render(s).stream().forEach(l -> feedback.info(l));
feedback.info(" ");
}
}