本文整理汇总了Java中org.jboss.marshalling.Marshalling类的典型用法代码示例。如果您正苦于以下问题:Java Marshalling类的具体用法?Java Marshalling怎么用?Java Marshalling使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Marshalling类属于org.jboss.marshalling包,在下文中一共展示了Marshalling类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readWithJBossMarshalling
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
private void readWithJBossMarshalling(byte[] bytes, long[] result) throws IOException, ClassNotFoundException {
MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(3);
MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("river");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
long tStart = System.nanoTime();
for (int i = 0; i < NUM_INNER_LOOPS; i++) {
Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
unmarshaller.start(Marshalling.createByteInput(bais));
unmarshaller.readObject();
unmarshaller.finish();
bais.close();
bais.reset();
}
result[0] = System.nanoTime() - tStart;
log.infof("JBoss marshalling read duration = %d ns", result[0]);
}
示例2: testSimpleUnmarshalling
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testSimpleUnmarshalling() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
EmbeddedChannel ch = new EmbeddedChannel(createDecoder(Integer.MAX_VALUE));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
ch.writeInbound(input(testBytes));
assertTrue(ch.finish());
String unmarshalled = (String) ch.readInbound();
assertEquals(testObject, unmarshalled);
assertNull(ch.readInbound());
}
示例3: testTooBigObject
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testTooBigObject() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
ChannelHandler mDecoder = createDecoder(4);
EmbeddedChannel ch = new EmbeddedChannel(mDecoder);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
onTooBigFrame(ch, input(testBytes));
}
示例4: testEqualBuffer
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testEqualBuffer() throws Exception {
final byte[] content = "1234567890".getBytes(StandardCharsets.UTF_8);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);
byteOutput.write(content);
byteOutput.flush();
final byte[] chunked = byteArrayOutputStream.toByteArray();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
byte[] result = new byte[content.length];
byteInput.read(result);
byteInput.close();
Assert.assertArrayEquals(content, result);
Assert.assertEquals(-1, byteInput.read());
}
示例5: testMultiChunk
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testMultiChunk() throws Exception {
final byte[] content = "12345678901234567890123456789012345678901234567890".getBytes(StandardCharsets.UTF_8);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);
byteOutput.write(content);
byteOutput.flush();
final byte[] chunked = byteArrayOutputStream.toByteArray();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
byte[] result = new byte[content.length];
byteInput.read(result);
byteInput.close();
Assert.assertArrayEquals(content, result);
Assert.assertEquals(-1, byteInput.read());
}
示例6: testRemainingBytes
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testRemainingBytes() throws Exception {
final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);
byteOutput.write(content);
byteOutput.flush();
final byte[] chunked = byteArrayOutputStream.toByteArray();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
byte[] result = new byte[content.length];
byteInput.read(result);
byteInput.close();
Assert.assertArrayEquals(content, result);
Assert.assertEquals(-1, byteInput.read());
}
示例7: testIncompleteRead
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testIncompleteRead() throws Exception {
final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);
byteOutput.write(content);
byteOutput.flush();
final byte[] chunked = byteArrayOutputStream.toByteArray();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
int readLength = content.length - 15;
byte[] result = new byte[readLength];
byteInput.read(result);
byteInput.close();
byte[] expected = new byte[readLength];
System.arraycopy(content, 0, expected, 0, readLength);
Assert.assertArrayEquals(expected, result);
Assert.assertEquals(-1, byteInput.read());
}
示例8: testOffsetRead
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testOffsetRead() throws Exception {
final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);
byteOutput.write(content);
byteOutput.flush();
final byte[] chunked = byteArrayOutputStream.toByteArray();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
int readLength = 5;
byte[] result = new byte[content.length];
byteInput.read(result, content.length - 6, readLength);
byteInput.close();
byte[] expected = new byte[content.length];
System.arraycopy(content, 0, expected, content.length - 6, readLength);
Assert.assertArrayEquals(expected, result);
Assert.assertEquals(-1, byteInput.read());
}
示例9: testSimpleUnmarshalling
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
@Test
public void testSimpleUnmarshalling() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
EmbeddedChannel ch = new EmbeddedChannel(createDecoder(Integer.MAX_VALUE));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
ch.writeInbound(input(testBytes));
assertTrue(ch.finish());
String unmarshalled = ch.readInbound();
assertEquals(testObject, unmarshalled);
assertNull(ch.readInbound());
}
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:26,代码来源:AbstractCompatibleMarshallingDecoderTest.java
示例10: writeWithJBossMarshalling
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
private byte[] writeWithJBossMarshalling(User user, long[] result) throws IOException {
MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(3);
MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("river");
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
long tStart = System.nanoTime();
for (int i = 0; i < NUM_INNER_LOOPS; i++) {
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(out));
marshaller.writeObject(user);
marshaller.finish();
out.close();
if (i != NUM_INNER_LOOPS - 1) {
out.reset();
}
}
result[0] = System.nanoTime() - tStart;
log.infof("JBoss Marshalling write duration = %d ns", result[0]);
return out.toByteArray();
}
示例11: buildMarshallingDecoder
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
/**
* 创建Jboss Marshalling解码器MarshallingDecoder
* @return MarshallingDecoder
*/
public static MarshallingDecoder buildMarshallingDecoder() {
//首先通过Marshalling工具类的精通方法获取Marshalling实例对象 参数serial标识创建的是java序列化工厂对象。
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
//创建了MarshallingConfiguration对象,配置了版本号为5
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
//根据marshallerFactory和configuration创建provider
UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory, configuration);
//构建Netty的MarshallingDecoder对象,俩个参数分别为provider和单个消息序列化后的最大长度
MarshallingDecoder decoder = new MarshallingDecoder(provider, 1024);
return decoder;
}
示例12: buildMarshallingEncoder
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
/**
* 创建Jboss Marshalling编码器MarshallingEncoder
* @return MarshallingEncoder
*/
public static MarshallingEncoder buildMarshallingEncoder() {
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory, configuration);
//构建Netty的MarshallingEncoder对象,MarshallingEncoder用于实现序列化接口的POJO对象序列化为二进制数组
MarshallingEncoder encoder = new MarshallingEncoder(provider);
return encoder;
}
示例13: buildMarshallingDecoder
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
/**
* 创建Jboss Marshalling解码器
* @return
*/
public static MarshallingDecoder buildMarshallingDecoder() {
MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");
MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
UnmarshallerProvider provider = new DefaultUnmarshallerProvider(factory, configuration);
MarshallingDecoder decoder = new MarshallingDecoder(provider, 1024);
return decoder;
}
示例14: buildMarshallingEncoder
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
/**
* 创建Jboss Marshalling编码器
* @return
*/
public static MarshallingEncoder buildMarshallingEncoder() {
MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");
MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
MarshallerProvider provider = new DefaultMarshallerProvider(factory, configuration);
MarshallingEncoder encoder = new MarshallingEncoder(provider);
return encoder;
}
示例15: buildMarshallingDecoder
import org.jboss.marshalling.Marshalling; //导入依赖的package包/类
/**
* 创建Jboss Marshalling解码器MarshallingDecoder
*
* @return
*/
public static MarshallingDecoder buildMarshallingDecoder() {
final MarshallerFactory marshallerFactory = Marshalling
.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
UnmarshallerProvider provider = new DefaultUnmarshallerProvider(
marshallerFactory, configuration);
MarshallingDecoder decoder = new MarshallingDecoder(provider, 1024*1024*10);
return decoder;
}