From b2f0488a51ca22c4c00e79ec4f04817f4e5d7f57 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 25 Feb 2018 20:06:11 +0300 Subject: [PATCH] Moved envelopes to kotlin. New implementation for tagless envelope via NIO --- .../java/inr/numass/client/NumassClient.java | 2 +- .../java/inr/numass/NumassEnvelopeType.java | 18 ++++++++---------- .../src/main/kotlin/inr/numass/NumassUtils.kt | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/numass-client/src/main/java/inr/numass/client/NumassClient.java b/numass-client/src/main/java/inr/numass/client/NumassClient.java index 389d54e6..d0cc07c4 100644 --- a/numass-client/src/main/java/inr/numass/client/NumassClient.java +++ b/numass-client/src/main/java/inr/numass/client/NumassClient.java @@ -83,7 +83,7 @@ public class NumassClient implements AutoCloseable, Responder { } private void write(Envelope envelope, OutputStream os) throws IOException { - DefaultEnvelopeType.instance.getWriter().write(os, envelope); + DefaultEnvelopeType.Companion.getINSTANCE().getWriter().write(os, envelope); os.flush(); } diff --git a/numass-core/src/main/java/inr/numass/NumassEnvelopeType.java b/numass-core/src/main/java/inr/numass/NumassEnvelopeType.java index 0d69571d..b382d1d7 100644 --- a/numass-core/src/main/java/inr/numass/NumassEnvelopeType.java +++ b/numass-core/src/main/java/inr/numass/NumassEnvelopeType.java @@ -9,8 +9,6 @@ import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; -import static hep.dataforge.io.envelopes.DefaultEnvelopeType.DEFAULT_ENVELOPE_TYPE; - /** * An envelope type for legacy numass tags. Reads legacy tag and writes DF02 tags */ @@ -21,7 +19,7 @@ public class NumassEnvelopeType implements EnvelopeType { @Override public int getCode() { - return DEFAULT_ENVELOPE_TYPE; + return DefaultEnvelopeType.DEFAULT_ENVELOPE_TYPE; } @Override @@ -41,7 +39,7 @@ public class NumassEnvelopeType implements EnvelopeType { @Override public EnvelopeWriter getWriter(Map properties) { - return new DefaultEnvelopeWriter(this, MetaType.resolve(properties)); + return new DefaultEnvelopeWriter(this, MetaType.Companion.resolve(properties)); } public static class LegacyTag extends EnvelopeTag { @@ -71,25 +69,25 @@ public class NumassEnvelopeType implements EnvelopeType { * @return * @throws IOException */ - protected Map readHeader(ByteBuffer buffer) throws IOException { + protected Map readHeader(ByteBuffer buffer) { Map res = new HashMap<>(); int type = buffer.getInt(2); - res.put(Envelope.TYPE_KEY, Value.of(type)); + res.put(Envelope.Companion.TYPE_KEY, Value.of(type)); short metaTypeCode = buffer.getShort(10); - MetaType metaType = MetaType.resolve(metaTypeCode); + MetaType metaType = MetaType.Companion.resolve(metaTypeCode); if (metaType != null) { - res.put(Envelope.META_TYPE_KEY, Value.of(metaType.getName())); + res.put(Envelope.Companion.META_TYPE_KEY, Value.of(metaType.getName())); } else { LoggerFactory.getLogger(EnvelopeTag.class).warn("Could not resolve meta type. Using default"); } long metaLength = Integer.toUnsignedLong(buffer.getInt(14)); - res.put(Envelope.META_LENGTH_KEY, Value.of(metaLength)); + res.put(Envelope.Companion.META_LENGTH_KEY, Value.of(metaLength)); long dataLength = Integer.toUnsignedLong(buffer.getInt(22)); - res.put(Envelope.DATA_LENGTH_KEY, Value.of(dataLength)); + res.put(Envelope.Companion.DATA_LENGTH_KEY, Value.of(dataLength)); return res; } } diff --git a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt index 12b52f4e..bb250b26 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt @@ -131,7 +131,7 @@ object NumassUtils { fun writeEnvelope(stream: OutputStream, envelope: Envelope) { try { - DefaultEnvelopeType.instance.writer.write(stream, envelope) + DefaultEnvelopeType.INSTANCE.writer.write(stream, envelope) stream.flush() } catch (e: IOException) { throw RuntimeException(e)