From bd86c2218b4a8befeb9b2789b62e1697993f0b5b Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Mon, 29 Apr 2019 21:51:54 +0200 Subject: [PATCH] jdoc --- .../utils/serial/CustomSerializer.java | 72 ++++++++++++++++++- .../utils/serial/server/ConnectAction.java | 1 + 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/be/nikiroo/utils/serial/CustomSerializer.java b/src/be/nikiroo/utils/serial/CustomSerializer.java index e5539c0f..c5876ce4 100644 --- a/src/be/nikiroo/utils/serial/CustomSerializer.java +++ b/src/be/nikiroo/utils/serial/CustomSerializer.java @@ -10,17 +10,74 @@ import be.nikiroo.utils.streams.NextableInputStreamStep; import be.nikiroo.utils.streams.ReplaceInputStream; import be.nikiroo.utils.streams.ReplaceOutputStream; +/** + * A {@link CustomSerializer} supports and generates values in the form: + * + *

+ * In this scheme, the values are: + *

+ *

+ * To create a new {@link CustomSerializer}, you are expected to implement the + * abstract methods of this class. The rest should be taken care of bythe + * system. + * + * @author niki + */ public abstract class CustomSerializer { - + /** + * Generate the custom ENCODED_VALUE from this + * value. + *

+ * The value will always be of the supported type. + * + * @param out + * the {@link OutputStream} to write the value to + * @param value + * the value to serialize + * + * @throws IOException + * in case of I/O error + */ protected abstract void toStream(OutputStream out, Object value) throws IOException; + /** + * Regenerate the value from the custom ENCODED_VALUE. + *

+ * The value in the {@link InputStream} in will always be of the + * supported type. + * + * @param in + * the {@link InputStream} containing the + * ENCODED_VALUE + * + * @return the regenerated object + * + * @throws IOException + * in case of I/O error + */ protected abstract Object fromStream(InputStream in) throws IOException; + /** + * Return the supported type name. + *

+ * It must be the name returned by {@link Object#getClass() + * #getCanonicalName()}. + * + * @return the supported class name + */ protected abstract String getType(); /** - * Encode the object into the given {@link OutputStream} if supported. + * Encode the object into the given {@link OutputStream}. * * @param out * the builder to append to @@ -45,6 +102,17 @@ public abstract class CustomSerializer { } } + /** + * Decode the value back into the supported object type. + * + * @param in + * the encoded value + * + * @return the object + * + * @throws IOException + * in case of I/O error + */ public Object decode(InputStream in) throws IOException { ReplaceInputStream replace = new ReplaceInputStream(in, // new String[] { "\\\\", "\\n" }, // diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index 25bde245..c02d734f 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -364,6 +364,7 @@ abstract class ConnectAction { * @throws java.lang.NullPointerException * for Objects only: if the counter part has no data to send */ + @SuppressWarnings("resource") private Object rec(boolean asString) throws IOException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException, java.lang.NullPointerException { -- 2.27.0