Wrapper class to store immutable name components. More...
Classes | |
class | DotDot |
Indicates an attempt to parse a . More... | |
Public Member Functions | |
Component (String text) | |
Create a component from a native string. | |
byte[] | getComponent () |
boolean | equals (Object obj) |
int | hashCode () |
String | toString () |
Static Public Member Functions | |
static byte[] | parseNative (String name) |
Parse native string component: just UTF-8 encode For full names in native strings only "/" is special but for an individual component we will even allow that. | |
static byte[] | parseURI (String name) throws DotDot, URISyntaxException |
Parse the URI Generic Syntax of RFC 3986. | |
static String | hexPrint (byte[] bs) |
static String | printNative (byte[] bs) |
static String | printURI (byte[] bs) |
static String | printURI (byte[] bs, int offset, int length) |
Print bytes in the URI Generic Syntax of RFC 3986 including byte sequences that are not legal character encodings in any character set and byte sequences that have special meaning for URI resolution per RFC 3986. | |
Static Public Attributes | |
static final ComponentProvider | NONCE |
Generates a random nonce component (with a nonce CommandMarker header). | |
static final ComponentProvider | EMPTY |
This object generates an empty component (length = 0). | |
Protected Member Functions | |
Component (byte[] comp) | |
Package Attributes | |
byte[] | component |
Static Package Attributes | |
static final char | HEX_DIGITS [] |
Wrapper class to store immutable name components.
org.ccnx.ccn.protocol.Component.Component | ( | String | text | ) |
Create a component from a native string.
text | native text string. |
byte [] org.ccnx.ccn.protocol.Component.getComponent | ( | ) |
Implements org.ccnx.ccn.protocol.ContentName.ComponentProvider.
static byte [] org.ccnx.ccn.protocol.Component.parseNative | ( | String | name | ) | [static] |
Parse native string component: just UTF-8 encode For full names in native strings only "/" is special but for an individual component we will even allow that.
This method intentionally throws no declared exceptions so you can be confident in encoding any native Java String TODO make this use Java string escaping rules?
name | Component as native Java string |
static byte [] org.ccnx.ccn.protocol.Component.parseURI | ( | String | name | ) | throws DotDot, URISyntaxException [static] |
Parse the URI Generic Syntax of RFC 3986.
Including handling percent encoding of sequences that are not legal character encodings in any character set. This method is the inverse of printComponent() and for any input sequence of bytes it must be the case that parseComponent(printComponent(input)) == input. Note that the inverse is NOT true printComponent(parseComponent(input)) != input in general.
Note in particular that this method interprets sequences of more than two dots ('.') as representing an empty component or dot component value as encoded by componentPrint. That is, the component value will be the value obtained by removing three dots.
name | a single component of a name, URI encoded |
static String org.ccnx.ccn.protocol.Component.printURI | ( | byte[] | bs, | |
int | offset, | |||
int | length | |||
) | [static] |
Print bytes in the URI Generic Syntax of RFC 3986 including byte sequences that are not legal character encodings in any character set and byte sequences that have special meaning for URI resolution per RFC 3986.
This is designed to match the C library URI encoding.
This method must be invertible by parseComponent() so for any input sequence of bytes it must be the case that parseComponent(printComponent(input)) == input.
All bytes that are unreserved characters per RFC 3986 are left unescaped. Other bytes are percent encoded.
Empty path components and path components "." and ".." have special meaning for relative URI resolution per RFC 3986. To guarantee these component variations are preserved and recovered exactly when the URI is parsed by parseComponent() we use a convention that components that are empty or consist entirely of '.' characters will have "..." appended. This is intended to be consistent with the CCN C library handling of URI representation of names.
bs | input byte array. |
final ComponentProvider org.ccnx.ccn.protocol.Component.EMPTY [static] |
new ComponentProvider() { public byte[] getComponent() { return emptyComponent; } }
This object generates an empty component (length = 0).
final char org.ccnx.ccn.protocol.Component.HEX_DIGITS[] [static, package] |
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }
final ComponentProvider org.ccnx.ccn.protocol.Component.NONCE [static] |
new ComponentProvider() { public byte[] getComponent() { byte [] nonce = new byte[8]; random.nextBytes(nonce); return COMMAND_MARKER_NONCE.addBinaryData(nonce); } }
Generates a random nonce component (with a nonce CommandMarker header).
Can be used in ContentName constructors where a nonce is required. Note: the nonce component generated will be different every time this is used.