本文整理汇总了Java中org.msgpack.packer.Packer.write方法的典型用法代码示例。如果您正苦于以下问题:Java Packer.write方法的具体用法?Java Packer.write怎么用?Java Packer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.packer.Packer
的用法示例。
在下文中一共展示了Packer.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeCall
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
protected void writeCall(String methodName, Object[] args) throws IOException {
huc = u.openConnection();
huc.setDoOutput(true);
huc.setDoInput(true);
huc.setUseCaches(false);
huc.setRequestProperty("Content-Type", "binary/message-pack");
huc.setReadTimeout(0);
OutputStream os = huc.getOutputStream();
Packer pk = msgpack.createPacker(os);
pk.writeArrayBegin(args.length+1);
pk.write(methodName);
for (Object arg : args)
pk.write(arg);
pk.writeArrayEnd();
pk.close();
os.close();
}
示例2: testDouble
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void testDouble(double v) throws Exception {
MessagePack msgpack = new JSON();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
if(((Double)v).isInfinite() || ((Double)v).isNaN()) {
try {
packer.write(v);
fail("JSONPacker should reject infinite and NaN value");
} catch (IOException ex) {
assertTrue(ex instanceof IOException);
}
return;
}
packer.write(v);
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
double ret = unpacker.readDouble();
assertEquals(v, ret, 10e-10);
}
示例3: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void write(Packer pk, Object v, boolean required) throws IOException {
if (v == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write(v);
}
示例4: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer pk, Object v, boolean required) throws IOException {
if (v == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
pk.write(v);
}
示例5: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer paramPacker, Object paramT, boolean paramBoolean)
throws IOException {
if(paramT==null) {
if(paramBoolean) {
throw new MessageTypeException("Attempted to write null");
}
paramPacker.writeNil();
return;
} else {
paramPacker.write(paramT);
}
}
示例6: write
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void write(Packer paramPacker, T paramT, boolean paramBoolean)
throws IOException {
if(paramT==null) {
if(paramBoolean) {
throw new MessageTypeException("Attempted to write null");
}
paramPacker.writeNil();
return;
} else {
Field[] fields = paramT.getClass().getFields();
paramPacker.writeMapBegin(fields.length);
for(Field field:fields) {
int mod = field.getModifiers();
if(Modifier.isPublic(mod) && !Modifier.isStatic(mod) && !Modifier.isTransient(mod)) {
try {
CompressField cfield;
if (isCompress && (cfield = field.getAnnotation(CompressField.class)) != null) {
// if compress option is true, serialize field name to integer
paramPacker.write(cfield.value());
} else {
paramPacker.write(field.getName());
}
paramPacker.write(field.get(paramT));
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new MessageTypeException("Illegal Exception");
}
}
}
paramPacker.writeMapEnd(paramBoolean);
}
}
示例7: main
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Order order = new Order();
order.id = 1L;
order.name = "ss";
Order order1 = new Order();
order1.id = 2L;
order1.name = "ss";
MessagePack messagePack = new MessagePack();
//序列化
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Packer packer = messagePack.createPacker(byteArrayOutputStream);
packer.write(order);
packer.write(order1);
byte[] raw = byteArrayOutputStream.toByteArray();
// System.out.println("ss:" + raw.length);
//反序列化
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(raw);
Unpacker unpacker = messagePack.createUnpacker(byteArrayInputStream);
Order destOrder = unpacker.read(Order.class);
Order destOrder2 = unpacker.read(Order.class);
System.out.println(destOrder.id + ":" + destOrder.name);
System.out.println(destOrder2.id + ":" + destOrder2.name);
}
示例8: writeTo
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
public void writeTo(Packer pk) throws IOException {
pk.writeArrayBegin(3);
pk.write(Messages.NOTIFY);
pk.write(method);
pk.writeArrayBegin(args.length);
for (Object arg : args) {
pk.write(arg);
}
pk.writeArrayEnd();
pk.writeArrayEnd();
}
示例9: testSample
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Test
public void testSample() throws Exception {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.write(1);
packer.write(2);
packer.write(3);
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(
new ByteArrayInputStream(bytes));
UnpackerIterator iter = unpacker.iterator();
unpacker.resetReadByteCount();
iter.hasNext();
iter.next();
assertEquals(1, unpacker.getReadByteCount());
unpacker.resetReadByteCount();
iter.hasNext();
iter.next();
assertEquals(1, unpacker.getReadByteCount());
unpacker.resetReadByteCount();
iter.hasNext();
iter.next();
assertEquals(1, unpacker.getReadByteCount());
}
示例10: testBoolean
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void testBoolean(boolean v) throws Exception {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.write(v);
byte[] bytes = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Unpacker unpacker = msgpack.createUnpacker(in);
unpacker.resetReadByteCount();
boolean ret = unpacker.readBoolean();
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例11: testByte
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void testByte(byte v) throws Exception {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.write(v);
byte[] bytes = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Unpacker unpacker = msgpack.createUnpacker(in);
unpacker.resetReadByteCount();
byte ret = unpacker.readByte();
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例12: packData
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
protected void packData(Packer packer) throws IOException {
packer.writeArrayBegin(data.size());
for(String dataRecord : data) {
packer.write(dataRecord);
}
packer.writeArrayEnd(true);
}
示例13: testLong
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void testLong(long v) throws Exception {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.write(v);
byte[] bytes = out.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
unpacker.resetReadByteCount();
Value value = unpacker.readValue();
assertTrue(value.isIntegerValue());
long ret = new Converter(value).readLong();
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例14: testString
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void testString(String v) throws Exception {
MessagePack msgpack = new MessagePack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.write(v);
byte[] bytes = out.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
String ret = unpacker.read(String.class);
assertEquals(v, ret);
assertEquals(bytes.length, unpacker.getReadByteCount());
}
示例15: testByte
import org.msgpack.packer.Packer; //导入方法依赖的package包/类
@Override
public void testByte(byte v) throws Exception {
MessagePack msgpack = new JSON();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Packer packer = msgpack.createPacker(out);
packer.write(v);
byte[] bytes = out.toByteArray();
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(bytes));
byte ret = unpacker.readByte();
assertEquals(v, ret);
}