Replaced OutputStreams with Output objects

This commit is contained in:
Alexander Nozik 2018-01-30 21:29:30 +03:00
parent 13a3376433
commit b5aece6d8e
16 changed files with 33 additions and 40 deletions

View File

@ -21,7 +21,7 @@ import java.util.Properties;
public class NumassProperties {
private static File getNumassPropertiesFile() throws IOException {
File file = new File(Global.instance().getUserDirectory(), "numass");
File file = new File(Global.Companion.instance().getUserDirectory(), "numass");
if (!file.exists()) {
file.mkdirs();
}
@ -54,7 +54,7 @@ public class NumassProperties {
}
props.store(new FileOutputStream(store), "");
} catch (IOException ex) {
Global.instance().getLogger().error("Failed to save numass properties", ex);
Global.Companion.instance().getLogger().error("Failed to save numass properties", ex);
}
}
}

View File

@ -2,7 +2,7 @@ package inr.numass.data.api;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.utils.MetaHolder;
import hep.dataforge.meta.MetaHolder;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -69,7 +69,7 @@ public class NumassStorageFactory implements StorageType {
return new NumassStorage(context, meta, path);
} else {
context.getLogger().warn("A storage path not provided. Creating default root storage in the working directory");
return new NumassStorage(context, meta, context.getIo().getWorkDirectory());
return new NumassStorage(context, meta, context.getIo().getWorkDir());
}
}

View File

@ -2,7 +2,7 @@ package inr.numass.scripts.workspace
import hep.dataforge.actions.ActionUtils
import hep.dataforge.context.Context
import hep.dataforge.io.IOManager
import hep.dataforge.context.IOManager
import inr.numass.NumassPlugin
/**

View File

@ -18,8 +18,8 @@ package inr.numass;
import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context;
import hep.dataforge.context.Global;
import hep.dataforge.context.IOManager;
import hep.dataforge.data.FileDataFactory;
import hep.dataforge.io.IOManager;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta;
import org.apache.commons.cli.*;
@ -52,7 +52,7 @@ public class Main {
public static void run(Context context, String[] args) throws Exception {
if(context == null){
context = Global.instance();
context = Global.Companion.instance();
}
Logger logger = LoggerFactory.getLogger("numass-main");
@ -78,7 +78,7 @@ public class Main {
if (args.length == 0) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar DataReader.jar [OPTIONS]", options);
out().println("Trying to use default config location...");
Companion.out().println("Trying to use default config location...");
}
if (line.hasOption("c")) {

View File

@ -31,14 +31,14 @@ import hep.dataforge.meta.Meta;
public class Numass {
public static Context buildContext(Context parent, Meta meta) {
return Context.builder("NUMASS", parent)
return Context.Companion.builder("NUMASS", parent)
.properties(meta)
.plugin(NumassPlugin.class)
.build();
}
public static Context buildContext() {
return buildContext(Global.instance(), Meta.empty());
return buildContext(Global.Companion.instance(), Meta.empty());
}
public static void printDescription(Context context) throws DescriptorException {

View File

@ -39,7 +39,7 @@ public class MonitorCorrector {
private final List<MonitorPoint> list;
public MonitorCorrector(String path) throws ParseException, IOException {
this(Global.instance().getIo().getFile(path));
this(Global.Companion.instance().getIo().getFile(path));
}
public MonitorCorrector(Path monitorFile) throws ParseException, IOException {

View File

@ -40,7 +40,7 @@ public class OldDataReader {
public static Table readConfig(String path) throws IOException {
String[] list = {"X", "time", "ushift"};
ListTable.Builder res = new ListTable.Builder(list);
Path file = Global.instance().getIo().getFile(path);
Path file = Global.Companion.instance().getIo().getFile(path);
Scanner sc = new Scanner(file);
sc.nextLine();
@ -62,7 +62,7 @@ public class OldDataReader {
public static Table readData(String path, double Elow) {
SpectrumAdapter factory = new SpectrumAdapter(Meta.empty());
ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory));
Path file = Global.instance().getIo().getFile(path);
Path file = Global.Companion.instance().getIo().getFile(path);
double x;
int count;
int time;
@ -114,7 +114,7 @@ public class OldDataReader {
public static Table readDataAsGun(String path, double Elow) {
SpectrumAdapter factory = new SpectrumAdapter(Meta.empty());
ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory));
Path file = Global.instance().getIo().getFile(path);
Path file = Global.Companion.instance().getIo().getFile(path);
double x;
long count;
int time;
@ -147,7 +147,7 @@ public class OldDataReader {
public static Table readSpectrumData(String path) {
SpectrumAdapter factory = new SpectrumAdapter(Meta.empty());
ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory));
Path file = Global.instance().getIo().getFile(path);
Path file = Global.Companion.instance().getIo().getFile(path);
double x;
double count;
double time;

View File

@ -21,9 +21,9 @@ import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.Appender
import ch.qos.logback.core.FileAppender
import hep.dataforge.context.Context
import hep.dataforge.context.DefaultIOManager
import hep.dataforge.context.IOManager
import hep.dataforge.fx.plots.plusAssign
import hep.dataforge.io.BasicIOManager
import hep.dataforge.io.IOManager
import hep.dataforge.meta.Meta
import hep.dataforge.names.Name
import hep.dataforge.plots.PlotUtils
@ -45,7 +45,7 @@ import java.util.*
/**
* @author Darksnake
*/
class NumassIO : BasicIOManager() {
class NumassIO : DefaultIOManager() {
internal var registry = ReferenceRegistry<OutputStream>()
// FileAppender<ILoggingEvent> appender;
@ -63,7 +63,7 @@ class NumassIO : BasicIOManager() {
ple.context = lc
ple.start()
val appender = FileAppender<ILoggingEvent>()
appender.file = File(workDirectory.toFile(), meta.getString("logFileName", "numass.log")).toString()
appender.file = File(workDir.toFile(), meta.getString("logFileName", "numass.log")).toString()
appender.encoder = ple
return appender
}
@ -103,7 +103,7 @@ class NumassIO : BasicIOManager() {
val dirName = tokens.joinToString(File.separator)
val fileName = name.toString() + getExtension(type)
val out = buildOut(workDirectory, dirName, fileName)
val out = buildOut(workDir, dirName, fileName)
registry.add(out)
return out
}

View File

@ -50,7 +50,7 @@ class NumassPlugin : BasicPlugin() {
override fun attach(context: Context) {
// StorageManager.buildFrom(context);
super.attach(context)
context.getPluginManager().load(NumassIO())
context.pluginManager.load(NumassIO())
loadModels(context.getFeature(ModelManager::class.java))
loadMath(MathPlugin.buildFrom(context))

View File

@ -18,12 +18,14 @@ package inr.numass
import hep.dataforge.context.Context
import hep.dataforge.data.DataNode
import hep.dataforge.data.DataSet
import hep.dataforge.data.binary.Binary
import hep.dataforge.io.envelopes.DefaultEnvelopeType
import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.io.envelopes.EnvelopeBuilder
import hep.dataforge.io.envelopes.TaglessEnvelopeType
import hep.dataforge.io.markup.Markedup
import hep.dataforge.io.markup.SimpleMarkupRenderer
import hep.dataforge.kodex.nullable
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.plots.jfreechart.JFreeChartFrame
@ -45,7 +47,6 @@ import tornadofx.*
import java.awt.Color
import java.awt.Font
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.lang.Math.*
import java.util.*
@ -165,18 +166,10 @@ object NumassUtils {
fun getFSS(context: Context, meta: Meta): FSS? {
return if (meta.getBoolean("useFSS", true)) {
val fssStream = meta.optString("fssFile")
.map<InputStream> { fssFile ->
try {
context.io.optBinary(fssFile)
.orElseThrow({ RuntimeException("Could not locate FSS file") })
.stream
} catch (e: IOException) {
throw RuntimeException("Could not load FSS file", e)
}
}
.orElse(context.io.optResource("data/FS.txt").get().stream)
FSS(fssStream)
val fssBinary: Binary? = meta.optString("fssFile")
.map { fssFile -> context.io.getFile(fssFile).binary }
.orElse(context.io.optResource("data/FS.txt").nullable)
fssBinary?.let { FSS(it.stream) } ?: throw RuntimeException("Could not load FSS file")
} else {
null
}

View File

@ -120,7 +120,7 @@ class MergeDataAction : ManyToOneAction<Table, Table>() {
}
companion object {
val MERGE_NAME = "mergeName"
const val MERGE_NAME = "mergeName"
}
}

View File

@ -175,7 +175,7 @@ val subtractEmptyTask = task("dif") {
res.goal.onComplete { r, _ ->
if (r != null) {
context.getIo().out("numass.merge", input.name + "_subtract").use {
context.io.out("numass.merge", input.name + "_subtract").use {
NumassUtils.write(it, resMeta, r)
}
}
@ -228,7 +228,7 @@ val fitTask = task("fit") {
configure(meta.getMeta("fit"))
}
pipe<Table, FitResult> { data ->
context.getIo().out("numass.fit", name).use { out ->
context.io.out("numass.fit", name).use { out ->
val writer = PrintWriter(out)
writer.printf("%n*** META ***%n")
writer.println(meta.toString())

View File

@ -30,7 +30,7 @@ public class TransmissionInterpolatorTest {
public static void main(String[] args) {
JFreeChartFrame frame = NumassPluginKt.displayJFreeChart("TransmissionInterpolatorTest");
//JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null);
TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(Global.instance(),
TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(Global.Companion.instance(),
"d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.onComplete", "Uset", "CR", 15, 0.8, 19002d);
frame.add(DataPlot.plot("data", interpolator.getX(), interpolator.getY()));
frame.add(XYFunctionPlot.Companion.plot("interpolated", interpolator.getXmin(), interpolator.getXmax(), 2000, interpolator::value));

View File

@ -24,7 +24,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
// private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path";
NumassStorage root;
NumassServer listener;
Context context = Global.getContext("NUMASS_SERVER");
Context context = Global.Companion.getContext("NUMASS_SERVER");
public ServerRunner() throws IOException, ParseException {
// Global.instance().getPluginManager().load(StorageManager.class);

View File

@ -27,7 +27,7 @@ public class TestServer {
* @throws hep.dataforge.exceptions.StorageException
*/
public static void main(String[] args) throws Exception {
Context context = Global.getContext("NUMASS-SERVER");
Context context = Global.Companion.getContext("NUMASS-SERVER");
StorageManager storageManager = context.getPluginManager().load(StorageManager.class);