idfactory.java
来自「JXTA™ is a set of open, generalize」· Java 代码 · 共 1,211 行 · 第 1/4 页
JAVA
1,211 行
if (-1 == colonAt) { throw new URISyntaxException(source.toString(), "URN namespace was missing."); } // check the namespace if (!net.jxta.id.ID.URNNamespace.equalsIgnoreCase(decoded.substring(0, colonAt))) { throw new URISyntaxException(source.toString(), "URN namespace was not as expected. (" + net.jxta.id.ID.URNNamespace + "!=" + decoded.substring(0, colonAt) + ")"); } // skip the namespace portion and the colon decoded = decoded.substring(colonAt + 1); int dashAt = decoded.indexOf('-'); // there's a dash, right? if (-1 == dashAt) { throw new URISyntaxException(source.toString(), "URN jxta namespace IDFormat was missing."); } // get the encoding used for this id String format = decoded.substring(0, dashAt); Instantiator instantiator; try { instantiator = factory.getInstantiator(format); } catch (NoSuchElementException itsUnknown) { instantiator = factory.getInstantiator("unknown"); } result = instantiator.fromURNNamespaceSpecificPart(decoded); return result.intern(); } /** * Construct a new ID instance from a JXTA ID contained in a URI. * * @deprecated Use of URLs for representing JXTA IDs and this method are * deprecated. Convert to using {@link #fromURI( URI )} instead. * * @param source URI which will be decoded to create a new ID instance. * @return ID containing the new ID instance initialized from the URI. * @throws UnknownServiceException Is thrown if the URI provided is of a * format unrecognized by this JXTA implementation. * @throws MalformedURLException Is thrown if the URI provided is not * a valid, recognized JXTA URI. */ @Deprecated public static ID fromURL(URL source) throws MalformedURLException, UnknownServiceException { ID result = null; // check the protocol if (!ID.URIEncodingName.equalsIgnoreCase(source.getProtocol())) { throw new UnknownServiceException("URI protocol type was not as expected."); } String encoded = source.getFile(); // Decode the URN to convert any % encodings and convert it from UTF8. String decoded = sun.net.www.protocol.urn.Handler.decodeURN(encoded); int colonAt = decoded.indexOf(':'); // There's a colon right? if (-1 == colonAt) { throw new MalformedURLException("URN namespace was missing."); } // check the namespace if (!net.jxta.id.ID.URNNamespace.equalsIgnoreCase(decoded.substring(0, colonAt))) { throw new MalformedURLException( "URN namespace was not as expected. (" + net.jxta.id.ID.URNNamespace + "!=" + decoded.substring(0, colonAt) + ")"); } // skip the namespace portion and the colon decoded = decoded.substring(colonAt + 1); int dashAt = decoded.indexOf('-'); // there's a dash, right? if (-1 == dashAt) { throw new UnknownServiceException("URN Encodingtype was missing."); } // get the encoding used for this id decoded = decoded.substring(0, dashAt); Instantiator instantiator; try { instantiator = factory.getInstantiator(decoded); } catch (NoSuchElementException itsUnknown) { instantiator = factory.getInstantiator("unknown"); } result = instantiator.fromURL(source); return result.intern(); } /** * Creates a new CodatID Instance. A new random CodatID is created for * the provided Peer Group. This type of CodatID can be used as a * canonical reference for dynamic content. * * @see net.jxta.codat.Codat * * @param groupID the group to which this content will belong. * @return The newly created CodatID. */ public static CodatID newCodatID(PeerGroupID groupID) { String useFormat = groupID.getIDFormat(); // is the group netpg or worldpg? if (IDFormat.INSTANTIATOR.getSupportedIDFormat().equals(useFormat)) { useFormat = factory.idNewInstances; } Instantiator instantiator = factory.getInstantiator(useFormat); return instantiator.newCodatID(groupID).intern(); } /** * Creates a new CodatID instance. A new CodatID is created for the * provided Peer Group. This type of CodatID can be used as a * canonical reference for dynamic content. * * <p/>This variant of CodatID allows you to create "Well-known" codats * within the context of diverse groups. This can be useful for common * services that need to do discovery without advertisements or for * network organization services. Because of the potential for ID * collisions and the difficulties with maintaining common service * interfaces this variant of CodatID should be used with great caution * and pre-planning. * * @see net.jxta.codat.Codat * * @param groupID the group to which this content will belong. * @param seed The seed information which will be used in creating the * codatID. The seed information should be at least four bytes in length, * though longer values are better. * @return The newly created CodatID. */ public static CodatID newCodatID(PeerGroupID groupID, byte[] seed) { String useFormat = groupID.getIDFormat(); // is the group netpg or worldpg? if (IDFormat.INSTANTIATOR.getSupportedIDFormat().equals(useFormat)) { useFormat = factory.idNewInstances; } Instantiator instantiator = factory.getInstantiator(useFormat); return instantiator.newCodatID(groupID, seed).intern(); } /** * Creates a new CodatID instance. A new random CodatID is created for * the provided Peer Group and contains a hash value for the Codat data. * This type of Codat ID is most appropriate for static content. By * including a hash value this form of Codat ID provides greater assurance * of the canonical property of IDs. It also allows the document content * returned when this ID is used to be verified to ensure it has not been * altered. * * @see net.jxta.codat.Codat * * @param groupID The group to which this ID will belong. * @param in The InputStream from which the content hash is calculated. * The stream is read until EOF and then closed. * @return The newly created CodatID. * @throws IOException I/O Error reading document */ public static CodatID newCodatID(PeerGroupID groupID, InputStream in) throws IOException { String useFormat = groupID.getIDFormat(); // is the group netpg or worldpg? if (IDFormat.INSTANTIATOR.getSupportedIDFormat().equals(useFormat)) { useFormat = factory.idNewInstances; } Instantiator instantiator = factory.getInstantiator(useFormat); return instantiator.newCodatID(groupID, in).intern(); } /** * Creates a new CodatID instance. A new CodatID is created for the * provided Peer Group and contains a hash value for the Codat data. * By including a hash value this form of Codat ID provides greater * assurance of the canonical property of IDs. It also allows the * document content returned when this ID is used to be verified to * ensure it has not been altered. This type of Codat ID is most * appropriate for static content. * * <p/>This variant of CodatID allows you to create "Well-known" codats * within the context of diverse groups. This can be useful for common * services that need to do discovery without advertisements or for * network organization services. Because of the potential for ID * collisions and the difficulties with maintaining common service * interfaces this variant of CodatID should be used with great caution * and pre-planning. * * @see net.jxta.codat.Codat * * @param groupID The group to which this ID will belong. * @param seed The seed information which will be used in creating the * codat ID. The seed information should be at least four bytes in length, * though longer values are better. * @param in The InputStream from which the content hash is calculated. * The stream is read until EOF and then closed. * @return The newly created CodatID. * @throws IOException I/O Error reading document */ public static CodatID newCodatID(PeerGroupID groupID, byte[] seed, InputStream in) throws IOException { String useFormat = groupID.getIDFormat(); // is the group netpg or worldpg? if (IDFormat.INSTANTIATOR.getSupportedIDFormat().equals(useFormat)) { useFormat = factory.idNewInstances; } Instantiator instantiator = factory.getInstantiator(useFormat); return instantiator.newCodatID(groupID, seed, in).intern(); } /** * Creates a new PeerID instance. A new random peer id will be generated. * The PeerID will be a member of the provided group. * * @see net.jxta.peergroup.PeerGroup * * @param groupID the group to which this PeerID will belong. * @return The newly created PeerID. */ public static PeerID newPeerID(PeerGroupID groupID) { String useFormat = groupID.getIDFormat(); // is the group netpg or worldpg? if (IDFormat.INSTANTIATOR.getSupportedIDFormat().equals(useFormat)) { useFormat = factory.idNewInstances; } Instantiator instantiator = factory.getInstantiator(useFormat); return instantiator.newPeerID(groupID).intern(); } /** * Creates a new PeerID instance. A new PeerID will be generated. * The PeerID will be a member of the provided group. * * @see net.jxta.peergroup.PeerGroup * * @param groupID the group to which this PeerID will belong. * @param seed The seed information which will be used in creating the * PeerID. The seed information should be at least four bytes in length, * though longer values are better. * @return The newly created PeerID. */ public static PeerID newPeerID(PeerGroupID groupID, byte[] seed) { String useFormat = groupID.getIDFormat(); // is the group netpg or worldpg? if (IDFormat.INSTANTIATOR.getSupportedIDFormat().equals(useFormat)) { useFormat = factory.idNewInstances; } Instantiator instantiator = factory.getInstantiator(useFormat); return instantiator.newPeerID(groupID, seed).intern(); } /** * Creates a new PeerGroupID instance. A new random peer group id will be * generated. The PeerGroupID will be created using the default ID Format. * * @see net.jxta.peergroup.PeerGroup * * @return The newly created PeerGroupID. */ public static PeerGroupID newPeerGroupID() { return newPeerGroupID(factory.idNewInstances).intern(); } /** * Creates a new PeerGroupID instance using the specified ID Format. * A new random peer group id will be generated. * * @see net.jxta.peergroup.PeerGroup * * @param idformat The ID Format to be used for crating the Peer Group ID. * @return The newly created PeerGroupID. */ public static PeerGroupID newPeerGroupID(String idformat) { Instantiator instantiator = factory.getInstantiator(idformat);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?