public class FreenetURI extends java.lang.Object implements java.lang.Cloneable, java.lang.Comparable<FreenetURI>, java.io.Serializable
freenet:[KeyType@]RoutingKey,CryptoKey[,n1=v1,n2=v2,...][/docname][/metastring]
where KeyType is the TLA of the key (currently USK, SSK, KSK, or CHK). If omitted, KeyType defaults to KSK. BUT: CHKs don't support or require a docname. KSKs and SSKs do. Therefore CHKs go straight into metastrings.
For KSKs, the string keyword (docname) takes the RoutingKey position and the
remainder of the fields are inapplicable (except metastring). Examples:
RoutingKey is the modified Base64 encoded key value. CryptoKey is the modified Base64 encoded decryption key.
Following the RoutingKey and CryptoKey there may be a series of
name=value
pairs representing URI meta-information.
The docname is only meaningful for SSKs, and is hashed with the PK fingerprint to get the key value.
The metastring is meant to be passed to the metadata processing systems that act on the retrieved document.
When constructing a FreenetURI with a String argument, it is now legal for CHK keys to have a '.extension' tail, eg 'CHK@blahblahblah.html'. The constructor will simply chop off at the first dot.
REDFLAG: Old code has a FieldSet, and the ability to put arbitrary metadata in through name/value pairs. Do we want this? WARNING: Changing non-transient members on classes that are Serializable can result in restarting downloads or losing uploads.Modifier and Type | Field and Description |
---|---|
static FreenetURI |
EMPTY_CHK_URI |
static java.util.Comparator<FreenetURI> |
FAST_COMPARATOR |
protected java.lang.String |
toStringCache |
protected static java.util.regex.Pattern |
URI_PREFIX |
Modifier | Constructor and Description |
---|---|
protected |
FreenetURI() |
|
FreenetURI(byte[] pubKeyHash,
byte[] cryptoKey,
byte[] extra,
java.lang.String siteName,
long suggestedEdition2)
USK constructor from components.
|
|
FreenetURI(FreenetURI uri) |
|
FreenetURI(java.lang.String URI) |
|
FreenetURI(java.lang.String URI,
boolean noTrim)
Create a FreenetURI from its string form.
|
|
FreenetURI(java.lang.String keyType,
java.lang.String docName) |
|
FreenetURI(java.lang.String keyType,
java.lang.String docName,
byte[] routingKey,
byte[] cryptoKey,
byte[] extra2) |
|
FreenetURI(java.lang.String keyType,
java.lang.String docName,
java.lang.String[] metaStr,
byte[] routingKey,
byte[] cryptoKey,
byte[] extra2) |
|
FreenetURI(java.lang.String keyType,
java.lang.String docName,
java.lang.String[] metaStr,
byte[] routingKey,
byte[] cryptoKey,
byte[] extra2,
long suggestedEdition) |
|
FreenetURI(java.lang.String keyType,
java.lang.String docName,
java.lang.String metaStr,
byte[] routingKey,
byte[] cryptoKey) |
Modifier and Type | Method and Description |
---|---|
FreenetURI |
addMetaStrings(java.util.List<java.lang.String> metaStrings)
Returns a copy of this URI with these meta strings appended.
|
FreenetURI |
addMetaStrings(java.lang.String[] strs)
Returns a copy of this URI with these meta strings appended.
|
void |
checkInsertURI()
Throw an InsertException if we have any meta-strings.
|
static void |
checkInsertURI(FreenetURI uri)
Throw an InsertException if the argument has any meta-strings.
|
FreenetURI |
clone() |
int |
compareTo(FreenetURI o) |
void |
decompose()
Dump the individual components of the key to System.out.
|
FreenetURI |
deriveRequestURIFromInsertURI()
If this object is a USK/SSK insert URI, this function computes the request URI which belongs to it.
|
FreenetURI |
dropLastMetaStrings(int i)
Create a new URI with the last few meta-strings dropped.
|
boolean |
equals(java.lang.Object o) |
boolean |
equalsKeypair(FreenetURI u2)
Is the keypair (the routing key and crypto key) the same as the
given key?
|
static FreenetURI |
fromFullBinaryKey(byte[] buf)
Create a FreenetURI from the binary form of the key.
|
static FreenetURI |
generateRandomCHK(java.util.Random rand) |
java.lang.String[] |
getAllMetaStrings()
Get all the meta strings.
|
byte[] |
getCryptoKey()
Get the crypto key.
|
java.lang.String |
getDocName()
Get the document name.
|
long |
getEdition()
Get the edition number, if the key is a USK or a USK converted to an
SSK.
|
byte[] |
getExtra()
Get the extra bytes.
|
java.lang.String |
getGuessableKey() |
java.lang.String |
getKeyType()
Get the key type.
|
java.lang.String |
getMetaString()
Get the first meta-string.
|
java.lang.String |
getPreferredFilename()
Generate a suggested filename for the URI.
|
byte[] |
getRoutingKey()
Get the routing key.
|
long |
getSuggestedEdition()
Get suggested edition.
|
int |
hashCode() |
boolean |
hasMetaStrings()
Are there any meta-strings?
|
FreenetURI |
intern()
Optimize for memory.
|
boolean |
isCHK()
Is this key a CHK?
|
boolean |
isKSK()
Is this key a KSK?
|
boolean |
isSSK()
Is this key an SSK?
|
boolean |
isSSKForUSK()
Could this SSK be the result of sskForUSK()?
|
boolean |
isUSK()
Is this key a USK?
|
java.lang.String |
lastMetaString()
Get the last meta string.
|
java.util.ArrayList<java.lang.String> |
listMetaStrings()
Get the meta strings as an ArrayList.
|
static void |
main(java.lang.String[] args)
Run this class to decompose the argument.
|
FreenetURI |
popMetaString()
Returns a copy of this URI with the first meta string removed.
|
FreenetURI |
pushMetaString(java.lang.String name)
Returns a copy of this URI with the given string appended as a
meta-string.
|
static FreenetURI |
readFullBinaryKey(java.io.DataInputStream dis)
Create a FreenetURI from the binary form of the key, read from a
stream, with no length.
|
static FreenetURI |
readFullBinaryKeyWithLength(java.io.DataInputStream dis)
Read the binary form of a key, preceded by a short for its length.
|
FreenetURI |
setDocName(java.lang.String name)
Returns a copy of this URI with a new Document name set.
|
FreenetURI |
setKeyType(java.lang.String newKeyType)
Returns a new FreenetURI with a new key type.
|
FreenetURI |
setMetaString(java.lang.String[] newMetaStr)
Returns a copy of this URI with new meta-strings.
|
FreenetURI |
setRoutingKey(byte[] newRoutingKey)
Returns a new FreenetURI with a new routing key.
|
FreenetURI |
setSuggestedEdition(long newEdition)
Returns a new FreenetURI with a new suggested edition number.
|
FreenetURI |
sskForUSK()
Convert a USK into an SSK by appending "-" and the suggested edition
to the document name and changing the key type.
|
java.lang.String |
toACIIString()
Deprecated.
Use
toASCIIString() instead |
java.lang.String |
toASCIIString()
Get the FreenetURI as a pure ASCII string, any non-english
characters as well as any dangerous characters are encoded.
|
java.net.URI |
toRelativeURI()
Convert to a relative URI in the form of a URI (/KSK@gpl.txt etc).
|
java.lang.String |
toShortString()
Encode to a user-friendly, incomplete string with ...
|
java.lang.String |
toString()
toString() is equivalent to toString(false, false) but is cached.
|
java.lang.String |
toString(boolean prefix,
boolean pureAscii)
Get the FreenetURI as a string.
|
java.net.URI |
toURI(java.lang.String basePath)
Convert to a relative URI in the form of a URI, with the base path
not necessarily /.
|
FreenetURI |
uskForSSK()
Convert an SSK into a USK, if possible.
|
void |
writeFullBinaryKeyWithLength(java.io.DataOutputStream dos)
Write a binary representation of this URI, with a short length, so it can be passed over if necessary.
|
static void |
writeFullBinaryKeyWithLength(FreenetURI uri,
java.io.DataOutputStream dos)
Write either a null or a FreenetURI.
|
public static final FreenetURI EMPTY_CHK_URI
protected static final java.util.regex.Pattern URI_PREFIX
protected java.lang.String toStringCache
public static final java.util.Comparator<FreenetURI> FAST_COMPARATOR
public FreenetURI(FreenetURI uri)
public FreenetURI(java.lang.String keyType, java.lang.String docName)
public FreenetURI(java.lang.String keyType, java.lang.String docName, byte[] routingKey, byte[] cryptoKey, byte[] extra2)
public FreenetURI(java.lang.String keyType, java.lang.String docName, java.lang.String metaStr, byte[] routingKey, byte[] cryptoKey)
public FreenetURI(java.lang.String keyType, java.lang.String docName, java.lang.String[] metaStr, byte[] routingKey, byte[] cryptoKey, byte[] extra2)
public FreenetURI(java.lang.String keyType, java.lang.String docName, java.lang.String[] metaStr, byte[] routingKey, byte[] cryptoKey, byte[] extra2, long suggestedEdition)
public FreenetURI(java.lang.String URI) throws java.net.MalformedURLException
java.net.MalformedURLException
public FreenetURI(java.lang.String URI, boolean noTrim) throws java.net.MalformedURLException
java.net.MalformedURLException
- If the string could not be parsed.public FreenetURI(byte[] pubKeyHash, byte[] cryptoKey, byte[] extra, java.lang.String siteName, long suggestedEdition2)
protected FreenetURI()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public boolean equalsKeypair(FreenetURI u2)
public final FreenetURI clone()
clone
in class java.lang.Object
public FreenetURI intern()
public void decompose()
public java.lang.String getGuessableKey()
public java.lang.String getDocName()
public java.lang.String getMetaString()
public java.lang.String lastMetaString()
public java.lang.String[] getAllMetaStrings()
public boolean hasMetaStrings()
public byte[] getRoutingKey()
public byte[] getCryptoKey()
public java.lang.String getKeyType()
public FreenetURI popMetaString()
public FreenetURI dropLastMetaStrings(int i)
i
- The number of meta-strings to drop.public FreenetURI pushMetaString(java.lang.String name)
public FreenetURI addMetaStrings(java.lang.String[] strs)
public FreenetURI addMetaStrings(java.util.List<java.lang.String> metaStrings)
public FreenetURI setDocName(java.lang.String name)
public FreenetURI setMetaString(java.lang.String[] newMetaStr)
public java.lang.String toString()
toString
in class java.lang.Object
@Deprecated public java.lang.String toACIIString()
toASCIIString()
insteadpublic java.lang.String toASCIIString()
public java.lang.String toString(boolean prefix, boolean pureAscii)
prefix
- Whether to include the freenet: prefix.pureAscii
- If true, encode any non-english characters. If
false, only encode dangerous characters (slashes e.g.).public java.lang.String toShortString()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public byte[] getExtra()
public java.util.ArrayList<java.lang.String> listMetaStrings()
public static FreenetURI readFullBinaryKeyWithLength(java.io.DataInputStream dis) throws java.io.IOException
java.io.IOException
public static FreenetURI fromFullBinaryKey(byte[] buf) throws java.io.IOException
java.io.IOException
public static FreenetURI readFullBinaryKey(java.io.DataInputStream dis) throws java.io.IOException
java.net.MalformedURLException
- If there was a format error in the data.java.io.IOException
- If a read error occurredpublic static void writeFullBinaryKeyWithLength(FreenetURI uri, java.io.DataOutputStream dos) throws java.io.IOException
java.io.IOException
public void writeFullBinaryKeyWithLength(java.io.DataOutputStream dos) throws java.io.IOException
dos
- The stream to write to.java.net.MalformedURLException
- If the key could not be written because of inconsistencies or other
problems in the key itself.java.io.IOException
- If an error occurred while writing the key.public long getSuggestedEdition()
public java.lang.String getPreferredFilename()
public FreenetURI setSuggestedEdition(long newEdition)
public FreenetURI setKeyType(java.lang.String newKeyType)
public FreenetURI setRoutingKey(byte[] newRoutingKey)
public void checkInsertURI() throws InsertException
InsertException
public static void checkInsertURI(FreenetURI uri) throws InsertException
InsertException
public java.net.URI toRelativeURI() throws java.net.URISyntaxException
java.net.URISyntaxException
public java.net.URI toURI(java.lang.String basePath) throws java.net.URISyntaxException
java.net.URISyntaxException
public boolean isSSK()
public boolean isUSK()
public boolean isCHK()
public boolean isKSK()
public FreenetURI sskForUSK()
public boolean isSSKForUSK()
public FreenetURI uskForSSK()
public long getEdition()
public int compareTo(FreenetURI o)
compareTo
in interface java.lang.Comparable<FreenetURI>
public FreenetURI deriveRequestURIFromInsertURI() throws java.net.MalformedURLException
java.net.MalformedURLException
- If this object is a USK/SSK request URI already. NOT thrown for CHK/KSK URIs!public static FreenetURI generateRandomCHK(java.util.Random rand)