From 240ea937b30bdc91043e0886651d110ce6bb969e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 21 Jun 2016 19:00:54 +0200 Subject: [PATCH] WIP --- .../java/de/juplo/jackson/SimpleMapper.java | 412 +++++++++++++++++- 1 file changed, 402 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/juplo/jackson/SimpleMapper.java b/src/main/java/de/juplo/jackson/SimpleMapper.java index db2df37..e4028db 100644 --- a/src/main/java/de/juplo/jackson/SimpleMapper.java +++ b/src/main/java/de/juplo/jackson/SimpleMapper.java @@ -5,7 +5,11 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.net.URL; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -34,16 +38,395 @@ public class SimpleMapper LoggerFactory.getLogger(SimpleMapper.class); - private JsonFactory factory = new JsonFactory(); + private final JsonFactory factory; - public static Stream getArrayStream(final JsonParser parser) + public SimpleMapper(JsonFactory factory) + { + this.factory = factory; + } + + + public Spliterator getArraySpliterator(File file) throws IOException { - return StreamSupport.stream(getArraySpliterator(parser), false); + return getArraySpliterator(factory.createParser(file)); + } + + public Spliterator getArraySpliterator(InputStream is) + throws + IOException + { + return getArraySpliterator(factory.createParser(is)); + } + + public Spliterator getArraySpliterator(Reader r) + throws + IOException + { + return getArraySpliterator(factory.createParser(r)); + } + + public Spliterator getArraySpliterator(String content) + throws + IOException + { + return getArraySpliterator(factory.createParser(content)); + } + + public Spliterator getArraySpliterator(URL url) + throws + IOException + { + return getArraySpliterator(factory.createParser(url)); + } + + public Spliterator getArraySpliterator(byte[] data) + throws + IOException + { + return getArraySpliterator(factory.createParser(data)); + } + + public Spliterator getArraySpliterator(char[] content) + throws + IOException + { + return getArraySpliterator(factory.createParser(content)); + } + + public Spliterator getArraySpliterator(byte[] data, int offset, int len) + throws + IOException + { + return getArraySpliterator(factory.createParser(data, offset, len)); + } + + public Spliterator getArraySpliterator(char[] data, int offset, int len) + throws + IOException + { + return getArraySpliterator(factory.createParser(data, offset, len)); + } + + public Stream getArrayStream(File file) + throws + IOException + { + return getArrayStream(factory.createParser(file)); + } + + public Stream getArrayStream(InputStream is) + throws + IOException + { + return getArrayStream(factory.createParser(is)); + } + + public Stream getArrayStream(Reader r) + throws + IOException + { + return getArrayStream(factory.createParser(r)); + } + + public Stream getArrayStream(String content) + throws + IOException + { + return getArrayStream(factory.createParser(content)); + } + + public Stream getArrayStream(URL url) + throws + IOException + { + return getArrayStream(factory.createParser(url)); + } + + public Stream getArrayStream(byte[] data) + throws + IOException + { + return getArrayStream(factory.createParser(data)); + } + + public Stream getArrayStream(char[] content) + throws + IOException + { + return getArrayStream(factory.createParser(content)); + } + + public Stream getArrayStream(byte[] data, int offset, int len) + throws + IOException + { + return getArrayStream(factory.createParser(data, offset, len)); + } + + public Stream getArrayStream(char[] data, int offset, int len) + throws + IOException + { + return getArrayStream(factory.createParser(data, offset, len)); + } + + public Iterator getArrayIterator(File file) + throws + IOException + { + return getArrayIterator(factory.createParser(file)); + } + + public Iterator getArrayIterator(InputStream is) + throws + IOException + { + return getArrayIterator(factory.createParser(is)); + } + + public Iterator getArrayIterator(Reader r) + throws + IOException + { + return getArrayIterator(factory.createParser(r)); + } + + public Iterator getArrayIterator(String content) + throws + IOException + { + return getArrayIterator(factory.createParser(content)); + } + + public Iterator getArrayIterator(URL url) + throws + IOException + { + return getArrayIterator(factory.createParser(url)); + } + + public Iterator getArrayIterator(byte[] data) + throws + IOException + { + return getArrayIterator(factory.createParser(data)); + } + + public Iterator getArrayIterator(char[] content) + throws + IOException + { + return getArrayIterator(factory.createParser(content)); + } + + public Iterator getArrayIterator(byte[] data, int offset, int len) + throws + IOException + { + return getArrayIterator(factory.createParser(data, offset, len)); + } + + public Iterator getArrayIterator(char[] data, int offset, int len) + throws + IOException + { + return getArrayIterator(factory.createParser(data, offset, len)); + } + + + public Spliterator> getObjectSpliterator(File file) + throws + IOException + { + return getObjectSpliterator(factory.createParser(file)); + } + + public Spliterator> getObjectSpliterator(InputStream is) + throws + IOException + { + return getObjectSpliterator(factory.createParser(is)); + } + + public Spliterator> getObjectSpliterator(Reader r) + throws + IOException + { + return getObjectSpliterator(factory.createParser(r)); + } + + public Spliterator> getObjectSpliterator(String content) + throws + IOException + { + return getObjectSpliterator(factory.createParser(content)); + } + + public Spliterator> getObjectSpliterator(URL url) + throws + IOException + { + return getObjectSpliterator(factory.createParser(url)); + } + + public Spliterator> getObjectSpliterator(byte[] data) + throws + IOException + { + return getObjectSpliterator(factory.createParser(data)); + } + + public Spliterator> getObjectSpliterator(char[] content) + throws + IOException + { + return getObjectSpliterator(factory.createParser(content)); + } + + public Spliterator> getObjectSpliterator(byte[] data, int offset, int len) + throws + IOException + { + return getObjectSpliterator(factory.createParser(data, offset, len)); + } + + public Spliterator> getObjectSpliterator(char[] data, int offset, int len) + throws + IOException + { + return getObjectSpliterator(factory.createParser(data, offset, len)); + } + + public Stream> getObjectStream(File file) + throws + IOException + { + return getObjectStream(factory.createParser(file)); + } + + public Stream> getObjectStream(InputStream is) + throws + IOException + { + return getObjectStream(factory.createParser(is)); + } + + public Stream> getObjectStream(Reader r) + throws + IOException + { + return getObjectStream(factory.createParser(r)); + } + + public Stream> getObjectStream(String content) + throws + IOException + { + return getObjectStream(factory.createParser(content)); + } + + public Stream> getObjectStream(URL url) + throws + IOException + { + return getObjectStream(factory.createParser(url)); + } + + public Stream> getObjectStream(byte[] data) + throws + IOException + { + return getObjectStream(factory.createParser(data)); + } + + public Stream> getObjectStream(char[] content) + throws + IOException + { + return getObjectStream(factory.createParser(content)); + } + + public Stream> getObjectStream(byte[] data, int offset, int len) + throws + IOException + { + return getObjectStream(factory.createParser(data, offset, len)); } + public Stream> getObjectStream(char[] data, int offset, int len) + throws + IOException + { + return getObjectStream(factory.createParser(data, offset, len)); + } + + public Iterator> getObjectIterator(File file) + throws + IOException + { + return getObjectIterator(factory.createParser(file)); + } + + public Iterator> getObjectIterator(InputStream is) + throws + IOException + { + return getObjectIterator(factory.createParser(is)); + } + + public Iterator> getObjectIterator(Reader r) + throws + IOException + { + return getObjectIterator(factory.createParser(r)); + } + + public Iterator> getObjectIterator(String content) + throws + IOException + { + return getObjectIterator(factory.createParser(content)); + } + + public Iterator> getObjectIterator(URL url) + throws + IOException + { + return getObjectIterator(factory.createParser(url)); + } + + public Iterator> getObjectIterator(byte[] data) + throws + IOException + { + return getObjectIterator(factory.createParser(data)); + } + + public Iterator> getObjectIterator(char[] content) + throws + IOException + { + return getObjectIterator(factory.createParser(content)); + } + + public Iterator> getObjectIterator(byte[] data, int offset, int len) + throws + IOException + { + return getObjectIterator(factory.createParser(data, offset, len)); + } + + public Iterator> getObjectIterator(char[] data, int offset, int len) + throws + IOException + { + return getObjectIterator(factory.createParser(data, offset, len)); + } + + public static Spliterator getArraySpliterator(final JsonParser parser) throws IOException @@ -100,6 +483,13 @@ public class SimpleMapper }; } + public static Stream getArrayStream(final JsonParser parser) + throws + IOException + { + return StreamSupport.stream(getArraySpliterator(parser), false); + } + public static Iterator getArrayIterator(final JsonParser parser) throws IOException @@ -139,13 +529,6 @@ public class SimpleMapper } - public static Stream> getObjectStream(final JsonParser parser) - throws - IOException - { - return StreamSupport.stream(getObjectSpliterator(parser), false); - } - public static Spliterator> getObjectSpliterator(final JsonParser parser) throws IOException @@ -226,6 +609,13 @@ public class SimpleMapper }; } + public static Stream> getObjectStream(final JsonParser parser) + throws + IOException + { + return StreamSupport.stream(getObjectSpliterator(parser), false); + } + public static Iterator> getObjectIterator( final JsonParser parser ) @@ -289,6 +679,7 @@ public class SimpleMapper return null; // << Will never be reached, because fail always throws an exception } + static Map convertObject(JsonParser parser) throws IOException { JsonToken token = parser.nextToken(); @@ -335,6 +726,7 @@ public class SimpleMapper return list; } + static void fail(JsonParser parser, String message) { JsonLocation location = parser.getCurrentLocation(); -- 2.20.1