org.jboss.marshalling.Marshalling Java Examples

The following examples show how to use org.jboss.marshalling.Marshalling. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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());
}
 
Example #2
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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());
}
 
Example #3
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #5
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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());
}
 
Example #6
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #7
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #8
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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());
}
 
Example #9
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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());
}
 
Example #10
Source File: CounterIO.java    From SLP-Core with MIT License 5 votes vote down vote up
public static void writeCounter(Counter counter, File file) {
	System.out.println("Writing counter to: " + file);
	try (FileOutputStream os = new FileOutputStream(file)) {
       	final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
           marshaller.start(Marshalling.createByteOutput(os));
           marshaller.writeObject(counter);
           marshaller.finish();
           os.close();
       } catch (IOException e) {
           System.err.print("Marshalling failed: ");
           e.printStackTrace();
       }
}
 
Example #11
Source File: MarshallingCodec.java    From redisson with Apache License 2.0 5 votes vote down vote up
public MarshallingCodec(Protocol protocol, MarshallingConfiguration configuration) {
    this.factory = Marshalling.getProvidedMarshallerFactory(protocol.toString().toLowerCase());
    if (factory == null) {
        throw new IllegalArgumentException(protocol.toString());
    }
    if (configuration == null) {
        configuration = createConfig();
    }
    this.configuration = configuration;
}
 
Example #12
Source File: AbstractCompatibleMarshallingEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshalling() throws IOException, ClassNotFoundException {
    @SuppressWarnings("RedundantStringConstructorCall")
    String testObject = new String("test");

    final MarshallerFactory marshallerFactory = createMarshallerFactory();
    final MarshallingConfiguration configuration = createMarshallingConfig();

    EmbeddedChannel ch = new EmbeddedChannel(createEncoder());

    ch.writeOutbound(testObject);
    assertTrue(ch.finish());

    ByteBuf buffer = (ByteBuf) ch.readOutbound();

    Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
    unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
    String read = (String) unmarshaller.readObject();
    assertEquals(testObject, read);

    assertEquals(-1, unmarshaller.read());

    assertNull(ch.readOutbound());

    unmarshaller.finish();
    unmarshaller.close();
    buffer.release();
}
 
Example #13
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Test
public void testFragmentedUnmarshalling() 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();

    ByteBuf buffer = input(testBytes);
    ByteBuf slice = buffer.readSlice(2);

    ch.writeInbound(slice.retain());
    ch.writeInbound(buffer);
    assertTrue(ch.finish());

    String unmarshalled = (String) ch.readInbound();

    assertEquals(testObject, unmarshalled);

    assertNull(ch.readInbound());
}
 
Example #14
Source File: MarshallingCodeCFactory.java    From fileserver with Apache License 2.0 5 votes vote down vote up
/**
    * 创建Jboss Marshalling编码器MarshallingEncoder
    * 
    * @return
    */
   public static MarshallingEncoder buildMarshallingEncoder() {
final MarshallerFactory marshallerFactory = Marshalling
	.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
MarshallerProvider provider = new DefaultMarshallerProvider(
	marshallerFactory, configuration);
MarshallingEncoder encoder = new MarshallingEncoder(provider);
return encoder;
   }
 
Example #15
Source File: MarshallingCodeCFactory.java    From fileserver with Apache License 2.0 5 votes vote down vote up
/**
    * 创建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;
   }
 
Example #16
Source File: CounterIO.java    From SLP-Core with MIT License 5 votes vote down vote up
public static Counter readCounter(File file) {
	System.out.println("Reading counter from: " + file);
       try (FileInputStream is = new FileInputStream(file)) {
       	final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
           unmarshaller.start(Marshalling.createByteInput(is));
           Counter counter = (Counter) unmarshaller.readObject();
           unmarshaller.finish();
           is.close();
           return counter;
       } catch (IOException | ClassNotFoundException e) {
           System.err.print("Un-marshalling failed: ");
           e.printStackTrace();
       }
	return null;
}
 
Example #17
Source File: MarshallingCodeCFactory.java    From netty-custom-protocol with MIT License 5 votes vote down vote up
/**
   * 创建Jboss Unmarshaller解码对象
   * @return Unmarshaller
   * @throws IOException 
   */
  public static Unmarshaller buildUnMarshalling() throws IOException {
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
return unmarshaller;
  }
 
Example #18
Source File: MarshallingCodeCFactory.java    From netty-custom-protocol with MIT License 5 votes vote down vote up
/**
   * 创建Jboss Marshaller编码对象
   * @return Marshaller
   * @throws IOException 
   */
  public static Marshaller buildMarshalling() throws IOException {
  	//首先通过Marshalling工具类的精通方法获取Marshalling实例对象 参数serial标识创建的是java序列化工厂对象。
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
//创建了MarshallingConfiguration对象,配置了版本号为5 
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
return marshaller;
  }
 
Example #19
Source File: AbstractCompatibleMarshallingEncoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshalling() throws Exception {
    @SuppressWarnings("RedundantStringConstructorCall")
    String testObject = new String("test");

    final MarshallerFactory marshallerFactory = createMarshallerFactory();
    final MarshallingConfiguration configuration = createMarshallingConfig();

    EmbeddedChannel ch = new EmbeddedChannel(createEncoder());

    ch.writeOutbound(testObject);
    assertTrue(ch.finish());

    ByteBuf buffer = ch.readOutbound();

    Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
    unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
    String read = (String) unmarshaller.readObject();
    assertEquals(testObject, read);

    assertEquals(-1, unmarshaller.read());

    assertNull(ch.readOutbound());

    unmarshaller.finish();
    unmarshaller.close();
    buffer.release();
}
 
Example #20
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testFragmentedUnmarshalling() 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();

    ByteBuf buffer = input(testBytes);
    ByteBuf slice = buffer.readRetainedSlice(2);

    ch.writeInbound(slice);
    ch.writeInbound(buffer);
    assertTrue(ch.finish());

    String unmarshalled = ch.readInbound();

    assertEquals(testObject, unmarshalled);

    assertNull(ch.readInbound());
}
 
Example #21
Source File: AbstractMarshallingTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void checkSupported() throws Throwable {
    Throwable error = null;
    try {
        Marshalling.getProvidedMarshallerFactory(SERIAL_FACTORY);
    } catch (Throwable cause) {
        // This may fail on Java 9+ depending on which command-line arguments are used when building.
        if (PlatformDependent.javaVersion() < 9) {
            throw cause;
        }
        error = cause;
    }
    Assume.assumeNoException(error);
}
 
Example #22
Source File: RiverCompatibleMarshallingEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("river");
}
 
Example #23
Source File: SimpleByteDataOutput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SimpleByteDataOutput(final OutputStream outputStream) {
    this.output = new SimpleDataOutput(Marshalling.createByteOutput(outputStream));
}
 
Example #24
Source File: SimpleByteDataInput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SimpleByteDataInput(final InputStream inputStream) {
    this.input = new SimpleDataInput(Marshalling.createByteInput(inputStream));
}
 
Example #25
Source File: ChunkyByteInput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ChunkyByteInput(final InputStream inputStream, final int remaining) {
    input = Marshalling.createByteInput(inputStream);
    this.remaining = remaining;
}
 
Example #26
Source File: ChunkyByteInput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ChunkyByteInput(final InputStream inputStream) {
    input = Marshalling.createByteInput(inputStream);
}
 
Example #27
Source File: SerialCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("serial");
}
 
Example #28
Source File: SerialCompatibleMarshallingEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("serial");
}
 
Example #29
Source File: RiverCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory(RIVER_FACTORY);
}
 
Example #30
Source File: RiverCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("river");
}