Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Provides a mapping from Event Admin events to Javascript Server Side Events (SSE). This bundle registers under /sse/1, the remaining path is treated as the topic. It will then send all matching events to the browser through SSE. The type of the event is org.osgi.service.eventadmin;topic=%s, the data payload is a JSON representation of the event properties.
package aQute.lib.json;
import java.io.EOFException;
import java.io.File;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
/**
* This is a simple JSON Coder and Encoder that uses the Java type system to
* convert data objects to JSON and JSON to (type safe) Java objects. The
* conversion is very much driven by classes and their public fields. Generic
* information, when present is taken into account.
*
* Usage patterns to encode:
*
*
* JSONCoder codec = new JSONCodec(); // assert "1".equals(
* codec.enc().to().put(1).toString()); assert "[1,2,3]".equals(
* codec.enc().to().put(Arrays.asList(1,2,3).toString()); Map m = new HashMap();
* m.put("a", "A"); assert "{\"a\":\"A\"}".equals(
* codec.enc().to().put(m).toString()); static class D { public int a; } D d =
* new D(); d.a = 41; assert "{\"a\":41}".equals(
* codec.enc().to().put(d).toString());
*
*
* It is possible to redirect the encoder to another output (default is a
* string). See {@link Encoder#to()},{@link Encoder#to(File)},
* {@link Encoder#to(OutputStream)}, {@link Encoder#to(Appendable)}. To reset
* the string output call {@link Encoder#to()}.
*
* This Codec class can be used in a concurrent environment. The Decoders and
* Encoders, however, must only be used in a single thread.
*
* Will now use hex for encoding byte arrays
*/
public class JSONCodec {
final static String START_CHARACTERS = "[{\"-0123456789tfn";
// Handlers
private final static WeakHashMap handlers = new WeakHashMap<>();
private static StringHandler sh = new StringHandler();
private static BooleanHandler bh = new BooleanHandler();
private static CharacterHandler ch = new CharacterHandler();
private static CollectionHandler dch = new CollectionHandler(ArrayList.class,
Object.class);
private static SpecialHandler sph = new SpecialHandler(Pattern.class, null, null);
private static DateHandler sdh = new DateHandler();
private static FileHandler fh = new FileHandler();
private static ByteArrayHandler byteh = new ByteArrayHandler();
private static UUIDHandler uuidh = new UUIDHandler();
boolean ignorenull;
Map localHandlers = new ConcurrentHashMap<>();
/**
* Create a new Encoder with the state and appropriate API.
*
* @return an Encoder
*/
public Encoder enc() {
return new Encoder(this);
}
/**
* Create a new Decoder with the state and appropriate API.
*
* @return a Decoder
*/
public Decoder dec() {
return new Decoder(this);
}
/*
* Work horse encode methods, all encoding ends up here.
*/
void encode(Encoder app, Object object, Type type, Map