org.jboss.marshalling.Marshalling.createByteOutput()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.jboss.marshalling.Marshalling.createByteOutput()方法的一些代码示例,展示了Marshalling.createByteOutput()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marshalling.createByteOutput()方法的具体详情如下:
包路径:org.jboss.marshalling.Marshalling
类名称:Marshalling
方法名:createByteOutput

Marshalling.createByteOutput介绍

[英]Create a ByteOutput wrapper for an OutputStream.
[中]为OutputStream创建字节输出包装器。

代码示例

代码示例来源:origin: wildfly/wildfly

StepObjectOutput(final Queue<Step> steps) throws IOException {
  super(SerializingCloner.this.bufferSize);
  this.steps = steps;
  super.start(Marshalling.createByteOutput(byteArrayOutputStream));
}

代码示例来源:origin: wildfly/wildfly

/**
 * 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);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Creates and returns a {@link org.jboss.marshalling.Marshaller} which is ready to be used for marshalling. The
 * {@link org.jboss.marshalling.Marshaller#start(org.jboss.marshalling.ByteOutput)} will be invoked by this method, to use
 * the passed {@link java.io.DataOutput dataOutput}, before returning the marshaller.
 *
 * @param dataOutput The {@link java.io.DataOutput} to which the data will be marshalled
 * @return
 * @throws IOException
 */
protected org.jboss.marshalling.Marshaller prepareForMarshalling(final DataOutput dataOutput) throws IOException {
  final org.jboss.marshalling.Marshaller marshaller = this.getMarshaller(marshallerFactory);
  final OutputStream outputStream = new OutputStream() {
    @Override
    public void write(int b) throws IOException {
      final int byteToWrite = b & 0xff;
      dataOutput.write(byteToWrite);
    }
  };
  final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream);
  // start the marshaller
  marshaller.start(byteOutput);
  return marshaller;
}

代码示例来源:origin: wildfly/wildfly

final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream);

代码示例来源:origin: wildfly/wildfly

@Override
public void objectToStream(Object object, DataOutput stream) throws Exception {
  int version = this.context.getCurrentVersion();
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  try (DataOutputStream output = new DataOutputStream(bytes)) {
    this.versionSerializer.writeInt(output, version);
    try (Marshaller marshaller = this.context.createMarshaller(version)) {
      marshaller.start(Marshalling.createByteOutput(output));
      marshaller.writeObject(object);
      marshaller.flush();
    }
  }
  byte[] buffer = bytes.toByteArray();
  IndexSerializer.VARIABLE.writeInt(stream, buffer.length);
  stream.write(buffer);
}

代码示例来源:origin: wildfly/wildfly

@Override
  public <R> byte[] marshal(Command<R, ? super C> command) throws IOException {
    int version = this.context.getCurrentVersion();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    try (DataOutputStream output = new DataOutputStream(bytes)) {
      IndexSerializer.VARIABLE.writeInt(output, version);
      try (Marshaller marshaller = this.context.createMarshaller(version)) {
        marshaller.start(Marshalling.createByteOutput(output));
        marshaller.writeObject(this.id);
        marshaller.writeObject(command);
        marshaller.flush();
      }
      return bytes.toByteArray();
    }
  }
}

代码示例来源:origin: wildfly/wildfly

if (object != null) {
  Marshaller marshaller = targetContext.createMarshaller(createMarshallingConfig(providerUri));
  marshaller.start(Marshalling.createByteOutput(output));
  marshaller.writeObject(object);
  marshaller.finish();

代码示例来源:origin: wildfly/wildfly

byte[] getBytes() throws IOException {
  byte[] bytes = this.bytes;
  if (bytes != null) return bytes;
  if (this.object == null) return null;
  int version = this.context.getCurrentVersion();
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader());
  try (SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output))) {
    IndexSerializer.VARIABLE.writeInt(data, version);
    try (Marshaller marshaller = this.context.createMarshaller(version)) {
      marshaller.start(data);
      marshaller.writeObject(this.object);
      marshaller.finish();
      return output.toByteArray();
    }
  } finally {
    setThreadContextClassLoader(loader);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
    public void writeInvocationResult(Object result) {
      if(identifier != null) {
        cancellationFlags.remove(identifier);
      }
      try {
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, EjbHeaders.EJB_RESPONSE_VERSION_ONE.toString());
//                                    if (output.getSessionAffinity() != null) {
//                                        exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", output.getSessionAffinity()).setPath(WILDFLY_SERVICES));
//                                    }
        final Marshaller marshaller = HttpServerHelper.RIVER_MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration);
        OutputStream outputStream = exchange.getOutputStream();
        final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream));
        // start the marshaller
        marshaller.start(byteOutput);
        marshaller.writeObject(result);
        // TODO: Do we really need to send this back?
        PackedInteger.writePackedInteger(marshaller, contextData.size());
        for(Map.Entry<String, Object> entry : contextData.entrySet()) {
          marshaller.writeObject(entry.getKey());
          marshaller.writeObject(entry.getValue());
        }
        marshaller.finish();
        marshaller.flush();
        exchange.endExchange();
      } catch (Exception e) {
        HttpServerHelper.sendException(exchange, 500, e);
      }
    }
  }

代码示例来源:origin: wildfly/wildfly

public static void sendException(HttpServerExchange exchange, int status, Throwable e) {
    try {
      exchange.setStatusCode(status);
      exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jbmar-exception;version=1");

      final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
      marshallingConfiguration.setVersion(2);
      final Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration);
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream));
      // start the marshaller
      marshaller.start(byteOutput);
      marshaller.writeObject(e);
      marshaller.write(0);
      marshaller.finish();
      marshaller.flush();
      exchange.getResponseSender().send(ByteBuffer.wrap(outputStream.toByteArray()));
    } catch (IOException e1) {
      HttpRemoteTransactionMessages.MESSAGES.debugf(e, "Failed to write exception");
    }
  }
}

代码示例来源:origin: wildfly/wildfly

targetContext.sendRequest(cr, sslContext, authenticationConfiguration, output -> {
  Marshaller marshaller = targetContext.createMarshaller(HttpRemoteTransactionPeer.createMarshallingConf());
  marshaller.start(Marshalling.createByteOutput(output));
  marshaller.writeInt(id.getFormatId());
  final byte[] gtid = id.getGlobalTransactionId();

代码示例来源:origin: wildfly/wildfly

private static void doMarshall(HttpServerExchange exchange, Object result) throws IOException {
  exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jndi-jbmar-value;version=1");
  final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
  marshallingConfiguration.setVersion(2);
  Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration);
  marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(exchange.getOutputStream())));
  marshaller.writeObject(result);
  marshaller.finish();
}

代码示例来源:origin: wildfly/wildfly

private void writeFailedResponse(final int invId, final Throwable e) {
  try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) {
    os.writeByte(Protocol.APPLICATION_EXCEPTION);
    os.writeShort(invId);
    final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os)));
    marshaller.writeObject(new RequestSendFailedException(e.getMessage() + "@" + channel.getConnection().getPeerURI(), e));
    marshaller.writeByte(0);
    marshaller.finish();
  } catch (IOException e2) {
    // nothing to do at this point; the client doesn't want the response
    Logs.REMOTING.trace("EJB response write failed", e2);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
  public void handleRequest(HttpServerExchange exchange) throws Exception {
    try {
      String timeoutString = exchange.getRequestHeaders().getFirst(TransactionConstants.TIMEOUT);
      if (timeoutString == null) {
        exchange.setStatusCode(StatusCodes.BAD_REQUEST);
        HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s is missing %s header", exchange, TransactionConstants.TIMEOUT);
        return;
      }
      final Integer timeout = Integer.parseInt(timeoutString);
      exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, TransactionConstants.NEW_TRANSACTION.toString());
      final LocalTransaction transaction = transactionContext.beginTransaction(timeout);
      final Xid xid = xidResolver.apply(transaction);
      final ByteArrayOutputStream out = new ByteArrayOutputStream();
      Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf());
      marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out)));
      marshaller.writeInt(xid.getFormatId());
      marshaller.writeInt(xid.getGlobalTransactionId().length);
      marshaller.write(xid.getGlobalTransactionId());
      marshaller.writeInt(xid.getBranchQualifier().length);
      marshaller.write(xid.getBranchQualifier());
      marshaller.finish();
      exchange.getResponseSender().send(ByteBuffer.wrap(out.toByteArray()));
    } catch (Exception e) {
      sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

public static void sendException(HttpServerExchange exchange, int status, Throwable e) throws IOException {
    exchange.setStatusCode(status);
    exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jbmar-exception;version=1");

    final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
    marshallingConfiguration.setVersion(2);
    final Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration);
    OutputStream outputStream = exchange.getOutputStream();
    final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream));
    // start the marshaller
    marshaller.start(byteOutput);
    marshaller.writeObject(e);
    marshaller.write(0);
    marshaller.finish();
    marshaller.flush();
  }
}

代码示例来源:origin: wildfly/wildfly

protected void writeFailure(Exception reason) {
  try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) {
    os.writeByte(Protocol.APPLICATION_EXCEPTION);
    os.writeShort(invId);
    if (version >= 3) os.writeByte(getEnlistmentStatus());
    final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os)));
    marshaller.writeObject(reason);
    marshaller.writeByte(0);
    marshaller.finish();
  } catch (IOException e) {
    // nothing to do at this point; the client doesn't want the response
    Logs.REMOTING.trace("EJB response write failed", e);
  } finally {
    invocations.removeKey(invId);
  }
}

代码示例来源:origin: wildfly/wildfly

final ByteArrayOutputStream out = new ByteArrayOutputStream();
Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf());
marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out)));
marshaller.writeInt(recoveryList.length);
for (int i = 0; i < recoveryList.length; ++i) {

代码示例来源:origin: wildfly/wildfly

public static void sendException(HttpServerExchange exchange, int status, Throwable e) {
    try {
      exchange.setStatusCode(status);
      exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jbmar-exception;version=1");
      final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
      marshallingConfiguration.setVersion(2);
      final Marshaller marshaller = RIVER_MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration);
      OutputStream outputStream = exchange.getOutputStream();
      final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream);
      // start the marshaller
      marshaller.start(byteOutput);
      marshaller.writeObject(e);
      marshaller.write(0);
      marshaller.finish();
      marshaller.flush();
      exchange.endExchange();
    } catch (Exception ex) {
      HttpClientMessages.MESSAGES.failedToWriteException(ex);
      exchange.endExchange();
    }
  }
}

代码示例来源:origin: wildfly/wildfly

public void writeWrongViewType() {
  final String message = Logs.REMOTING.remoteMessageBadViewType(getEJBIdentifier());
  try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) {
    if (version >= 3) {
      os.writeByte(Protocol.BAD_VIEW_TYPE);
      os.writeShort(invId);
      os.writeUTF(message);
    } else {
      os.writeByte(Protocol.APPLICATION_EXCEPTION);
      os.writeShort(invId);
      final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
      marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os)));
      marshaller.writeObject(Logs.REMOTING.invalidViewTypeForInvocation(message));
      marshaller.writeByte(0);
      marshaller.finish();
    }
  } catch (IOException e) {
    // nothing to do at this point; the client doesn't want the response
    Logs.REMOTING.trace("EJB response write failed", e);
  } finally {
    invocations.removeKey(invId);
  }
}

代码示例来源:origin: wildfly/wildfly

void handleTxnRecoverRequest(final int invId, final MessageInputStream message) throws IOException {
  final String parentName = message.readUTF();
  final int flags = message.readInt();
  final Xid[] xids;
  try {
    xids = transactionServer.getTransactionService().getTransactionContext().getRecoveryInterface().recover(flags, parentName);
  } catch (XAException e) {
    writeFailedResponse(invId, e);
    return;
  }
  try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) {
    os.writeByte(Protocol.TXN_RECOVERY_RESPONSE);
    os.writeShort(invId);
    PackedInteger.writePackedInteger(os, xids.length);
    final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os)));
    for (Xid xid : xids) {
      marshaller.writeObject(new XidTransactionID(xid));
    }
    marshaller.finish();
  } catch (IOException e) {
    // nothing to do at this point; the client doesn't want the response
    Logs.REMOTING.trace("EJB transaction response write failed", e);
  }
}

相关文章