mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-09 12:20:16 +01:00
Added the ability to retrieve the input buffer as a stream.
This commit is contained in:
parent
fefad5d806
commit
9f0d3a5054
@ -1,5 +1,7 @@
|
||||
package com.comphenix.protocol.events;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -11,13 +13,19 @@ import javax.annotation.Nonnull;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/**
|
||||
* Marker containing the serialized packet data seen from the network,
|
||||
* or output handlers that will serialize the current packet.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class NetworkMarker {
|
||||
// Custom network handler
|
||||
private PriorityQueue<PacketOutputHandler> outputHandlers;
|
||||
// The input buffer
|
||||
private ByteBuffer inputBuffer;
|
||||
|
||||
private ConnectionSide side;
|
||||
private final ConnectionSide side;
|
||||
|
||||
/**
|
||||
* Construct a new network marker.
|
||||
@ -57,6 +65,24 @@ public class NetworkMarker {
|
||||
return inputBuffer != null ? inputBuffer.asReadOnlyBuffer() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the serialized packet data as an input stream.
|
||||
* <p>
|
||||
* The data is exactly the same as in {@link #getInputBuffer()}.
|
||||
* @see {@link #getInputBuffer()}
|
||||
* @return The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally.
|
||||
*/
|
||||
public DataInputStream getInputStream() {
|
||||
if (side.isForServer())
|
||||
throw new IllegalStateException("Server-side packets have no input buffer.");
|
||||
if (inputBuffer == null)
|
||||
return null;
|
||||
|
||||
return new DataInputStream(
|
||||
new ByteArrayInputStream(inputBuffer.array())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue the given output handler for managing how the current packet will be written to the network stream.
|
||||
* <p>
|
||||
|
Loading…
Reference in New Issue
Block a user