🎨 Update Exceptions

Dieser Commit ist enthalten in:
Chaoscaot 2022-05-09 17:24:08 +02:00
Ursprung 75c03f79c5
Commit fed8a5f830

Datei anzeigen

@ -20,21 +20,19 @@
package de.steamwar.network.packets;
import lombok.EqualsAndHashCode;
import lombok.SneakyThrows;
import java.io.*;
@EqualsAndHashCode
public abstract class NetworkPacket implements Serializable {
@SneakyThrows
public byte[] serialize() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
oos.flush();
} catch (Exception e) {
throw new RuntimeException(e);
}
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
oos.flush();
return baos.toByteArray();
}
@ -42,13 +40,10 @@ public abstract class NetworkPacket implements Serializable {
PacketHandler.handlePacket(deserialize(data));
}
@SneakyThrows
public static NetworkPacket deserialize(byte[] data) {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
try {
ObjectInputStream ois = new ObjectInputStream(bais);
return (NetworkPacket) ois.readObject();
} catch (Exception e) {
throw new RuntimeException(e);
}
ObjectInputStream ois = new ObjectInputStream(bais);
return (NetworkPacket) ois.readObject();
}
}