link start!
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.io.ByteBuffer
|
||||
* javax.baja.io.ValueDocDecoder
|
||||
* javax.baja.io.ValueDocDecoder$BogDecoderPlugin
|
||||
* javax.baja.io.ValueDocEncoder
|
||||
* javax.baja.io.ValueDocEncoder$BogEncoderPlugin
|
||||
* javax.baja.sys.BValue
|
||||
* javax.baja.sys.Context
|
||||
* javax.baja.xml.XException
|
||||
* javax.baja.xml.XWriter
|
||||
*/
|
||||
package com.tridium.fox.encoding;
|
||||
|
||||
import com.tridium.fox.encoding.DecoderFactory;
|
||||
import com.tridium.fox.message.FoxMessage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.baja.io.ByteBuffer;
|
||||
import javax.baja.io.ValueDocDecoder;
|
||||
import javax.baja.io.ValueDocEncoder;
|
||||
import javax.baja.sys.BValue;
|
||||
import javax.baja.sys.Context;
|
||||
import javax.baja.xml.XException;
|
||||
import javax.baja.xml.XWriter;
|
||||
|
||||
public final class BogCodec {
|
||||
public static void add(FoxMessage foxMessage, String string, BValue bValue, Context context) throws IOException {
|
||||
ByteBuffer byteBuffer = BogCodec.encode(bValue, context);
|
||||
foxMessage.add(string, "bog", byteBuffer.getBytes(), byteBuffer.getLength());
|
||||
}
|
||||
|
||||
public static ByteBuffer encode(BValue bValue, Context context) throws IOException {
|
||||
ByteBuffer byteBuffer = new ByteBuffer(1024);
|
||||
ValueDocEncoder valueDocEncoder = new ValueDocEncoder(byteBuffer.getOutputStream());
|
||||
XWriter xWriter = ((ValueDocEncoder.BogEncoderPlugin)valueDocEncoder.getPlugin()).getWriter();
|
||||
xWriter.w((Object)"<bog version=\"1.0\"");
|
||||
if (bValue != null) {
|
||||
xWriter.w((Object)">\n");
|
||||
valueDocEncoder.setEncodeTransients(true);
|
||||
valueDocEncoder.setEncodeComments(false);
|
||||
valueDocEncoder.encode(bValue);
|
||||
xWriter.w((Object)"</bog>\n");
|
||||
} else {
|
||||
xWriter.w((Object)"/>\n");
|
||||
}
|
||||
valueDocEncoder.close();
|
||||
return byteBuffer;
|
||||
}
|
||||
|
||||
static class Provider
|
||||
implements DecoderFactory.Provider {
|
||||
Provider() {
|
||||
}
|
||||
|
||||
public Object decode(byte[] byArray, Object object) throws Exception {
|
||||
ValueDocDecoder valueDocDecoder = new ValueDocDecoder((InputStream)new ByteArrayInputStream(byArray));
|
||||
valueDocDecoder.next();
|
||||
if (!valueDocDecoder.elem().name().equals("bog")) {
|
||||
throw new XException("Expected <bog>, not " + valueDocDecoder.elem(), ((ValueDocDecoder.BogDecoderPlugin)valueDocDecoder.getPlugin()).getXmlParser());
|
||||
}
|
||||
valueDocDecoder.next();
|
||||
if (valueDocDecoder.type() == 2) {
|
||||
return null;
|
||||
}
|
||||
return valueDocDecoder.decode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.encoding;
|
||||
|
||||
import com.tridium.fox.encoding.BogCodec;
|
||||
import com.tridium.fox.message.FoxMessage;
|
||||
import com.tridium.fox.message.FoxObject;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DecoderFactory {
|
||||
private static final HashMap providers = new HashMap();
|
||||
|
||||
public static Object decode(FoxMessage foxMessage, String string, Object object) throws Exception {
|
||||
FoxObject foxObject = (FoxObject)foxMessage.get(string);
|
||||
return DecoderFactory.decode(foxObject.encoding, foxObject.data, object);
|
||||
}
|
||||
|
||||
public static Object decode(FoxObject foxObject, Object object) throws Exception {
|
||||
return DecoderFactory.decode(foxObject.encoding, foxObject.data, object);
|
||||
}
|
||||
|
||||
public static Object decode(String string, byte[] byArray, Object object) throws Exception {
|
||||
Provider provider = (Provider)providers.get(string);
|
||||
if (provider != null) {
|
||||
return provider.decode(byArray, object);
|
||||
}
|
||||
throw new IOException("Unknown object encoding: " + string);
|
||||
}
|
||||
|
||||
public static void register(String string, Provider provider) {
|
||||
providers.put(string, provider);
|
||||
}
|
||||
|
||||
public static void unregister(String string) {
|
||||
providers.remove(string);
|
||||
}
|
||||
|
||||
static {
|
||||
DecoderFactory.register("bog", new BogCodec.Provider());
|
||||
}
|
||||
|
||||
public static interface Provider {
|
||||
public Object decode(byte[] var1, Object var2) throws Exception;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user