List of usage examples for java.util UUID nameUUIDFromBytes
public static UUID nameUUIDFromBytes(byte[] name)
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.queryresultspanel.actions.ExportResultTask.java
@Override protected Void doInBackground() throws Exception { // open file dialog to get save location FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select location to save", FileDialog.SAVE); fd.setVisible(true);/*from w w w .j av a2 s .c o m*/ String selectedFile = fd.getFile(); String selectedDirectory = fd.getDirectory(); if (selectedDirectory != null && selectedFile != null && resultSet != null) { try { // save to selected location File file = new File(selectedDirectory, selectedFile); // export to flat file FileWriter fw = new FileWriter(file); fw.flush(); // add column names to data String cols = ""; int colNum = resultSet.getMetaData().getColumnCount(); for (int c = 0; c < colNum; c++) { cols = cols + "\t" + resultSet.getMetaData().getColumnName(c + 1); } // trim line and add new line character cols = cols.trim(); cols = cols + "\n"; // write to file fw.write(cols); float totalRows = resultSetCount; float percent = 0; int counter = 0; // reset resultSet to first row in case its been iterated over before resultSet.beforeFirst(); while (resultSet.next()) { String line = ""; for (int l = 0; l < colNum; l++) { Object o = resultSet.getObject(l + 1); if (o instanceof Date) { o = sdf.format((Date) o); } else if (o instanceof byte[]) { byte[] bytes = (byte[]) o; o = UUID.nameUUIDFromBytes(bytes).toString(); } line = line + "\t" + o.toString(); } // trim line line = line.trim(); // append new line character to line line = line + "\n"; // write to file fw.write(line); // update progress bar percent = (counter / totalRows) * 100; setProgress((int) percent); setMessage("Exported " + counter + " of " + totalRows + " rows"); counter++; } // close file writer fw.close(); } catch (IOException e) { logger.warn("Nested exception is : " + e.fillInStackTrace()); } } return null; }
From source file:eu.loopit.f2011.library.BitmapManager.java
private InputStream cacheImage(String url, InputStream input) throws IOException { if (context == null) return input; UUID uuid = UUID.nameUUIDFromBytes(url.getBytes()); FileOutputStream output = null; try {/*ww w . j av a 2 s . c o m*/ output = context.openFileOutput(uuid.toString(), Context.MODE_PRIVATE); byte[] array = new byte[8196]; int read = 0; while ((read = input.read(array)) != -1) { output.write(array, 0, read); } } finally { if (output != null) output.close(); } Log.i(TAG, "Wrote " + uuid.toString() + " to image cache. URL:" + url); return fetch(uuid); }
From source file:io.teak.sdk.DeviceConfiguration.java
public DeviceConfiguration(@NonNull final Context context, @NonNull AppConfiguration appConfiguration) { if (android.os.Build.VERSION.RELEASE == null) { this.platformString = "android_unknown"; } else {//from w w w .j a v a 2 s . com this.platformString = "android_" + android.os.Build.VERSION.RELEASE; } // Preferences file { SharedPreferences tempPreferences = null; try { tempPreferences = context.getSharedPreferences(Teak.PREFERENCES_FILE, Context.MODE_PRIVATE); } catch (Exception e) { Log.e(LOG_TAG, "Error calling getSharedPreferences(). " + Log.getStackTraceString(e)); } finally { this.preferences = tempPreferences; } if (this.preferences == null) { Log.e(LOG_TAG, "getSharedPreferences() returned null. Some caching is disabled."); } } // Device model/manufacturer // https://raw.githubusercontent.com/jaredrummler/AndroidDeviceNames/master/library/src/main/java/com/jaredrummler/android/device/DeviceName.java { this.deviceManufacturer = Build.MANUFACTURER == null ? "" : Build.MANUFACTURER; this.deviceModel = Build.MODEL == null ? "" : Build.MODEL; if (this.deviceModel.startsWith(Build.MANUFACTURER)) { this.deviceFallback = capitalize(Build.MODEL); } else { this.deviceFallback = capitalize(Build.MANUFACTURER) + " " + Build.MODEL; } } // Device id { String tempDeviceId = null; try { tempDeviceId = UUID.nameUUIDFromBytes(android.os.Build.SERIAL.getBytes("utf8")).toString(); } catch (Exception e) { Log.e(LOG_TAG, "android.os.Build.SERIAL not available, falling back to Settings.Secure.ANDROID_ID. " + Log.getStackTraceString(e)); } if (tempDeviceId == null) { try { String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); if (androidId.equals("9774d56d682e549c")) { Log.e(LOG_TAG, "Settings.Secure.ANDROID_ID == '9774d56d682e549c', falling back to random UUID stored in preferences."); } else { tempDeviceId = UUID.nameUUIDFromBytes(androidId.getBytes("utf8")).toString(); } } catch (Exception e) { Log.e(LOG_TAG, "Error generating device id from Settings.Secure.ANDROID_ID, falling back to random UUID stored in preferences. " + Log.getStackTraceString(e)); } } if (tempDeviceId == null) { if (this.preferences != null) { tempDeviceId = this.preferences.getString(PREFERENCE_DEVICE_ID, null); if (tempDeviceId == null) { try { String prefDeviceId = UUID.randomUUID().toString(); SharedPreferences.Editor editor = this.preferences.edit(); editor.putString(PREFERENCE_DEVICE_ID, prefDeviceId); editor.apply(); tempDeviceId = prefDeviceId; } catch (Exception e) { Log.e(LOG_TAG, "Error storing random UUID, no more fallbacks. " + Log.getStackTraceString(e)); } } } else { Log.e(LOG_TAG, "getSharedPreferences() returned null, unable to store random UUID, no more fallbacks."); } } this.deviceId = tempDeviceId; if (this.deviceId == null) { return; } } // Kick off GCM request if (this.preferences != null) { int storedAppVersion = this.preferences.getInt(PREFERENCE_APP_VERSION, 0); String storedGcmId = this.preferences.getString(PREFERENCE_GCM_ID, null); if (storedAppVersion == appConfiguration.appVersion && storedGcmId != null) { // No need to get a new one, so put it on the blocking queue if (Teak.isDebug) { Log.d(LOG_TAG, "GCM Id found in cache: " + storedGcmId); } this.gcmId = storedGcmId; displayGCMDebugMessage(); } } this.gcm = new FutureTask<>(new RetriableTask<>(100, 2000L, new Callable<GoogleCloudMessaging>() { @Override public GoogleCloudMessaging call() throws Exception { return GoogleCloudMessaging.getInstance(context); } })); new Thread(this.gcm).start(); if (this.gcmId == null) { registerForGCM(appConfiguration); } // Kick off Advertising Info request fetchAdvertisingInfo(context); }
From source file:org.openmrs.module.metadatasharing.converter.ConceptMapConverter.java
/** * @see org.openmrs.module.metadatasharing.converter.BaseConverter#convert(org.w3c.dom.Document, org.openmrs.module.metadatasharing.util.Version, org.openmrs.module.metadatasharing.util.Version, org.openmrs.module.metadatasharing.converter.BaseConverter.ConverterContext) * @should replace source if the from version is pre one nine * @should replace nothing if the to version is post one nine *//*from w ww . ja v a 2 s . c o m*/ @Override public void convert(Document doc, Version fromVersion, Version toVersion, ConverterContext context) throws SerializationException { if (fromVersion.compareTo(new Version("1.9")) >= 0 || toVersion.compareTo(new Version("1.9")) < 0) { return; } Map<String, Element> mapTypeElements = new HashMap<String, Element>(); NodeList maps = doc.getElementsByTagName("org.openmrs.ConceptMap"); for (int i = 0; i < maps.getLength(); i++) { Node map = maps.item(i); Element commentElement = getChildElement(map, "comment"); if (commentElement == null) { continue; } map.removeChild(commentElement); String mapTypeName = getMapTypeName(commentElement); if (mapTypeName == null) { continue; } Element mapTypeElement = mapTypeElements.get(mapTypeName); if (mapTypeElement == null) { ConceptMapType mapType = Context.getConceptService().getConceptMapTypeByName(mapTypeName); if (mapType == null) { continue; } mapTypeElement = newElement(doc, "conceptMapType", mapType, context); mapTypeElements.put(mapTypeName, mapTypeElement); map.appendChild(mapTypeElement); } else { Element reference = doc.createElement("conceptMapTye"); newReferenced(reference, mapTypeElement); map.appendChild(reference); } } Map<String, Element> referenceTermElements = new HashMap<String, Element>(); for (int i = 0; i < maps.getLength(); i++) { Node map = maps.item(i); Element source = getChildElement(map, "source"); map.removeChild(source); Element referencedSource = (Element) reference(source, context); Element sourceCode = getChildElement(map, "sourceCode"); map.removeChild(sourceCode); //ConceptReferenceTerms are the same if source and sourceCode are the same String key = referencedSource.getAttribute("uuid") + sourceCode.getTextContent(); Element referenceTermElement = referenceTermElements.get(key); if (referenceTermElement == null) { ConceptReferenceTerm referenceTerm = new ConceptReferenceTerm(); String uuid = UUID.nameUUIDFromBytes(((Element) map).getAttribute("uuid").getBytes()).toString(); referenceTerm.setUuid(uuid); referenceTerm.setCode(sourceCode.getTextContent()); referenceTermElement = newElement(doc, "conceptReferenceTerm", referenceTerm, context); source = (Element) source.cloneNode(true); source = (Element) doc.renameNode(source, "", "conceptSource"); referenceTermElement.appendChild(source); referenceTermElements.put(key, referenceTermElement); map.appendChild(referenceTermElement); } else { Element reference = doc.createElement("conceptReferenceTerm"); newReferenced(reference, referenceTermElement); map.appendChild(reference); } } }
From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POCache.java
/** * Get a cache key for the given operator, or null if we don't know how to handle its type (or one of * its predcesessors' types) and want to not cache this subplan at all. * * Right now, this only handles loads. Unless we figure out a nice way to turn the PO plan into a * string or compare two PO plans, we'll probably have to handle each type of physical operator * recursively to generate a cache key.//from www . jav a 2s . c o m * @param plan * @throws IOException */ public String computeCacheKey() throws IOException { if (key == null) { key = computeRawCacheKey(inputs); if (key != null) { // TODO deal with collisions!! key = UUID.nameUUIDFromBytes(key.getBytes()).toString(); } } return key; }
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java
public CachingChromatogram1D(final IFileFragment e) { this.parent = e; String id = e.getUri().toString() + "-1D"; whm = ChromatogramScanCache//from w w w . ja va 2s. c o m .createVolatileAutoRetrievalCache(UUID.nameUUIDFromBytes(id.getBytes()).toString(), this); }
From source file:cz.mzk.editor.server.quartz.jobs.ConvertImages.java
/** * {@inheritDoc}/*from w ww .j a v a 2s.c o m*/ */ @Override public void execute(JobExecutionContext context) throws JobExecutionException { ; this.setJobKey(context.getJobDetail().getKey()); JobDataMap dataMap = context.getJobDetail().getJobDataMap(); guice = (Injector) dataMap.get("Injector"); EditorConfiguration configuration = guice.getInstance(EditorConfiguration.class); ImageResolverDAO imageResolverDAO = guice.getInstance(ImageResolverDAO.class); String model = dataMap.getString("model"); String code = dataMap.getString("code"); ScanFolderImpl.ScanFolderFactory scanFolderFactory = guice .getInstance(ScanFolderImpl.ScanFolderFactory.class); ScanFolder scanFolder = scanFolderFactory.create(model, code); final List<String> fileNames = scanFolder.getFileNames(); Collections.sort(fileNames); ArrayList<String> resolvedIdentifiers = null; try { resolvedIdentifiers = imageResolverDAO.resolveItems(fileNames); } catch (DatabaseException e) { e.printStackTrace(); } //TODO-MR need refactoring! (http://jdem.cz/yeqp2) ArrayList<ImageItem> toAdd = new ArrayList<ImageItem>(); ArrayList<ImageItem> result = new ArrayList<ImageItem>(fileNames.size()); for (int i = 0; i < resolvedIdentifiers.size(); i++) { //get mimetype from extension (for audio) int position = fileNames.get(i).lastIndexOf('.'); String extension = null; if (position > 0) { extension = fileNames.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, fileNames.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, fileNames.get(i)); String name = FilenameUtils.getBaseName(fileNames.get(i)); String[] splits = name.split("-"); /** audio files - special name convection */ if (splits.length == 4 && "DS".equals(splits[0])) { item.setName(splits[2] + "-" + splits[3]); } if (splits.length == 5 && "MC".equals(splits[0])) { item.setName(splits[2] + "-" + splits[3] + "-" + splits[4]); } result.add(item); } if (!toAdd.isEmpty()) { try { imageResolverDAO.insertItems(toAdd); } catch (DatabaseException e) { e.printStackTrace(); } convert(toAdd); } }
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram2D.java
public CachingChromatogram2D(final IFileFragment e) { this.parent = e; String id = e.getUri().toString() + "-2D"; whm = ChromatogramScanCache// w w w . j a va2 s .c o m .createVolatileAutoRetrievalCache(UUID.nameUUIDFromBytes(id.getBytes()).toString(), this); }
From source file:net.longfalcon.newsj.service.UserService.java
@Transactional public User add(String userName, String password, String email, int roleId, String host, int inviteCount, Long invitedByUserId) {//from ww w. j a v a 2s.c o m User user = new User(); user.setUsername(userName); user.setEmail(email.toLowerCase()); user.setRole(roleId); user.setHost(host); user.setInvites(inviteCount); user.setInvitedBy(invitedByUserId); user.setCreateDate(new Date()); String rssToken = UUID.randomUUID().toString(); user.setRssToken(EncodingUtil.md5Hash(rssToken)); String userSeed = UUID.nameUUIDFromBytes(userName.getBytes()).toString(); user.setUserseed(EncodingUtil.md5Hash(userSeed)); try { user.setPassword(PasswordHash.createHash(password)); userDAO.update(user); } catch (Exception e) { _log.error(e, e); return null; } return user; }
From source file:org.photovault.imginfo.ImageFile.java
private void init(File f) throws PhotovaultException, IOException { id = UUID.nameUUIDFromBytes(hash); size = f.length(); readImageFile(f); }