use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class RmiSerializer method writeType.
private void writeType(ByteBuffer buffer, Class<?> clazz) throws IOException {
if (clazz == void.class) {
buffer.putShort((short) 0);
} else {
SerializerRegistration reg = Serializer.getSerializerRegistration(clazz);
if (reg == null) {
logger.log(Level.WARNING, "Unknown class: {0}", clazz);
// prevents message from being serialized
throw new IOException();
}
buffer.putShort(reg.getId());
}
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class KernelAdapter method createAndDispatch.
protected void createAndDispatch(Envelope env) {
MessageProtocol protocol = getMessageBuffer(env.getSource());
byte[] data = env.getData();
ByteBuffer buffer = ByteBuffer.wrap(data);
int count = protocol.addBuffer(buffer);
if (count == 0) {
// connections.
if (!reliable) {
// Log some additional information about the packet.
int len = Math.min(10, data.length);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
sb.append("[" + Integer.toHexString(data[i]) + "]");
}
log.log(Level.FINE, "First 10 bytes of incomplete nessage:" + sb);
throw new RuntimeException("Envelope contained incomplete data:" + env);
}
}
// Should be complete... and maybe we should check but we don't
Message m = null;
while ((m = protocol.getMessage()) != null) {
m.setReliable(reliable);
dispatch(env.getSource(), m);
}
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class ZIPSerializer method readObject.
@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
try {
ZIPCompressedMessage result = new ZIPCompressedMessage();
byte[] byteArray = new byte[data.remaining()];
data.get(byteArray);
ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(byteArray));
in.getNextEntry();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] tmp = new byte[9012];
int read;
while (in.available() > 0 && ((read = in.read(tmp)) > 0)) {
out.write(tmp, 0, read);
}
in.closeEntry();
out.flush();
in.close();
result.setMessage((Message) Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray())));
return (T) result;
} catch (Exception e) {
e.printStackTrace();
throw new IOException(e.toString());
}
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class ZIPSerializer method writeObject.
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
if (!(object instanceof ZIPCompressedMessage))
return;
ZIPCompressedMessage zipMessage = (ZIPCompressedMessage) object;
Message message = zipMessage.getMessage();
ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
Serializer.writeClassAndObject(tempBuffer, message);
ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
ZipOutputStream zipOutput = new ZipOutputStream(byteArrayOutput);
zipOutput.setLevel(zipMessage.getLevel());
ZipEntry zipEntry = new ZipEntry("zip");
zipOutput.putNextEntry(zipEntry);
tempBuffer.flip();
zipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
zipOutput.flush();
zipOutput.closeEntry();
zipOutput.close();
buffer.put(byteArrayOutput.toByteArray());
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class GZIPSerializer method writeObject.
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
if (!(object instanceof GZIPCompressedMessage))
return;
Message message = ((GZIPCompressedMessage) object).getMessage();
ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
Serializer.writeClassAndObject(tempBuffer, message);
ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
GZIPOutputStream gzipOutput = new GZIPOutputStream(byteArrayOutput);
tempBuffer.flip();
gzipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
gzipOutput.flush();
gzipOutput.finish();
gzipOutput.close();
buffer.put(byteArrayOutput.toByteArray());
}
Aggregations