String password = "p4ssword"; PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String encodedPassword = passwordEncoder.encode(password);
/** * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. * <p/> * * @param s String to encode. * @return encoded string. */ public static String encode(String s) { return shouldEncodePassword(s) ? PREFIX + Base64Encoder.encode(s) : s; }
/** * Returns the namespace URIs found in the given XML file */ public static Set<String> getNamespaces(InputSource source) throws ParserConfigurationException, SAXException, IOException { XmlNamespaceFinder finder = createNamespaceFinder(); Set<String> answer = finder.parseContents(source); if (factory == null) { factory = finder.getFactory(); } return answer; }
protected String decodeSecretData(String text) { if (Strings.isNotBlank(text)) { return Base64Encoder.decode(text); } else { return text; } }
protected static String stripSlashesAndGit(String path) { path = Strings.stripPrefix(path, "/"); path = Strings.stripPrefix(path, "/"); path = Strings.stripSuffix(path, "/"); path = Strings.stripSuffix(path, ".git"); return path; }
/** * Returns the map of entries in the properties object which have keys starting with the given prefix, removing the prefix * from the returned map. */ public static Map<String, String> findPropertiesWithPrefix(Properties properties, String prefix) { return findPropertiesWithPrefix(properties, prefix, Functions.<String>noop()); }
/** * Defines the columns of the table */ public void columns(String... headers) { for (String header : headers) { // force lazy creation column(header); } }
/** * Reads a {@link File} and returns a {@String}. */ public static String toString(File file) throws IOException { return toString(file, null); }
/** * This method should be called before the resource is used. * * @throws ShutdownException once {@see shutdown} has been called. */ public void retain() { if(!attemptRetain()) { throw new ShutdownException(); // fail the attempt at retaining. } }
static public int getPublicPort(int localPort) { return create().getPublicPort(localPort); }
/** * Creates a zip fie from the given source directory and output zip file name */ public static void createZipFile(Logger log, File sourceDir, File outputZipFile) throws IOException { FileFilter filter = null; createZipFile(log, sourceDir, outputZipFile, filter); }
@Override public List<Runnable> shutdownNow() { shutdown(); return Collections.EMPTY_LIST; }
protected static void readProcessOutput(InputStream inputStream, final String prefix, final String message) throws Exception { Function<String, Void> function = new Function<String, Void>() { @Override public Void apply(String line) { LOG.debug("Error " + prefix + message + ": " + line); return null; } }; processOutput(inputStream, function, prefix + message); }
/** * Reads the specified key as a String from configuration. */ public static String readString(Dictionary dictionary, String key) { return readString(dictionary, key, "null"); }
/** * Returns the String value of the given property in the map or null */ public static String stringValue(Map map, String key) { return stringValue(map, key, null); }
/** * Asserts that the block passes within a default time of 30 seconds. */ public static void assertWaitFor(Block block) throws Exception { assertWaitFor(30 * 1000, block); }
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String hashedPassword = passwordEncoder.encode(yourpassword);
/** * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. * <p/> * * @param s String to encode. * @return encoded string. */ public static String encode(String s) { return shouldEncodePassword(s) ? PREFIX + Base64Encoder.encode(s) : s; }
@Override public String readFrom(Class<String> stringClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream inputStream) throws IOException, WebApplicationException { return Files.toString(inputStream); } }