当前位置: 首页>>代码示例>>Java>>正文


Java Packer.write方法代码示例

本文整理汇总了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();
}
 
开发者ID:Android-leak,项目名称:csploit,代码行数:18,代码来源:RPCClient.java

示例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);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:21,代码来源:TestJSONPackUnpack.java

示例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);
}
 
开发者ID:weibocom,项目名称:yar-java,代码行数:11,代码来源:MsgpackPackager.java

示例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);
}
 
开发者ID:vongosling,项目名称:jvm-serializer,代码行数:12,代码来源:ObjectTemplate.java

示例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);
	}

}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:15,代码来源:ObjectTemplate.java

示例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);
	}
}
 
开发者ID:ksgwr,项目名称:MessagePackTemplate,代码行数:33,代码来源:MapObjectTemplate.java

示例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);

    }
 
开发者ID:krisjin,项目名称:bscl,代码行数:29,代码来源:MultipleObjectSerialize.java

示例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();
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:12,代码来源:NotifyMessage.java

示例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());
}
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:28,代码来源:TestUnpackerIterator.java

示例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());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:15,代码来源:TestPackUnpack.java

示例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());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:15,代码来源:TestPackUnpack.java

示例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);
}
 
开发者ID:sunsus,项目名称:socket.io-java-emitter,代码行数:8,代码来源:PacketText.java

示例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());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:16,代码来源:TestPackConvert.java

示例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());
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:13,代码来源:TestPackBufferUnpack.java

示例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);
   }
 
开发者ID:nict-wisdom,项目名称:rasc,代码行数:12,代码来源:TestJSONPackUnpack.java


注:本文中的org.msgpack.packer.Packer.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。