org.jnetstream.packet
Interface HeaderModifier

All Superinterfaces:
Updatable

public interface HeaderModifier
extends Updatable

Mutable interface which allows many different types of operations to be performend upon a container such as adding, removing or clearing headers.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Method Summary
<T extends Header>
T
add(java.lang.Class<T> c)
           
<T extends Header>
T
add(T t)
           
 void addAll(java.lang.Class<? extends Header> c1, java.lang.Class<?>... c3)
           
 void addAll(java.util.List<java.lang.Class<? extends Header>> c)
           
 void clearAll()
          Clears all the buffer contents to zeros, effectively removing all headers from the packet.
 java.nio.ByteBuffer compact()
          Compacts the current data buffer's capacity to be exactly of current length.
 java.nio.ByteBuffer copy(byte[] buffer)
           
 java.nio.ByteBuffer copy(java.nio.ByteBuffer buffer)
          Copies the contents from user supplied buffer to the existing packet buffer.
 void init(PacketInitializer initializer)
          Initializes each header by allowing it to pull any relavent information from the capture device.
<T extends Header>
T
insert(java.lang.Class<T> c, java.lang.Class<? extends Header> afterHeader)
           
<T extends Header>
T
insert(java.lang.Class<T> c, int afterIndex)
           
<T extends Header>
T
remove(java.lang.Class<T> c)
           
 Header remove(int index)
           
 Header[] removeAll()
          Removes all headers from the packet and effectively shrinking the packet data buffer to length 0.
 java.nio.ByteBuffer replace(byte[] buffer)
           
 java.nio.ByteBuffer replace(java.nio.ByteBuffer buffer)
          Replaces the current buffer with the user supplied buffer.
 
Methods inherited from interface org.jnetstream.packet.Updatable
update
 

Method Detail

add

<T extends Header> T add(java.lang.Class<T> c)

add

<T extends Header> T add(T t)

addAll

void addAll(java.lang.Class<? extends Header> c1,
            java.lang.Class<?>... c3)

addAll

void addAll(java.util.List<java.lang.Class<? extends Header>> c)

clearAll

void clearAll()
              throws java.io.IOException
Clears all the buffer contents to zeros, effectively removing all headers from the packet. The difference between clearAll and removeAll is that removeAll removes all the headers and shrinks the packet buffer size down to zero length.

Throws:
java.io.IOException

compact

java.nio.ByteBuffer compact()
                            throws java.io.IOException
Compacts the current data buffer's capacity to be exactly of current length. The compacted buffer will no extra capacity to expand. It can however still be expanded, but methods will require reallocation of buffer space to increase it capacity. If the compacted buffer is further shrunk, no copies of data will take place.

Returns:
Throws:
java.io.IOException

copy

java.nio.ByteBuffer copy(byte[] buffer)

copy

java.nio.ByteBuffer copy(java.nio.ByteBuffer buffer)
Copies the contents from user supplied buffer to the existing packet buffer. The old buffer length is changed to match the new buffer lengths. If the capacity of the current packet buffer is too small to accomodate the data, a completely new buffer is allocated. All decoded state is cleared and needs to be rebuilt from scratch by calling on update method.

Parameters:
buffer -
Returns:

init

void init(PacketInitializer initializer)
Initializes each header by allowing it to pull any relavent information from the capture device. For example Ethernet2 header would pull the MAC address from the capture device and assign it to its source field. While IPv4 header would pull the IP address and assign that to its source field.

Parameters:
device -

insert

<T extends Header> T insert(java.lang.Class<T> c,
                            java.lang.Class<? extends Header> afterHeader)

insert

<T extends Header> T insert(java.lang.Class<T> c,
                            int afterIndex)

remove

<T extends Header> T remove(java.lang.Class<T> c)

remove

Header remove(int index)

removeAll

Header[] removeAll()
Removes all headers from the packet and effectively shrinking the packet data buffer to length 0. The difference between removeAll and clearAll is that clearAll does not shrink the buffer size, but zero's out all the values allowing the buffer to be reused.


replace

java.nio.ByteBuffer replace(byte[] buffer)
                            throws java.io.IOException
Throws:
java.io.IOException

replace

java.nio.ByteBuffer replace(java.nio.ByteBuffer buffer)
                            throws java.io.IOException
Replaces the current buffer with the user supplied buffer. The internal buffer reference is replaced to reference the user supplied buffer. All of decoded state cleared completely and requires rebuilding by calling on update method.

Parameters:
buffer - new buffer which will replaced the old
Returns:
the new buffer
Throws:
java.io.IOException