/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param content the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null */ public static byte[] getHash( Algorithm algorithm, byte[] content ) throws NoSuchAlgorithmException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), content); }
/** * Construct a Reflection instance that cache's some information about the target class. The target class is the Class object * upon which the methods will be found. * * @param targetClass the target class * @throws IllegalArgumentException if the target class is null */ public Reflection( Class<?> targetClass ) { CheckArg.isNotNull(targetClass, "targetClass"); this.targetClass = targetClass; }
/** * Read and return the entire contents of the supplied {@link Reader}. This method always closes the reader when finished * reading. * * @param reader the reader of the contents; may be null * @return the contents, or an empty string if the supplied reader is null * @throws IOException if there is an error reading the content */ public static String read( Reader reader ) throws IOException { return IoUtil.read(reader); }
/** * Get the logging level at which this logger is current set. * * @return the current logging level */ public Level getLevel() { if (this.isTraceEnabled()) return Level.TRACE; if (this.isDebugEnabled()) return Level.DEBUG; if (this.isInfoEnabled()) return Level.INFO; if (this.isWarnEnabled()) return Level.WARNING; if (this.isErrorEnabled()) return Level.ERROR; return Level.OFF; }
/** * Encodes content of the supplied InputStream into Base64 notation. Does not GZip-compress data. * * @param source The data to convert * @return the encoded bytes */ public static String encode( java.io.InputStream source ) { return encode(source, NO_OPTIONS); }
/** * Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it. * * @param s the string to decode * @return the decoded data */ public static byte[] decode( String s ) { return decode(s, NO_OPTIONS); }
/** * {@inheritDoc} * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return HashCode.compute(status, code, message, resource, location); }
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source The data to convert * @return the encoded bytes */ public static String encodeBytes( byte[] source ) { return encodeBytes(source, 0, source.length, NO_OPTIONS); }
/** * Write the entire contents of the supplied string to the given stream. This method always flushes and closes the stream when * finished. * * @param content the content to write to the stream; may be null * @param stream the stream to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the stream is null */ public static void write( String content, OutputStream stream ) throws IOException { IoUtil.write(content, stream); }
/** * Suspends encoding of the stream. May be helpful if you need to embed a piece of base640-encoded data in a stream. * * @throws IOException * @since 1.5.1 */ public void suspendEncoding() throws IOException { flushBase64(); this.suspendEncoding = true; }
@Override public String toString() { return digestName(); } }
/** * Combine the lines into a single string, using the new line character as the delimiter. This is compatible with * {@link #splitLines(String)}. * * @param lines the lines to be combined * @return the combined lines, or an empty string if there are no lines */ public static String combineLines( String[] lines ) { return combineLines(lines, '\n'); }
/** * Serializes an object and returns the Base64-encoded version of that serialized object. If the object cannot be serialized * or there is another error, the method will return <tt>null</tt>. The object is not GZip-compressed before being encoded. * * @param serializableObject The object to encode * @return The Base64-encoded object * @throws IOException if there is an IOException while serializing */ public static String encodeObject( java.io.Serializable serializableObject ) throws IOException { return encodeObject(serializableObject, NO_OPTIONS); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param stream the stream containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the stream */ public static byte[] getHash( Algorithm algorithm, InputStream stream ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), stream); }
/** * Create an encoder that uses the supplied algorithm and returns only the supplied number of characters in the hash. * * @param algorithm the algorithm that should be used * @param maxLength the maximumLength, or a non-positive number (or {@link Integer#MAX_VALUE}) if the full hash should be used * @throws IllegalArgumentException if the algorithm is null */ public SecureHashTextEncoder( Algorithm algorithm, int maxLength ) { CheckArg.isNotNull(algorithm, "algorithm"); this.algorithm = algorithm; this.maxLength = maxLength < 1 ? Integer.MAX_VALUE : maxLength; }
/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read( InputStream stream ) throws IOException { return IoUtil.read(stream); }
/** * Compute a combined hash code from the supplied objects. This method always returns 0 if no objects are supplied. * * @param objects the objects that should be used to compute the hash code * @return the hash code */ public static int compute( Object... objects ) { return compute(0, objects); }
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source The data to convert * @param off Offset in array where conversion should begin * @param len Length of data * @return the encoded bytes */ public static String encodeBytes( byte[] source, int off, int len ) { return encodeBytes(source, off, len, NO_OPTIONS); }
/** * Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when * finished. * * @param content the content to write to the writer; may be null * @param writer the writer to which the content is to be written * @throws IOException * @throws IllegalArgumentException if the writer is null */ public static void write( String content, Writer writer ) throws IOException { IoUtil.write(content, writer); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param file the file containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the file */ public static byte[] getHash( Algorithm algorithm, File file ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), file); }