本文整理了Java中org.jboss.marshalling.Marshalling
类的一些代码示例,展示了Marshalling
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marshalling
类的具体详情如下:
包路径:org.jboss.marshalling.Marshalling
类名称:Marshalling
[英]Static utility methods for simplifying use of marshallers.
[中]简化编组机使用的静态实用方法。
代码示例来源:origin: wildfly/wildfly
/**
* {@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;
}
代码示例来源: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
Common(Channel channel) {
marshallerFactory = Marshalling.getProvidedMarshallerFactory(MARSHALLING_STRATEGY);
if (marshallerFactory == null) {
throw new RuntimeException("Could not find a marshaller factory for " + MARSHALLING_STRATEGY
+ " marshalling strategy");
}
this.channel = channel;
}
代码示例来源: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: org.jboss.as/jboss-as-server
final MarshallerFactory factory = Marshalling.getMarshallerFactory("river", DomainServerMain.class.getClassLoader());
final Unmarshaller unmarshaller;
final ByteInput byteInput;
configuration.setVersion(2);
configuration.setClassResolver(new SimpleClassResolver(DomainServerMain.class.getClassLoader()));
unmarshaller = factory.createUnmarshaller(configuration);
byteInput = Marshalling.createByteInput(initialInput);
unmarshaller.start(byteInput);
final ServerTask task = unmarshaller.readObject(ServerTask.class);
unmarshaller.finish();
containerFuture = task.run(Arrays.<ServiceActivator>asList(new ServiceActivator() {
@Override
代码示例来源: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: org.jboss.as/jboss-as-domain-client
@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;
}
}
代码示例来源:origin: org.jboss.as/jboss-as-clustering-impl
/**
* Serializes an object into a byte buffer. The object has to implement interface Serializable or Externalizable
*/
byte[] objectToByteBufferInternal(Object object) throws Exception {
Marshaller marshaller = marshallerFactory.createMarshaller(this.marshallingConfig);
ByteArrayOutputStream output = new ByteArrayOutputStream();
marshaller.start(Marshalling.createByteOutput(output));
marshaller.writeObject(object);
marshaller.close();
return output.toByteArray();
}
代码示例来源:origin: wildfly/wildfly
final SecurityIdentity identity;
if (version >= 3) {
unmarshaller = marshallerFactory.createUnmarshaller(configuration);
unmarshaller.start(Marshalling.createByteInput(input));
identifier = unmarshaller.readObject(EJBIdentifier.class);
methodLocator = unmarshaller.readObject(EJBMethodLocator.class);
int identityId = unmarshaller.readInt();
identity = identityId == 0 ? connection.getLocalIdentity() : connection.getLocalIdentity(identityId);
unmarshaller = marshallerFactory.createUnmarshaller(configuration);
unmarshaller.start(Marshalling.createByteInput(data));
String appName = unmarshaller.readObject(String.class);
String moduleName = unmarshaller.readObject(String.class);
代码示例来源: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
@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();
}
}
}
}
代码示例来源:origin: wildfly/wildfly
public static Unmarshaller createUnmarshaller(MessageInputStream is, MarshallingConfiguration configuration) throws IOException {
final Unmarshaller unmarshaller = riverMarshallerFactory.createUnmarshaller(configuration);
unmarshaller.start(Marshalling.createByteInput(is));
return unmarshaller;
}
代码示例来源: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
/**
* 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;
}
代码示例来源:origin: wuyinxian124/nettybook2
/**
* 创建Jboss Unmarshaller
*
* @return
* @throws IOException
*/
protected static Unmarshaller buildUnMarshalling() throws IOException {
final MarshallerFactory marshallerFactory = Marshalling
.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
final Unmarshaller unmarshaller = marshallerFactory
.createUnmarshaller(configuration);
return unmarshaller;
}
}
代码示例来源:origin: wuyinxian124/nettybook2
/**
* 创建Jboss Marshaller
*
* @return
* @throws IOException
*/
protected static Marshaller buildMarshalling() throws IOException {
final MarshallerFactory marshallerFactory = Marshalling
.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
Marshaller marshaller = marshallerFactory
.createMarshaller(configuration);
return marshaller;
}
代码示例来源:origin: wildfly/wildfly
/**
* 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));
}
代码示例来源: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
/**
* Read bytes from a {@code ByteInput}. Fully fills in the array.
*
* @param input the input
* @param dest the destination
* @throws EOFException if the end of file is reached before the array is filled
* @throws IOException if an I/O error occurs
*/
public static void readFully(ByteInput input, byte[] dest) throws IOException {
readFully(input, dest, 0, dest.length);
}
代码示例来源:origin: wildfly/wildfly
private Object readObject(boolean unshared) throws ClassNotFoundException, IOException {
if (remaining > 0) {
throw createOptionalDataException(remaining);
} else if (remaining == -1) {
throw createOptionalDataException(true);
}
final int leadByte = riverUnmarshaller.read();
if (leadByte == -1 || leadByte == Protocol.ID_END_BLOCK_DATA) {
remaining = -1;
throw createOptionalDataException(true);
}
return riverUnmarshaller.doReadObject(leadByte, unshared, false);
}
内容来源于网络,如有侵权,请联系作者删除!