public static String encodePassword(String originalPassword) { byte[] passwordBytes = originalPassword.getBytes(StringUtils.getPreferredCharset()); byte[] encodedPasswordBytes = Base64.encodeBase64(passwordBytes); return new String(encodedPasswordBytes, StringUtils.getPreferredCharset()); }
public static String decodePassword(String encodedPassword) { byte[] encodedPasswordBytes = encodedPassword.getBytes(StringUtils.getPreferredCharset()); byte[] passwordBytes = Base64.decodeBase64(encodedPasswordBytes); return new String(passwordBytes, StringUtils.getPreferredCharset()); }
/** * Writes a content {@link String} to a file that is going to be created in a folder. We will not append to the file if it already exists. Therefore, its content will be overwritten. * Moreover, the charset used is {@link com.cloud.utils.StringUtils#getPreferredCharset()}. * * We expect the folder object and the file not to be null/empty. */ static void writeFile(File folder, String file, String content) { try { FileUtils.write(new File(folder, file), content, com.cloud.utils.StringUtils.getPreferredCharset(), false); } catch (IOException ex) { throw new CloudRuntimeException("Failed to create config drive file " + file, ex); } }
protected StoragePoolInfo initializeLocalStorage() { String hostIp = getConfiguredProperty("private.ip.address", "127.0.0.1"); String localStoragePath = getConfiguredProperty("local.storage.path", "/mnt"); String lh = hostIp + localStoragePath; String uuid = UUID.nameUUIDFromBytes(lh.getBytes(StringUtils.getPreferredCharset())).toString(); String capacity = getConfiguredProperty("local.storage.capacity", "1000000000"); String available = getConfiguredProperty("local.storage.avail", "10000000"); return new StoragePoolInfo(uuid, hostIp, localStoragePath, localStoragePath, StoragePoolType.Filesystem, Long.parseLong(capacity), Long.parseLong(available)); }
static void createFileInTempDirAnAppendOpenStackMetadataToJsonObject(String tempDirName, JsonObject metaData, String dataType, String fileName, String content) { if (StringUtils.isBlank(dataType)) { return; } //create folder File typeFolder = new File(tempDirName + ConfigDrive.cloudStackConfigDriveName + dataType); if (!typeFolder.exists() && !typeFolder.mkdirs()) { throw new CloudRuntimeException("Failed to create folder: " + typeFolder); } if (StringUtils.isNotBlank(content)) { File file = new File(typeFolder, fileName + ".txt"); try { if (fileName.equals(USERDATA_FILE)) { // User Data is passed as a base64 encoded string FileUtils.writeByteArrayToFile(file, Base64.decodeBase64(content)); } else { FileUtils.write(file, content, com.cloud.utils.StringUtils.getPreferredCharset()); } } catch (IOException ex) { throw new CloudRuntimeException("Failed to create file ", ex); } } //now write the file to the OpenStack directory buildOpenStackMetaData(metaData, dataType, fileName, content); }
String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes(com.cloud.utils.StringUtils.getPreferredCharset())).toString(); String localRootPath = _parent + "/" + dir;
md5.update(password.getBytes(StringUtils.getPreferredCharset())); byte[] digest = md5.digest(); BigInteger bigInt = new BigInteger(1, digest);
@Test public void testGetPreferredCharset() { final boolean ifUtf8Supported = StringUtils.isUtf8Supported(); if (ifUtf8Supported) { assertEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8")); } else { assertNotEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8")); } }
pubkStream.write(command.getPubKey().getBytes(StringUtils.getPreferredCharset())); } catch (final FileNotFoundException e) { result = "File" + sshpubkeypath + "is not found:" try (FileOutputStream prvKStream = new FileOutputStream(prvKeyFile);){ if ( prvKStream != null) { prvKStream.write(prvKey.getBytes(StringUtils.getPreferredCharset()));
templateName = jobs.get(jobId).getTmpltName().trim().replace(" ", "_"); } else { templateName = java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName() + System.currentTimeMillis()).getBytes(StringUtils.getPreferredCharset())).toString();
@Test public void testGetPreferredCharset() { final boolean ifUtf8Supported = StringUtils.isUtf8Supported(); if (ifUtf8Supported) { assertEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8")); } else { assertNotEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8")); } }