/** * Construct a new instance which delegates to the given unmarshaller, reading from the given input. The unmarshaller * will read from the input stream until it is closed. * * @param unmarshaller the delegate unmarshaller * @param stream the input stream to read from * * @throws java.io.IOException if an I/O error occurs * @throws SecurityException if the caller does not have permission to construct an instance of this class */ public UnmarshallingObjectInputStream(final Unmarshaller unmarshaller, final InputStream stream) throws IOException, SecurityException { this(unmarshaller, Marshalling.createByteInput(stream)); }
/** * Construct a new instance. */ public BytePipe() { final PipedOutputStream output = new PipedOutputStream(); final PipedInputStream input; try { input = new PipedInputStream(output); } catch (IOException e) { throw new IllegalStateException(e); } this.input = Marshalling.createByteInput(input); this.output = Marshalling.createByteOutput(output); }
public static Unmarshaller createUnmarshaller(MessageInputStream is, MarshallingConfiguration configuration) throws IOException { final Unmarshaller unmarshaller = riverMarshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(is)); return unmarshaller; }
@Override public Object objectFromStream(DataInput stream) throws Exception { int size = IndexSerializer.VARIABLE.readInt(stream); byte[] buffer = new byte[size]; stream.readFully(buffer); if (this.factory.isUnknownForkResponse(ByteBuffer.wrap(buffer))) return NoSuchService.INSTANCE; try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(buffer))) { int version = this.versionSerializer.readInt(input); try (Unmarshaller unmarshaller = this.context.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); return unmarshaller.readObject(); } } } }
/** * Creates and returns a {@link org.jboss.marshalling.Unmarshaller} which is ready to be used for unmarshalling. The * {@link org.jboss.marshalling.Unmarshaller#start(org.jboss.marshalling.ByteInput)} will be invoked by this method, to use * the passed {@link java.io.DataInput dataInput}, before returning the unmarshaller. * * @param dataInput The data input from which to unmarshall * @param classResolver The class resolver to use for unmarshalling * @return * @throws IOException */ protected Unmarshaller prepareForUnMarshalling(final DataInput dataInput, final ClassResolver classResolver) throws IOException { final Unmarshaller unmarshaller = this.getUnMarshaller(marshallerFactory, classResolver); final InputStream is = new InputStream() { @Override public int read() throws IOException { try { final int b = dataInput.readByte(); return b & 0xff; } catch (EOFException eof) { return -1; } } }; final ByteInput byteInput = Marshalling.createByteInput(is); // start the unmarshaller unmarshaller.start(byteInput); return unmarshaller; }
/** * Creates and returns a {@link org.jboss.marshalling.Unmarshaller} which is ready to be used for unmarshalling. The * {@link org.jboss.marshalling.Unmarshaller#start(org.jboss.marshalling.ByteInput)} will be invoked by this method, to use * the passed {@link java.io.DataInput dataInput}, before returning the unmarshaller. * * @param dataInput The data input from which to unmarshall * @param classResolver The class resolver to use for unmarshalling * @return * @throws IOException */ protected Unmarshaller prepareForUnMarshalling(final DataInput dataInput, final ClassResolver classResolver) throws IOException { final Unmarshaller unmarshaller = this.getUnMarshaller(marshallerFactory, classResolver); final InputStream is = new InputStream() { @Override public int read() throws IOException { try { final int b = dataInput.readByte(); return b & 0xff; } catch (EOFException eof) { return -1; } } }; final ByteInput byteInput = Marshalling.createByteInput(is); // start the unmarshaller unmarshaller.start(byteInput); return unmarshaller; }
private Callable<Object> read(Message message) throws Exception { try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(message.getRawBuffer(), message.getOffset(), message.getLength()))) { int version = IndexSerializer.VARIABLE.readInt(input); try (Unmarshaller unmarshaller = this.marshallingContext.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); Object clientId = unmarshaller.readObject(); Optional<Object> context = this.contexts.get(clientId); if (context == null) return () -> NoSuchService.INSTANCE; @SuppressWarnings("unchecked") Command<Object, Object> command = (Command<Object, Object>) unmarshaller.readObject(); // Wrap execution result in an Optional, since command execution might return null ExceptionSupplier<Optional<Object>, Exception> task = () -> Optional.ofNullable(command.execute(context.orElse(null))); return () -> this.executor.execute(task).orElse(Optional.of(NoSuchService.INSTANCE)).orElse(null); } } }
/** * {@inheritDoc} * @see org.wildfly.clustering.marshalling.spi.MarshalledValue#get(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public synchronized T get(MarshallingContext context) throws IOException, ClassNotFoundException { if (this.object == null) { this.context = context; if (this.bytes != null) { ByteArrayInputStream input = new ByteArrayInputStream(this.bytes); ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader()); try (SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input))) { int version = IndexSerializer.VARIABLE.readInt(data); try (Unmarshaller unmarshaller = context.createUnmarshaller(version)) { unmarshaller.start(data); this.object = (T) unmarshaller.readObject(); unmarshaller.finish(); this.bytes = null; // Free up memory } } finally { setThreadContextClassLoader(loader); } } } return this.object; }
if (version >= 3) { unmarshaller = marshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(input)); identifier = unmarshaller.readObject(EJBIdentifier.class); methodLocator = unmarshaller.readObject(EJBMethodLocator.class); unmarshaller.start(Marshalling.createByteInput(data)); String appName = unmarshaller.readObject(String.class); String moduleName = unmarshaller.readObject(String.class);
static XAException readAppException(final EJBClientChannel channel, final BlockingInvocation.Response response) throws XAException { Exception e; try (final Unmarshaller unmarshaller = channel.createUnmarshaller()) { try (MessageInputStream inputStream = response.getInputStream()) { unmarshaller.start(Marshalling.createByteInput(inputStream)); e = unmarshaller.readObject(Exception.class); unmarshaller.finish(); // The version is probably < 3 else we would not be here // drain off attachments so the server doesn't complain while (inputStream.read() != -1) { inputStream.skip(Long.MAX_VALUE); } } } catch (IOException | ClassNotFoundException e1) { throw new XAException(XAException.XAER_RMERR); } if (e == null) { throw new XAException(XAException.XAER_RMFAIL); } try { throw e; } catch (RuntimeException | XAException e1) { throw e1; } catch (Exception e1) { final XAException xae = new XAException(XAException.XAER_RMERR); xae.initCause(e1); return xae; } }
static SystemException readAppException(final EJBClientChannel channel, final BlockingInvocation.Response response) throws SystemException { Exception e; try (final Unmarshaller unmarshaller = channel.createUnmarshaller()) { try (MessageInputStream inputStream = response.getInputStream()) { unmarshaller.start(Marshalling.createByteInput(inputStream)); e = unmarshaller.readObject(Exception.class); unmarshaller.finish(); // The version is probably < 3 else we would not be here // drain off attachments so the server doesn't complain while (inputStream.read() != -1) { inputStream.skip(Long.MAX_VALUE); } } } catch (IOException | ClassNotFoundException e1) { throw new SystemException(); } if (e == null) { throw new SystemException(); } try { throw e; } catch (RuntimeException | SystemException e1) { throw e1; } catch (Exception e1) { final SystemException e2 = new SystemException(); e2.initCause(e1); return e2; } }
unmarshaller.start(Marshalling.createByteInput(inputStream)); for (int i = 0; i < count; i ++) { xids[i ++] = unmarshaller.readObject(XidTransactionID.class).getXid();
public static Unmarshaller createUnmarshaller(MessageInputStream is, MarshallingConfiguration configuration) throws IOException { final Unmarshaller unmarshaller = riverMarshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(is)); return unmarshaller; }
@Override protected final DomainUpdateApplierResponse receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_UPDATE); DomainUpdateApplierResponse rsp = unmarshal(unmarshaller, DomainUpdateApplierResponse.class); unmarshaller.finish(); return rsp; } }
@Override protected final DomainModel receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_DOMAIN_MODEL); final DomainModel domainModel = unmarshal(unmarshaller, DomainModel.class); unmarshaller.finish(); return domainModel; } }
@Override protected final ServerModel receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_MODEL); final ServerModel serverModel = unmarshal(unmarshaller, ServerModel.class); unmarshaller.finish(); return serverModel; } }
/** {@inheritDoc} */ @Override protected ServerModel receiveResponse(InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, StandaloneClientProtocol.PARAM_SERVER_MODEL); final ServerModel serverModel = unmarshal(unmarshaller, ServerModel.class); unmarshaller.finish(); return serverModel; } }
@Override final public ObjectInput startObjectInput(final InputStream is, final boolean isReentrant) throws IOException { PerThreadInstanceHolder instanceHolder = getPerThreadInstanceHolder(); Unmarshaller unmarshaller = instanceHolder.getUnmarshaller(); if (trace) log.tracef("Start unmarshaller after retrieving marshaller from %s", isReentrant ? "factory" : "thread local"); unmarshaller.start(Marshalling.createByteInput(is)); return unmarshaller; }
@Override protected final ServerStatus receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_STATUS); final ServerStatus serverStatus = unmarshal(unmarshaller, ServerStatus.class); unmarshaller.finish(); return serverStatus; } }
/** {@inheritDoc} */ @Override protected final ServerDeploymentPlanResult receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, StandaloneClientProtocol.PARAM_DEPLOYMENT_PLAN_RESULT); final ServerDeploymentPlanResult result = unmarshal(unmarshaller, ServerDeploymentPlanResult.class); unmarshaller.finish(); return result; } }