📄 idfactory.java
字号:
} // 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 = (Instantiator) factory.getInstantiator( format ); } catch ( NoSuchElementException itsUnknown ) { instantiator = (Instantiator) factory.getInstantiator( "unknown" ); } if( instantiator instanceof URIInstantiator ) { result = ((URIInstantiator) instantiator).fromURNNamespaceSpecificPart( decoded ); } else { URISyntaxException failure; try { result = instantiator.fromURL( jxtaURL(source.toString()) ); return result; } catch( MalformedURLException failed ) { failure = new URISyntaxException( source.toString(), "Malformed URL" ); failure.initCause( failed ); } catch( UnknownServiceException failed ) { failure = new URISyntaxException( source.toString(), "Unrecognized URL" ); failure.initCause( failed ); } throw failure; } return result; } /** * 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. **/ 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 = (Instantiator) factory.getInstantiator( decoded ); } catch ( NoSuchElementException itsUnknown ) { instantiator = (Instantiator) factory.getInstantiator( "unknown" ); } result = instantiator.fromURL( source ); return result; } /** * 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 = (Instantiator) factory.getInstantiator( useFormat ); return instantiator.newCodatID( groupID ); } /** * 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 varient 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 varient 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 = (Instantiator) factory.getInstantiator( useFormat ); return instantiator.newCodatID( groupID, seed ); } /** * 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 = (Instantiator) factory.getInstantiator( useFormat ); return instantiator.newCodatID( groupID, in ); } /** * 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 varient 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 varient 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 = (Instantiator) factory.getInstantiator( useFormat ); return instantiator.newCodatID( groupID, seed, in ); } /** * 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 = (Instantiator) factory.getInstantiator( useFormat ); return instantiator.newPeerID( groupID ); } /** * 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 = (Instantiator) factory.getInstantiator( useFormat ); return instantiator.newPeerID( groupID, seed ); } /** * 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 ); } /** * Creates a new PeerGroupID instance using the specified ID Format. * A new random peer group id will be generated. * @return The newly created PeerGroupID.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -