Example usage for java.util UUID nameUUIDFromBytes

List of usage examples for java.util UUID nameUUIDFromBytes

Introduction

In this page you can find the example usage for java.util UUID nameUUIDFromBytes.

Prototype

public static UUID nameUUIDFromBytes(byte[] name) 

Source Link

Document

Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.

Usage

From source file:com.edgenius.core.repository.SimpleRepositoryServiceImpl.java

public void createWorkspace(String spacename, String username, String password)
        throws RepositoryException, RepositoryTiemoutExcetpion {
    //TODO: need verify permission?
    try {//from  w  w w  .j  a  va 2s  .c o  m

        acquireLock(spacename, null, null);
        String uuid = UUID.nameUUIDFromBytes(spacename.getBytes()).toString();
        CrWorkspace crW = new CrWorkspace();
        //leave user/pass empty
        crW.setName(spacename);
        crW.setSpaceUuid(uuid);
        crW.setQuota(Global.SpaceQuota);

        String spaceDir = FileUtil.getFullPath(homeDir, uuid);
        File space = new File(spaceDir);
        if (space.exists()) {
            throw new RepositoryException("Space already exist in repository " + spacename);
        }
        if (!space.mkdir()) {
            log.error("Space " + spacename + " directory can not created successfully");
            throw new RepositoryException("Space " + spacename + " directory can not created successfully");
        } else {
            crWorkspaceDAO.saveOrUpdate(crW);
            //            does not user Quota file 16/11/2007
            //            createQuotaFile(spacename);
            log.info("Space  " + spacename + " is created");
        }
    } finally {
        releaseLock(spacename, null, null);
    }

}

From source file:org.xenei.jdbc4sparql.impl.rdf.RdfKey.java

@Override
public final String getId() {
    return UUID.nameUUIDFromBytes(toString().getBytes()).toString();
}

From source file:org.midonet.cluster.rest_api.models.Route.java

public static UUID idOf(org.midonet.midolman.layer3.Route route) {
    ByteBuffer buffer = ByteBuffer.allocate(50);
    buffer.putInt(route.dstNetworkAddr);
    buffer.putInt(route.srcNetworkAddr);
    buffer.putInt(route.nextHopGateway);
    buffer.putInt(route.weight);/*ww  w .  j a v a  2 s.  c o m*/
    buffer.put((byte) (route.dstNetworkLength & 0xFF));
    buffer.put((byte) (route.srcNetworkLength & 0xFF));
    buffer.putLong(route.nextHopPort.getMostSignificantBits());
    buffer.putLong(route.nextHopPort.getLeastSignificantBits());
    buffer.putLong(route.routerId.getMostSignificantBits());
    buffer.putLong(route.routerId.getLeastSignificantBits());
    return UUID.nameUUIDFromBytes(buffer.array());
}

From source file:com.cloud.hypervisor.xen.resource.Xenserver625StorageProcessor.java

protected SR createFileSr(Connection conn, String remotePath, String dir) {
    String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(remotePath.getBytes());
    mountNfs(conn, remotePath, localDir);
    SR sr = createFileSR(conn, localDir + "/" + dir);
    return sr;/*from   w w w . ja va2s  .  c om*/
}

From source file:org.springframework.batch.core.partition.gemfire.RemoteScope.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    beanFactory.registerScope(name, this);

    this.beanFactory = beanFactory;
    evaluationContext = new StandardEvaluationContext();
    evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());

    Assert.state(beanFactory instanceof BeanDefinitionRegistry,
            "BeanFactory was not a BeanDefinitionRegistry, so RefreshScope cannot be used.");
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

    String id = this.id;
    if (id == null) {
        String names = Arrays.asList(registry.getBeanDefinitionNames()).toString();
        logger.debug("Generating bean factory id from names: " + names);
        id = UUID.nameUUIDFromBytes(names.getBytes()).toString();
        logger.debug("Generated bean factory id: " + id);
    }//from w w w.  j a  v  a  2s .  co m

    Assert.state(beanFactory instanceof BeanDefinitionRegistry,
            "BeanFactory was not a DefaultListableBeanFactory, so RefreshScope cannot be used.");
    ((DefaultListableBeanFactory) beanFactory).setSerializationId(id);

    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        // Replace this or any of its inner beans with scoped proxy if it
        // has this scope
        boolean scoped = name.equals(definition.getScope());
        Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped);
        scopifier.visitBeanDefinition(definition);
        if (scoped) {
            createScopedProxy(beanName, definition, registry, proxyTargetClass);
        }
    }

}

From source file:org.wso2.extension.siddhi.store.solr.utils.SolrTableUtils.java

public static String generateRecordIdFromPrimaryKeyValues(SiddhiSolrDocument document,
        List<String> primaryKeys) {
    StringBuilder builder = new StringBuilder();
    Object obj;/*w w w  . j a  va2s  .c  o m*/
    for (String key : primaryKeys) {
        obj = document.getFieldValue(key);
        if (obj != null) {
            builder.append(obj.toString());
        }
    }
    /* to make sure, we don't have an empty string */
    builder.append("");
    byte[] data = builder.toString().getBytes(Charset.forName("UTF-8"));
    return UUID.nameUUIDFromBytes(data).toString();
}

From source file:cz.mzk.editor.server.handler.ScanFolderHandler.java

@Override
public ScanFolderResult execute(final ScanFolderAction action, final ExecutionContext context)
        throws ActionException {

    LOGGER.debug("Processing action: ScanFolderAction " + action.getModel() + " - " + action.getCode());

    scanFolderFactory.create(action.getModel(), action.getCode());

    // parse input
    final String model = action.getModel();
    final String code = action.getCode();
    if (model == null || code == null) {
        return null;
    }/* ww w .  j  ava 2s  .  c o  m*/

    ScanFolder scanFolder = scanFolderFactory.create(model, code);
    List<String> wrongNames = scanFolder.getWrongNames();
    List<String> imgFileNames = scanFolder.getFileNames();
    if (imgFileNames == null || imgFileNames.isEmpty()) {
        throw new ActionException("No images found in " + scanFolder.getPath());
    }

    if (imgFileNames.size() == 1 && imgFileNames.get(0).endsWith(Constants.PDF_EXTENSION)) {
        return handlePdf(imgFileNames.get(0));
    }

    Collections.sort(imgFileNames);
    // due to gwt performance issues, more
    // concrete interface is used
    ArrayList<ImageItem> result = new ArrayList<ImageItem>(imgFileNames.size());
    ArrayList<ImageItem> toAdd = new ArrayList<ImageItem>();
    ArrayList<String> resolvedIdentifiers;

    try {
        resolvedIdentifiers = imageResolverDAO.resolveItems(imgFileNames);
        for (int i = 0; i < resolvedIdentifiers.size(); i++) {
            if (imgFileNames.get(i).endsWith(Constants.PDF_EXTENSION)) {
                throw new ActionException(
                        "There is more than one pdf file or one pdf file and some other file with enable extension in "
                                + scanFolder.getPath());
            }

            //get mimetype from extension (for audio)
            int position = imgFileNames.get(i).lastIndexOf('.');
            String extension = null;
            if (position > 0) {
                extension = imgFileNames.get(i).substring(position);
            }
            Constants.AUDIO_MIMETYPES audioMimeType = Constants.AUDIO_MIMETYPES.findByExtension(extension);

            String newIdentifier = null;
            String resolvedIdentifier = resolvedIdentifiers.get(i);
            if (resolvedIdentifier == null) {
                StringBuffer sb = new StringBuffer();
                sb.append(model).append('#').append(code).append('#').append(i);
                newIdentifier = UUID.nameUUIDFromBytes(sb.toString().getBytes()).toString();
                sb = new StringBuffer();
                sb.append(configuration.getImagesPath()).append(newIdentifier)
                        .append(Constants.JPEG_2000_EXTENSION);
                resolvedIdentifier = sb.toString();

                ImageItem item = new ImageItem(newIdentifier, resolvedIdentifier, imgFileNames.get(i));
                if (!audioMimeType.equals(Constants.AUDIO_MIMETYPES.UNKOWN_MIMETYPE)) {
                    item.setMimeType(audioMimeType.getMimeType());
                    sb = new StringBuffer();
                    sb.append(configuration.getImagesPath()).append(newIdentifier)
                            .append(Constants.AUDIO_MIMETYPES.WAV_MIMETYPE.getExtension());
                    item.setJpeg2000FsPath(sb.toString());
                }

                toAdd.add(item);
            }
            String uuid = newIdentifier != null ? newIdentifier
                    : resolvedIdentifier.substring(resolvedIdentifier.lastIndexOf('/') + 1,
                            resolvedIdentifier.lastIndexOf('.'));
            ImageItem item = new ImageItem(uuid, resolvedIdentifier, imgFileNames.get(i));

            String name = FilenameUtils.getBaseName(imgFileNames.get(i));

            if (imgFileNames.get(i).endsWith(".wav") || imgFileNames.get(i).endsWith(".mp3")) {
                String[] splits = name.split("-");
                /** audio files - special name convection */
                if (splits.length == 4 && "DS".equals(splits[0])) {
                    item.setName(splits[2] + "-" + splits[3]);
                } else if (splits.length == 5 && "MC".equals(splits[0])) {
                    item.setName(splits[2] + "-" + splits[3] + "-" + splits[4]);
                } else {
                    item.setName(name);
                }

                item.setLength(AudioUtils.getLengthDigit(imgFileNames.get(i)));
                item.setMimeType(Constants.AUDIO_MIMETYPES.WAV_MIMETYPE.getMimeType());
            }
            result.add(item);
        }
        if (!toAdd.isEmpty()) {
            imageResolverDAO.insertItems(toAdd);
        }
    } catch (DatabaseException e) {
        throw new ActionException(e);
    } catch (IOException e) {
        throw new ActionException(e);
    }

    if (toAdd.size() > 10) {
        removeOldImages();
    }

    if (wrongNames.size() == 0) {
        try {
            conversionDAO.insertConversionInfo(File.separator + model + File.separator + code + File.separator,
                    userProvider.getUserId());
        } catch (DatabaseException e) {
            LOGGER.error(e.getMessage());
            e.printStackTrace();
        }
        return new ScanFolderResult(result, toAdd, new ServerActionResult(Constants.SERVER_ACTION_RESULT.OK));
    } else {
        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i < wrongNames.size() && i < 10; i++) {
            sb.append("<br>" + wrongNames.get(i));
            if (i < 9) {
                if (i < wrongNames.size() - 1)
                    sb.append(",");
            } else {
                sb.append(",...");
            }
        }
        return new ScanFolderResult(result, toAdd,
                new ServerActionResult(Constants.SERVER_ACTION_RESULT.WRONG_FILE_NAME, sb.toString()));
    }
}

From source file:com.cloud.hypervisor.xenserver.resource.Xenserver625StorageProcessor.java

protected SR createFileSr(final Connection conn, final String remotePath, final String dir) {
    final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(remotePath.getBytes());
    mountNfs(conn, remotePath, localDir);
    final SR sr = createFileSR(conn, localDir + "/" + dir);
    return sr;//from   w  w  w.  ja v a  2 s.  c  om
}

From source file:net.sf.mpaxs.spi.server.HostRegister.java

/**
 * Adds a new Host to the register./* w w w  .j a  va2 s.  c o m*/
 *
 * @param name  Name of the Host
 * @param ip    IP of the server the Host is running on
 * @param cores Numer of available cores
 * @return the uuid of the new host
 */
public UUID newHost(final String name, final String ip, final int cores) {
    UUID hostID = UUID.nameUUIDFromBytes((name + ":" + ip).getBytes());
    if (hosts.containsKey(hostID)) {
        return hostID;
    }
    Host tmp = new Host(name, ip, cores, hostID);
    hosts.offer(tmp);
    reporter.report("New Host added with IP " + ip);
    hostAdded(tmp);
    return hostID;
}

From source file:ro.kuberam.libs.java.crypto.CryptoModuleTests.java

@Test
public void uuid5NewTest() throws Exception {
    final String NameSpace_OID_string = "6ba7b812-9dad-11d1-80b4-00c04fd430c8";
    final UUID NameSpace_OID_uuid = UUID.fromString(NameSpace_OID_string);

    final long msb = NameSpace_OID_uuid.getMostSignificantBits();
    final long lsb = NameSpace_OID_uuid.getLeastSignificantBits();

    final byte[] NameSpace_OID_buffer = new byte[16];

    for (int i = 0; i < 8; i++) {
        NameSpace_OID_buffer[i] = (byte) (msb >>> 8 * (7 - i));
    }/*w ww . j  a va2  s.co m*/
    for (int i = 8; i < 16; i++) {
        NameSpace_OID_buffer[i] = (byte) (lsb >>> 8 * (7 - i));
    }

    final String name = "user123";
    final byte[] name_buffer = name.getBytes();

    try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        outputStream.write(NameSpace_OID_buffer);
        outputStream.write(name_buffer);

        final byte byteArray[] = outputStream.toByteArray();
        System.out.println(UUID.nameUUIDFromBytes(byteArray).toString());
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}