/** * Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet. * Uses UTF8 encoding. * * @param pArray a byte array containing binary data * @return A String containing only Base-N character data */ public String encodeToString(final byte[] pArray) { return StringUtils.utf8(encode(pArray)); }
/** * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the * method treats whitespace as valid. * * @param base64 String to test * @return {@code true} if all characters in the String are valid characters in the Base64 alphabet or if * the String is empty; {@code false}, otherwise * @since 1.5 */ public static boolean isBase64(final String base64) { return isBase64(StringUtils.utf8(base64)); }
/** * Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet. * Uses UTF8 encoding. * * @param pArray a byte array containing binary data * @return String containing only character data in the appropriate alphabet. */ public String encodeAsString(final byte[] pArray) { return StringUtils.utf8(encode(pArray)); }
/** * Tests a given String to see if it contains only valid characters within the alphabet. * The method treats whitespace and PAD as valid. * * @param basen String to test * @return {@code true} if all characters in the String are valid characters in the alphabet or if * the String is empty; {@code false}, otherwise * @see #isInAlphabet(byte[], boolean) */ public boolean isInAlphabet(final String basen) { return isInAlphabet(StringUtils.utf8(basen), true); }
/** * Encodes binary data using the base64 algorithm but does not chunk the output. * NOTE: We changed the behaviour of this method from multi-line chunking (commons-codec-1.4) to * single-line non-chunking (commons-codec-1.5). * * @param binaryData binary data to encode * @return String containing Base64 characters. * @since 1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not). */ public static String encodeBase64String(final byte[] binaryData) { return StringUtils.utf8(encodeBase64(binaryData, false)); }
/** * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The * url-safe variation emits - and _ instead of + and / characters. * <b>Note: no padding is added.</b> * * @param binaryData binary data to encode * @return String containing Base64 characters * @since 1.4 */ public static String encodeBase64URLSafeString(final byte[] binaryData) { return StringUtils.utf8(encodeBase64(binaryData, false, true)); }
/** * Decodes a String containing characters in the Base-N alphabet. * * @param pArray A String containing Base-N character data * @return a byte array containing binary data */ public byte[] decode(final String pArray) { return decode(StringUtils.utf8(pArray)); }
/** * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the * method treats whitespace as valid. * * @param base64 String to test * @return {@code true} if all characters in the String are valid characters in the Base64 alphabet or if * the String is empty; {@code false}, otherwise * @since 1.5 */ public static boolean isBase64(final String base64) { return isBase64(StringUtils.utf8(base64)); }
/** * Decodes a String containing characters in the Base-N alphabet. * * @param pArray A String containing Base-N character data * @return a byte array containing binary data */ public byte[] decode(final String pArray) { return decode(StringUtils.utf8(pArray)); }
public static byte[] saltedDigest(String text, DigestAlgorithm alg) { return saltedDigest(StringUtils.utf8(text), alg); }
public String getString(long id) throws InvalidSerializedDataException { return StringUtils.utf8(getData(id)); }
public long setString(String data) { return setData(StringUtils.utf8(data)); } }
/** * Encodes a byte[] containing binary data, into a String containing characters in the Base-N alphabet. * Uses UTF8 encoding. * * @param pArray a byte array containing binary data * @return A String containing only Base-N character data */ public String encodeToString(final byte[] pArray) { return StringUtils.utf8(encode(pArray)); }
/** * Encodes a byte[] containing binary data, into a String containing characters in the appropriate alphabet. * Uses UTF8 encoding. * * @param pArray a byte array containing binary data * @return String containing only character data in the appropriate alphabet. */ public String encodeAsString(final byte[] pArray) { return StringUtils.utf8(encode(pArray)); }
/** * Tests a given String to see if it contains only valid characters within the alphabet. * The method treats whitespace and PAD as valid. * * @param basen String to test * @return {@code true} if all characters in the String are valid characters in the alphabet or if * the String is empty; {@code false}, otherwise * @see #isInAlphabet(byte[], boolean) */ public boolean isInAlphabet(final String basen) { return isInAlphabet(StringUtils.utf8(basen), true); }
/** * Encodes binary data using the base64 algorithm but does not chunk the output. * NOTE: We changed the behaviour of this method from multi-line chunking (commons-codec-1.4) to * single-line non-chunking (commons-codec-1.5). * * @param binaryData binary data to encode * @return String containing Base64 characters. * @since 1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not). */ public static String encodeBase64String(final byte[] binaryData) { return StringUtils.utf8(encodeBase64(binaryData, false)); }
/** * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The * url-safe variation emits - and _ instead of + and / characters. * <b>Note: no padding is added.</b> * * @param binaryData binary data to encode * @return String containing Base64 characters * @since 1.4 */ public static String encodeBase64URLSafeString(final byte[] binaryData) { return StringUtils.utf8(encodeBase64(binaryData, false, true)); }
private String exec(HttpUriRequest req) throws IOException { final CloseableHttpResponse response = httpClient.execute(req); try { checkStatus(response); if (response.getEntity() != null) { return StringUtils.utf8(IOUtils.toByteArray(response.getEntity().getContent())); } else { return null; } } finally { response.close(); } }
/** * Check if a user has been linked against your website. * Use this to verify the user has been successfully linked to your website/service after he's been redirected to * the redirectUrl you specified in {@link #linkUser(String, URL, String, URL)}. * * @param serviceId Website serviceId * @param userRef User reference (generally the user's username on your website) * @return true if the user is linked against your website * @throws IOException If error occurred performing the operation */ public boolean isUserLinked(String serviceId, String userRef) throws IOException { final HttpGet req = new HttpGet(linkUserUrl(serviceId, userRef)); try { final CloseableHttpResponse response = httpClient.execute(req); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 404) { return false; } else if (statusCode == 200) { return Boolean.parseBoolean(StringUtils.utf8(IOUtils.toByteArray(response.getEntity().getContent()))); } else { throw new IOException("Server returned " + response.getStatusLine()); } } finally { req.releaseConnection(); } }
/** * Link an IDVKey user to your service/website. * You need to call this operation before a user on your website can use his IDVKey device * * @param serviceId Your website serviceId * @param redirectUrl The URL to which the user's browser will be redirected to after he's approved the link * @param userRef User reference (generally the user's username on your website) * @param cancelUrl URL to redirect user to should he wish to cancel the linking * @return URL you should redirect your user's browser to, in order for him to approve the linking * @throws IOException If the server returned an error * @throws UserAlreadyLinkedException if the user was already linked */ public URL linkUser(String serviceId, URL redirectUrl, String userRef, URL cancelUrl) throws IOException, UserAlreadyLinkedException { final HttpPost req = new HttpPost(linkUserUrl(serviceId, userRef, redirectUrl, cancelUrl)); try { final CloseableHttpResponse response = httpClient.execute(req); final int retCode = response.getStatusLine().getStatusCode(); if (retCode == 409) { throw new UserAlreadyLinkedException(); } else if (retCode < 200 || retCode > 299) { throw new IOException("Server returned " + response.getStatusLine()); } return new URL(StringUtils.utf8(IOUtils.toByteArray(response.getEntity().getContent()))); } finally { req.releaseConnection(); } }