Added InputStream and Writer in constructor of Json classes

This commit is contained in:
Ziver Koc 2015-10-01 16:02:48 +00:00
parent 1dba0c88aa
commit 38f03585e4
4 changed files with 25 additions and 12 deletions

View file

@ -48,11 +48,18 @@ public class JSONObjectInputStream extends InputStream implements ObjectInput, C
private HashMap<Integer, Object> objectCache; private HashMap<Integer, Object> objectCache;
public JSONObjectInputStream(Reader in) { private JSONObjectInputStream() {
this.parser = new JSONParser(in);
this.registeredClasses = new HashMap<>(); this.registeredClasses = new HashMap<>();
this.objectCache = new HashMap<>(); this.objectCache = new HashMap<>();
} }
public JSONObjectInputStream(Reader in) {
this();
this.parser = new JSONParser(in);
}
public JSONObjectInputStream(InputStream in) {
this();
this.parser = new JSONParser(in);
}
/** /**

View file

@ -31,10 +31,7 @@ import zutil.parser.DataNode.DataType;
import static zutil.parser.json.JSONObjectInputStream.*; import static zutil.parser.json.JSONObjectInputStream.*;
import javax.activation.UnsupportedDataTypeException; import javax.activation.UnsupportedDataTypeException;
import java.io.Closeable; import java.io.*;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.OutputStream;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -50,9 +47,16 @@ public class JSONObjectOutputStream extends OutputStream implements ObjectOutput
private HashMap<Object,Integer> objectCache; private HashMap<Object,Integer> objectCache;
private JSONWriter out; private JSONWriter out;
public JSONObjectOutputStream(OutputStream out) { private JSONObjectOutputStream() {
this.generateMetaData = true; this.generateMetaData = true;
this.objectCache = new HashMap<Object, Integer>(); this.objectCache = new HashMap<Object, Integer>();
}
public JSONObjectOutputStream(OutputStream out) {
this();
this.out = new JSONWriter(out);
}
public JSONObjectOutputStream(Writer out) {
this();
this.out = new JSONWriter(out); this.out = new JSONWriter(out);
} }

View file

@ -29,9 +29,7 @@ import zutil.parser.DataNode.DataType;
import zutil.parser.Parser; import zutil.parser.Parser;
import zutil.struct.MutableInt; import zutil.struct.MutableInt;
import java.io.IOException; import java.io.*;
import java.io.Reader;
import java.io.StringReader;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -48,6 +46,9 @@ public class JSONParser extends Parser {
public JSONParser(Reader in){ public JSONParser(Reader in){
this.in = in; this.in = in;
} }
public JSONParser(InputStream in){
this.in = new InputStreamReader(in);
}
/** /**
* Starts parsing from the input. * Starts parsing from the input.

View file

@ -31,6 +31,7 @@ import zutil.parser.DataNode.DataType;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -55,7 +56,7 @@ public class JSONWriter{
* *
* @param out the OutputStream that the Nodes will be sent to * @param out the OutputStream that the Nodes will be sent to
*/ */
public JSONWriter(PrintStream out){ public JSONWriter(Writer out){
this( new PrintWriter(out) ); this( new PrintWriter(out) );
} }