Package com.thunken.beacon
Class BeaconParser
java.lang.Object
com.thunken.beacon.BeaconParser
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterator<Optional<BeaconLink>>
public class BeaconParser extends Object implements Closeable, Iterator<Optional<BeaconLink>>
Main class to parse BEACON dumps.
Note: the current Javadoc for this project is incomplete. We rely on Lombok to generate boilerplate code, and Lombok does not plug into Javadoc. Generated methods and constructors are not included, and the Javadoc for other methods and constructors may be incomplete. See delombok and beacon#1 for more information.
-
Constructor Summary
Constructors Constructor Description BeaconParser(Reader reader)
Creates a BEACON parser that uses the specifiedReader
, and initializes the parser'sBeaconMetaFields
from the meta lines.BeaconParser(Reader reader, BeaconMetaFields defaults)
Creates a BEACON parser that uses the specifiedReader
and defaultBeaconMetaFields
, and further initializes the parser'sBeaconMetaFields
from the meta lines. -
Method Summary
Modifier and Type Method Description void
close()
int
getLineNo()
int
getLinkNo()
Returns the current link number.BeaconMetaFields
getMetaFields()
boolean
hasNext()
Returnstrue
if the underlying BEACON dump has more links.Optional<BeaconLink>
next()
Returns anOptional
describing the nextBeaconLink
in the underlying BEACON dump, orOptional.empty()
if the corresponding line cannot be parsed.static Optional<BeaconLink>
parseLine(String linkLine, BeaconMetaFields metaFields)
Parses a BEACON link line and returns anOptional
describing the correspondingBeaconLink
, orOptional.empty()
if the line cannot be parsed into a valid link.void
remove()
BeaconParser
provides read-only access to a BEACON dump, soIterator.remove()
is not supported.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
BeaconParser
Creates a BEACON parser that uses the specifiedReader
, and initializes the parser'sBeaconMetaFields
from the meta lines.- Parameters:
reader
- A character stream reader.- Throws:
BeaconFormatException
- If the parser encounters data that violates the BEACON specification.IOException
- If an I/O error occurs.NullPointerException
- Ifreader
is null.- See Also:
- https://gbv.github.io/beaconspec/beacon.html#beacon-format
-
BeaconParser
Creates a BEACON parser that uses the specifiedReader
and defaultBeaconMetaFields
, and further initializes the parser'sBeaconMetaFields
from the meta lines.- Parameters:
reader
- A character stream reader.defaults
- Default values for BEACON meta fields. Overwritten by meta fields parsed from the reader, if any.- Throws:
BeaconFormatException
- If the parser encounters data that violates the BEACON specification.IOException
- If an I/O error occurs.NullPointerException
- Ifreader
is null.- See Also:
- https://gbv.github.io/beaconspec/beacon.html#beacon-format
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getLineNo
public int getLineNo() -
getLinkNo
public int getLinkNo()Returns the current link number.- Returns:
- The current link number.
-
getMetaFields
-
hasNext
public boolean hasNext()Returnstrue
if the underlying BEACON dump has more links. (In other words, returnstrue
ifnext()
would return anOptional
rather than throwing an exception.)- Specified by:
hasNext
in interfaceIterator<Optional<BeaconLink>>
- Returns:
true
if the underlying BEACON dump has more links.
-
next
Returns anOptional
describing the nextBeaconLink
in the underlying BEACON dump, orOptional.empty()
if the corresponding line cannot be parsed.- Specified by:
next
in interfaceIterator<Optional<BeaconLink>>
- Returns:
- An
Optional
describing the nextBeaconLink
in the underlying BEACON dump, orOptional.empty()
if the corresponding line cannot be parsed. - Throws:
NoSuchElementException
- If the underlying BEACON dump has no more links.- See Also:
parseLine(String, BeaconMetaFields)
-
remove
public final void remove()BeaconParser
provides read-only access to a BEACON dump, soIterator.remove()
is not supported.- Specified by:
remove
in interfaceIterator<Optional<BeaconLink>>
- Throws:
UnsupportedOperationException
-
parseLine
Parses a BEACON link line and returns anOptional
describing the correspondingBeaconLink
, orOptional.empty()
if the line cannot be parsed into a valid link.- Parameters:
linkLine
- The BEACON link line to parse.metaFields
- TheBeaconMetaFields
specifying link construction rules.- Returns:
- An
Optional
describing the correspondingBeaconLink
, orOptional.empty()
if the line cannot be parsed into a valid link - Throws:
NullPointerException
- IflinkLine
ormetaFields
is null.- See Also:
- https://gbv.github.io/beaconspec/beacon.html#links, https://gbv.github.io/beaconspec/beacon.html#link-construction
-