|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Capture<T extends CapturePacket>
Main capture session interface. The Capture interface provides general services to any open and active sessions which aquire network packets from either a live network interface, a file, a memory based collection or from remote system over the network.
Capture is Iterable which means that it can be placed in a
tight foreach loop. Care must be taken when the iterator functionality is
used as aquiring packets usually means that some kind of back-end IO
operation had to take place which can throw an IO exception at any time. The
standard Iterator interface does not provide a way of throwing an IO
exception therefore the Iterator will relay any IO exceptions as a runtime
exception. Runtime exception is one that does not have to have a specified
throws statement in its signature, but can throw an exception anyhow. The
iterator specifically, will throw a IORuntimeException which will relay the
original IO exception which caused an error. Care must be taken that even
though this iterator can be passed to other non IO exception aware methods,
that a runtime IO exception can occure at any time and cause the method and
iterator to abort.
FileCapture capture = Captures.openFile(new File("capture.pcap"));
for (FilePacket packet : capture) {
System.out.println(packet.toString());
}
In addition to the convenient Iterator interface, a specialized IOIterator
interface is also provided which mimics its java.util.Iterator counter part
and provides exact same methods with exactly the same meanings, with the
exception that IOIterator.hasNext() and
IOIterator.next() methods also throw IO
exception immediately. The IOIterator can not be used in the foreach loop as
its not a the standard java.util.Iterator.
FileCapture capture = Captures.openFile(new File("capture.pcap"));
FileIterator i = capture.getFileIterator(); while (i.hasNext()) { // May
throw IO exception FilePacket packet = i.next(); // May throw IO exception
System.out.println(packet.toString()); }
| Method Summary | |
|---|---|
Filter<ProtocolFilterTarget> |
getFilter()
Gets the currently active filter set on this capture session. |
com.slytechs.utils.collection.IOSkippableIterator<T> |
getPacketIterator()
Retrieves an iterator Iterator which can iterate over all
the packets of this capture session. |
CaptureType |
getType()
Returns the type of file capture this is. |
boolean |
isMutable()
Tells if this capture session is mutable. |
java.util.Iterator<T> |
iterator()
Creates a standard java iterator which will iterate over all packets within the current capture session. |
| Methods inherited from interface java.io.Closeable |
|---|
close |
| Method Detail |
|---|
Filter<ProtocolFilterTarget> getFilter()
com.slytechs.utils.collection.IOSkippableIterator<T> getPacketIterator()
throws java.io.IOException
Iterator which can iterate over all
the packets of this capture session. The IO based iterator mimics the
methods and behaviour of its counter part Iterator that it
can throw IO exceptions in any of the methods.
java.io.IOException - Any IO errors while retrieving a packetCaptureType getType()
boolean isMutable()
java.util.Iterator<T> iterator()
Creates a standard java iterator which will iterate over all packets within
the current capture session. Since all operations behind this iterator
actually use IO operations to aquire data, an IO exception may be thrown at
anytime. The IO exception is relayed using a special
com.slytechs.utils.io.IORuntimeException runtime exception. This
may cause the iterator from being created or returned. Runtime exceptions
do not have to be declared in the methods signature to be thrown, and to
conform to java's standard interface Iterable this
iterator getter does not declare one, but IORuntimeException might be
thrown and must be caught when aquiring the iterator and later around the
usage of the iterator returned.
The iterator's remove method is optional method and is only available on
capture session's who's isMutable() method returns boolean. If you
try to invoke the Iterator.remove() method on a non mutable
capture session, and UnsupportedOperationException will be thrown to
indicate that this is a non mutable capture session. I.e. LiveCaptures or
read-only capture files are types of non mutable capture sessions.
iterator in interface java.lang.Iterable<T extends CapturePacket>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||