aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-02-27 17:42:52 -0500
committerJim Hahn <jrh3@att.com>2019-02-27 22:05:42 -0500
commite6b3fdd85893ea9a2ccff6e1e7be573e211d0c2c (patch)
tree1b9fbfc1be55ff5f4543da8603dc09d2fa933dbf /utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java
parentdf8ba3401bb8ca7056a4cf4fcb2a202ae454b7e0 (diff)
Add additional encode and decode methods to Coder
Also: Updated some comments and renamed a few parameters. Removed a "throws" for a RuntimeException. Short-circuit some calls. Typo in comment. Let gson create the JsonWriter. Renamed a few more parameters. Change-Id: I22e48c2191820c2a3d0743200edca79bd74353e7 Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java')
-rw-r--r--utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java65
1 files changed, 64 insertions, 1 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java b/utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java
index 41db218b..66a308f7 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/Coder.java
@@ -20,6 +20,12 @@
package org.onap.policy.common.utils.coder;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
/**
* JSON encoder and decoder.
*/
@@ -35,7 +41,34 @@ public interface Coder {
String encode(Object object) throws CoderException;
/**
- * Decodes a json string into an object.
+ * Encodes an object into json, writing to the given target.
+ *
+ * @param target target to which to write the encoded json
+ * @param object object to be encoded
+ * @throws CoderException if an error occurs
+ */
+ void encode(Writer target, Object object) throws CoderException;
+
+ /**
+ * Encodes an object into json, writing to the given target.
+ *
+ * @param target target to which to write the encoded json
+ * @param object object to be encoded
+ * @throws CoderException if an error occurs
+ */
+ void encode(OutputStream target, Object object) throws CoderException;
+
+ /**
+ * Encodes an object into json, writing to the given target.
+ *
+ * @param target target to which to write the encoded json
+ * @param object object to be encoded
+ * @throws CoderException if an error occurs
+ */
+ void encode(File target, Object object) throws CoderException;
+
+ /**
+ * Decodes json into an object.
*
* @param json json string to be decoded
* @param clazz class of object to be decoded
@@ -43,4 +76,34 @@ public interface Coder {
* @throws CoderException if an error occurs
*/
<T> T decode(String json, Class<T> clazz) throws CoderException;
+
+ /**
+ * Decodes json into an object, reading it from the given source.
+ *
+ * @param source source from which to read the json string to be decoded
+ * @param clazz class of object to be decoded
+ * @return the object represented by the given json string
+ * @throws CoderException if an error occurs
+ */
+ <T> T decode(Reader source, Class<T> clazz) throws CoderException;
+
+ /**
+ * Decodes json into an object, reading it from the given source.
+ *
+ * @param source source from which to read the json string to be decoded
+ * @param clazz class of object to be decoded
+ * @return the object represented by the given json string
+ * @throws CoderException if an error occurs
+ */
+ <T> T decode(InputStream source, Class<T> clazz) throws CoderException;
+
+ /**
+ * Decodes json into an object, reading it from the given source.
+ *
+ * @param source source from which to read the json string to be decoded
+ * @param clazz class of object to be decoded
+ * @return the object represented by the given json string
+ * @throws CoderException if an error occurs
+ */
+ <T> T decode(File source, Class<T> clazz) throws CoderException;
}