Java Code Examples for org.jboss.marshalling.Unmarshaller#readObject()
The following examples show how to use
org.jboss.marshalling.Unmarshaller#readObject() .
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: MarshallingDecoder.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(frame); try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
Example 2
Source File: MarshallingDecoder.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(frame); try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
Example 3
Source File: CompatibleMarshallingDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); out.add(obj); } catch (LimitingByteInput.TooBigObjectException ignored) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
Example 4
Source File: AbstractCompatibleMarshallingEncoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@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 5
Source File: CounterIO.java From SLP-Core with MIT License | 5 votes |
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 6
Source File: CompatibleMarshallingDecoder.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); out.add(obj); } catch (LimitingByteInput.TooBigObjectException ignored) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
Example 7
Source File: AbstractCompatibleMarshallingEncoderTest.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@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 8
Source File: ProtocolUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static <T> T unmarshal(final Unmarshaller unmarshaller, final Class<T> expectedType) throws IOException { try { return unmarshaller.readObject(expectedType); } catch (ClassNotFoundException e) { throw ProcessLogger.ROOT_LOGGER.failedToReadObject(e); } }