当前位置: 首页>>代码示例>>Java>>正文


Java Util类代码示例

本文整理汇总了Java中net.handle.hdllib.Util的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Util类属于net.handle.hdllib包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildResolutionRequest

import net.handle.hdllib.Util; //导入依赖的package包/类
private ResolutionRequest buildResolutionRequest(final String handle) {
    String handlePrefix = handle.substring(0,handle.indexOf("/"));
    
    PublicKeyAuthenticationInfo auth = getAuthInfo(handlePrefix);
    
    byte[][] types = null;
    int[] indexes = null;
    ResolutionRequest req =
            new ResolutionRequest(Util.encodeString(handle),
            types, indexes,
            auth);
    req.certify = false;
    req.cacheCertify = true;
    req.authoritative = false;
    req.ignoreRestrictedValues = true;
    return req;
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:18,代码来源:HandlenetServiceBean.java

示例2: readPrivKey

import net.handle.hdllib.Util; //导入依赖的package包/类
private PrivateKey readPrivKey(byte[] key, final String file) {
    PrivateKey privkey=null;
    
    String secret = System.getProperty("dataverse.handlenet.admprivphrase");
    byte secKey[] = null;
    try {
        if(Util.requiresSecretKey(key)){
            secKey = secret.getBytes();
        }
        key = Util.decrypt(key, secKey);
        privkey = Util.getPrivateKeyFromBytes(key, 0);
    } catch (Throwable t){
        logger.severe("Can't load private key in " + file +": " + t);
    }
    return privkey;
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:HandlenetServiceBean.java

示例3: getHandlesForNA

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * Return an enumeration of all the handles for a given naming authority.  This could be 
 * a very expensive call as it retrieves all of the handles at once.
 * 
 * @param namingAuthorityBytes
 * @return
 * @throws HandleException
 */
@SuppressWarnings("unchecked")
public Enumeration getHandlesForNA(byte[] namingAuthorityBytes) throws HandleException {
	log.debug("Get handles for na called ");
	String namingAuthority = Util.decodeString(namingAuthorityBytes);
	log.debug("Naming authority = " + namingAuthority);
	
	List<HandleInfo> handles = handleService.getAllHandlesForAuthority(namingAuthority);
	
	List<byte[]> handleValues = new LinkedList<byte[]>();
	
	for(HandleInfo hi : handles)
	{
		String handle = namingAuthority + "/" + hi.getLocalName();
		handleValues.add(Util.encodeString(handle));
	}
	return Collections.enumeration(handleValues);
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:26,代码来源:IrHandleStorage.java

示例4: createAdminRecord

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * Create the NA admin record for a new handle. The NA admin is provided
 * all permissions bar ADD_NA and DELETE_NA 
 * 
 * @return AdminRecord
 *           an AdminRecord object representing the NA handle admin
 * @param handle
 *           the NA admin handle in byte form
 * @param idx
 *           the handle index the of the NA handle's HS_VLIST entry
 */    
 public AdminRecord createAdminRecord(String handle, int idx)
 {
     return new AdminRecord(Util.encodeString(handle),
                           idx,
                           AdminRecord.PRM_ADD_HANDLE,
                           AdminRecord.PRM_DELETE_HANDLE,
                           AdminRecord.PRM_NO_ADD_NA,
                           AdminRecord.PRM_NO_DELETE_NA,
                           AdminRecord.PRM_READ_VALUE,
                           AdminRecord.PRM_MODIFY_VALUE,
                           AdminRecord.PRM_REMOVE_VALUE,
                           AdminRecord.PRM_ADD_VALUE,
                           AdminRecord.PRM_MODIFY_ADMIN,
                           AdminRecord.PRM_REMOVE_ADMIN,
                           AdminRecord.PRM_ADD_ADMIN,
                           AdminRecord.PRM_LIST_HANDLES);
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:29,代码来源:Handle.java

示例5: deleteValue

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * Delete a value from the handle 
 * 
 * @return boolean
 *           <code>true</code> if the value was deleted else <code>false</code>
 * @param index
 *           the index of the value to delete
 * @throws HandleException
 */
public boolean deleteValue(int index) throws HandleException
{
    byte idHandle[] = Util.encodeString(Constants.NA_HANDLE_PREFIX + handleConfig.getPrefix());
    
    PublicKeyAuthenticationInfo pubKeyAuthInfo = new PublicKeyAuthenticationInfo(idHandle,
          Constants.SEC_KEY_IDX,
          handleConfig.getPrivateKey());
            
    RemoveValueRequest req = new RemoveValueRequest(Util.encodeString(this.getHandle()), index, pubKeyAuthInfo);
    
    AbstractResponse response = resolver.getResolver().processRequest(req);
    
    if (response.responseCode == AbstractMessage.RC_SUCCESS)
    {
        return true;
    }
    else
    {
        log.error("Error deleting handle value from handle " + getHandle() + ": " + AbstractMessage.getResponseCodeMessage(response.responseCode));
        return false;
    }
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:32,代码来源:Handle.java

示例6: getAuthInfo

import net.handle.hdllib.Util; //导入依赖的package包/类
private PublicKeyAuthenticationInfo getAuthInfo(String handlePrefix) {
    byte[] key = null;
    String adminCredFile = System.getProperty("dataverse.handlenet.admcredfile");

    key = readKey(adminCredFile);        
    PrivateKey privkey = null;
    privkey = readPrivKey(key, adminCredFile);
    String authHandle =  getHandleAuthority(handlePrefix);
    PublicKeyAuthenticationInfo auth =
            new PublicKeyAuthenticationInfo(Util.encodeString(authHandle), 300, privkey);
    return auth;
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:13,代码来源:HandlenetServiceBean.java

示例7: haveNA

import net.handle.hdllib.Util; //导入依赖的package包/类
public boolean haveNA(byte[] naBytes) throws HandleException {
	
	boolean haveNa = false;
	String namingAuthority = Util.decodeString(naBytes);
	log.debug("checking to see if we have naming authority : " + namingAuthority);
	String[] namingAuthorityParts = namingAuthority.split("/");
	
	if( namingAuthorityParts.length < 2 )
	{
		// false
	}
	else
	{
		String prefix = namingAuthorityParts[1];
		log.debug("Checing for prefix " + prefix);
		if( handleService.getNameAuthority(prefix) != null )
		{
		    haveNa = true;	
		}
		else
		{
			// false
		}
	}
	log.debug("returning haveNa = " + haveNa);
	return haveNa;

}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:29,代码来源:IrHandleStorage.java

示例8: createHandle

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * Create a new handle record on the handle server 
 * 
 * @return AbstractResponse
 *           the handle server response to the create request
 * @param HandleValue[]
 *          An array of HandleValue objects
 * @throws HandleException
 */
private AbstractResponse createHandle(HandleValue[] hv) throws HandleException
{
    byte idHandle[] = Util.encodeString(Constants.NA_HANDLE_PREFIX + handleConfig.getPrefix());
    
    PublicKeyAuthenticationInfo pubKeyAuthInfo = new PublicKeyAuthenticationInfo(idHandle,
          Constants.SEC_KEY_IDX,
          handleConfig.getPrivateKey());

    CreateHandleRequest req = new CreateHandleRequest(Util.encodeString(this.getHandle()), hv, pubKeyAuthInfo);
    HandleResolver resolver = new HandleResolver();
    resolver.traceMessages = true;
    return resolver.processRequest(req);
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:23,代码来源:Handle.java

示例9: getSortedIndexes

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * Obtain an array of sorted indexes for a handle
 * 
 * @return Integer[]
 *           An array of sorted integers
 * @param handle
 *          The Handle object
 * @throws HandleException
 * @throws DAOException
 */
public Integer[] getSortedIndexes(Handle handle) throws DAOException
{
    Connection c = null; 
    
    PreparedStatement ps = null;
    
    ResultSet rs = null;
    
    ArrayList<Integer> indexList = new ArrayList<Integer>();
    
    try
    {
        c = datasource.getConnection();
        c.setAutoCommit(false);
        
        ps = c.prepareStatement(SELECT_ORDERED_INDEX_SQL);
        ps.setBytes(1, Util.encodeString(handle.getHandle()));
        rs = ps.executeQuery();
        
        while (rs.next())
        {
            int i = rs.getInt(1);
            indexList.add(new Integer(i));
        }
    }
    catch (SQLException sqle)
    {
        log.error("SQLException occurred", sqle);
        throw new DAOException(sqle);
    }
    finally
    {
        JDBCSupport.closeObjects(rs, ps, c);
    }
    
    return (Integer[])indexList.toArray(new Integer[indexList.size()]);
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:48,代码来源:HandleDAO.java

示例10: retrieve

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
     * obtain an identifier record
     * 
     * @return Identifier
     *           An identifier object if found, null if not found
     *           
     * @param identifier
     *          The identifier
     *          
     * @param authDomain
     *          The authentication domain
     *          
     * @exception DAOException
     */
    public Identifier retrieve(String identifier,
                               String authDomain) throws DAOException
    {
        Connection c = null; 
        
        PreparedStatement ps = null;
        
        ResultSet rs = null;
        
        try
        {
            c = datasource.getConnection();
            c.setAutoCommit(false);
            
            ps = c.prepareStatement(SELECT_IDENTIFIER_SQL);
            ps.setBytes(1, Util.encodeString(identifier + Identifier.separator + authDomain));
            ps.setBytes(2, Constants.XT_TYPE_DESC);
            rs = ps.executeQuery();
            
            Identifier id = null;
            if (rs.next())
            {
                id = new Identifier(identifier, authDomain);
                id.setHandle(Util.decodeString(rs.getBytes("handle")));
//                id.setID(rs.getInt("identifier_id"));
            }
            return id;
        }
        catch (SQLException sqle)
        {
            log.error("SQLException occurred", sqle);
            throw new DAOException(sqle);
        }
        finally
        {
            JDBCSupport.closeObjects(rs, ps, c);
        }
    }
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:53,代码来源:IdentifierDAO.java

示例11: createHandleValue

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * create a Handle Value with index 1 for type and value. This
 * should only be used when creating a handle for the first time
 * and that handle has a single value.
 *
 * @return HandleValue[]
 *    An array containing a single HandleValue
 * 
 * @param type
 *          the handle type
 * @param value
 *          the handle value
 */
public static HandleValue[] createHandleValue(String type,
                                              String value)
{
    HandleValue valueArray[] = new HandleValue[1];

    valueArray[0] = new HandleValue();
    valueArray[0].setIndex(1);
    valueArray[0].setType(Util.encodeString(type));
    valueArray[0].setData(Util.encodeString(value));
    valueArray[0].setTTL(Constants.DEFAULT_TTL);
       
    return valueArray;
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:27,代码来源:HandleSupport.java

示例12: create

import net.handle.hdllib.Util; //导入依赖的package包/类
/** 
 * Create a Handle object object using the provided Identifier and
 * handle values
 * 
 * @return Handle
 *           the Handle object
 * @param identifier
 *           the agent Identifier object
 * @param hv
 *           an array of HandleValue objects to be added to the handle
 * @throws DAOException
 * @throws HandleException
 */
public static Handle create(Identifier identifier,
                            HandleValue[] hv) throws DAOException, HandleException
{
    Handle handleObject = new Handle();
    
    HandleConfig hc = HandleConfig.getHandleConfig();
    handleObject.setHandle(hc.getPrefix() + '/' + Handle.getNextSuffix());
    
    String idHash = null;
    AdminRecord admin = handleObject.createAdminRecord(Constants.NA_HANDLE_PREFIX + hc.getPrefix(), Constants.ADMIN_GROUP_IDX);
    
    HandleValue values[] = new HandleValue[hv.length + 2];

    // load the passed values into the value array
    int i;
    
    for (i = 0; i < hv.length; i++)
    {
        values[i] = hv[i];
    }
    
    // add the admin values
    values[i] = new HandleValue();
    values[i].setIndex(Constants.ADMIN_IDX);
    values[i].setType(Common.STD_TYPE_HSADMIN);
    values[i].setData(Encoder.encodeAdminRecord(admin));
    values[i].setTTL(Constants.DEFAULT_TTL);
    
    values[i+1] = new HandleValue();
    values[i+1].setIndex(Constants.AGENT_IDX);
    values[i+1].setType(Constants.XT_AGENTID);
    values[i+1].setData(Util.encodeString(identifier.getHandle()));
    values[i+1].setTTL(Constants.DEFAULT_TTL);
    
    AbstractResponse response = handleObject.createHandle(values);

    if (response.responseCode == AbstractMessage.RC_SUCCESS)
    {
        log.info("Successfully created handle: " + handleObject.getHandle());
        return handleObject;
    }
    else
    {
        log.info("Failed to create handle: " + response);
        return null;
    }
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:61,代码来源:Handle.java

示例13: createAdmin

import net.handle.hdllib.Util; //导入依赖的package包/类
/** 
 * Create an agent admin Handle object object using the provided identifier
 * string and authentication domain string
 * 
 * @return Handle
 *           the Handle object
 * @param identifier
 *           the agent identifier string
 * @param authDomain
 *           the agent authentication domain string
 * @throws DAOException
 * @throws HandleException
 */
public static Handle createAdmin(String identifier,
		                         String authDomain,
		                         String appId) throws DAOException, HandleException
{
    Handle handleObject = new Handle();

    HandleConfig hc = HandleConfig.getHandleConfig();

    handleObject.setHandle(hc.getPrefix() + '/' + Handle.getNextSuffix());

    AdminRecord admin = handleObject.createAdminRecord(Constants.NA_HANDLE_PREFIX + hc.getPrefix(), Constants.ADMIN_GROUP_IDX);

    HandleValue values[] = new HandleValue[4];

    values[0] = new HandleValue();
    values[0].setIndex(Constants.AGENT_DESC_IDX);
    values[0].setType(Constants.XT_TYPE_DESC);
    values[0].setAnyoneCanRead(false);
    values[0].setData(Util.encodeString(identifier + Identifier.separator + authDomain));
    values[0].setTTL(Constants.DEFAULT_TTL);
    
    values[1] = new HandleValue();
    values[1].setIndex(Constants.ADMIN_IDX);
    values[1].setType(Common.STD_TYPE_HSADMIN);
    values[1].setData(Encoder.encodeAdminRecord(admin));
    values[1].setTTL(Constants.DEFAULT_TTL);
    
    values[2] = new HandleValue();
    values[2].setIndex(Constants.AGENT_IDX);
    values[2].setType(Constants.XT_AGENTID);
    values[2].setData(Util.encodeString(handleObject.getHandle()));
    values[2].setTTL(Constants.DEFAULT_TTL);
    
    values[3] = new HandleValue();
    values[3].setIndex(Constants.AGENT_DESC_APPIDX);
    values[3].setType(Constants.XT_APPID);
    values[3].setAnyoneCanRead(false);
    values[3].setData(Util.encodeString(appId));
    values[3].setTTL(Constants.DEFAULT_TTL);

    AbstractResponse response = handleObject.createHandle(values);

    if (response.responseCode == AbstractMessage.RC_SUCCESS)
    {
        log.info("Successfully created admin handle: " + handleObject.getHandle());
        return handleObject;
    }
    else
    {
        log.info("Failed to create admin handle: " + response);
        return null;
    }
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:67,代码来源:Handle.java

示例14: modifyValue

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * Modify a handle value 
 * 
 * @return boolean
 *           <code>true</code> if the value was deleted else <code>false</code>
 * @param index
 *           the index of the value to modify
 * @param value
 *           a string value to replace the existing value
 * @throws HandleException
 */
public boolean modifyValue(int index,
                           String value) throws HandleException
{
    boolean modified = false;
    
    HandleValue[] hv = getValues(index);
    if (hv.length == 0)
    {
        return modified;
    }
    
    if (hv[0].getTypeAsString().equals("URL"))
    {
        if (!HandleSupport.isValidURL(value))
        {
            log.error("Invalid value for URL type: " + value);
            return modified;
        }
    }
    hv[0].setData(Util.encodeString(value));
    hv[0].setTTL(Constants.DEFAULT_TTL);
    
    byte idHandle[] = Util.encodeString(Constants.NA_HANDLE_PREFIX + handleConfig.getPrefix());
    
    PublicKeyAuthenticationInfo pubKeyAuthInfo = new PublicKeyAuthenticationInfo(idHandle,
          Constants.SEC_KEY_IDX,
          handleConfig.getPrivateKey());
            
    ModifyValueRequest req = new ModifyValueRequest(Util.encodeString(this.getHandle()), hv, pubKeyAuthInfo);
    
    AbstractResponse response = resolver.getResolver().processRequest(req);
    
    if (response.responseCode == AbstractMessage.RC_SUCCESS)
    {
        modified = true;
    }
    else
    {
        log.error("Error modifying handle value for " + getHandle() + ": " + AbstractMessage.getResponseCodeMessage(response.responseCode));
        modified = false;
    }
    
    return modified;
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:56,代码来源:Handle.java

示例15: init

import net.handle.hdllib.Util; //导入依赖的package包/类
/**
 * 
 * 
 * @exception ServletException
 */    
public void init() throws ServletException
{
    HandleConfig handleConfig = HandleConfig.getHandleConfig();
    try
    {
        HashMap<String,Object> hm = new HashMap<String,Object>();
        
        String na = getInitParameter("naming-authority");
        if (na == null)
        {
            throw new ServletException("naming-authority not set, unable to initialise");
        }
        
        hm.put("naming-authority", na);

        String configDir = getInitParameter("config-dir");
        if (configDir == null)
        {
            throw new ServletException("config-dir not set, unable to initialise");
        }
        
        hm.put("config-dir", configDir);
        
        File privateKeyFile = new File(configDir + File.separator + "admpriv.bin");
        FileInputStream in = new FileInputStream(privateKeyFile);
        byte encKeyBytes[] = new byte[(int)privateKeyFile.length()];
        int n = 0; int r= 0;
        while(n < encKeyBytes.length && (r = in.read(encKeyBytes, n, encKeyBytes.length-n)) > 0)
        {
            n +=r;
        }
        in.close();
        
        // only support unencrypted keys for now
        byte[] keyBytes = Util.decrypt(encKeyBytes, null);

        hm.put("key", Util.getPrivateKeyFromBytes(keyBytes, 0));            
        
        handleConfig.init(hm);
    }
    catch (Exception e)
    {
        log.error("Exception occurred", e);
        throw new ServletException(e);
    }
}
 
开发者ID:au-research,项目名称:ANDS-PIDS-Service,代码行数:52,代码来源:LoadConfigServlet.java


注:本文中的net.handle.hdllib.Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。