Commonly used Java tools - sixteen kinds

Commonly used Java tools - sixteen kinds

 

In Java, the utility class defines a set of common methods, this article describes the most frequently used in Java and the most common Java tools. The following tools, methods by using the popularity ranking on Github reference data from randomly selected 50 000 open source projects.

一. org.apache.commons.io.IOUtils

closeQuietly: Close an IO stream, socket, or selector does not throw an exception, generally placed in the finally block
toString: conversion IO streams, Uri, byte [] is the String
Copy: Copy data stream IO, written to the output stream from the input stream , up to 2GB
the toByteArray: from the input stream, acquires the URI byte []
write:. the byte characters and the like to the output stream
toInputStream: convert characters to the input stream
readLines: multiple rows of data read from the input stream, returned List < String>
copyLarge: copy the same, the above data support the replication of 2GB
lineIterator: returns a stream from the input iterator, the amount of data required parameters read, reading all, if the data is not enough, the failure
two org.apache.commons.. io.FileUtils

deleteDirectory: Delete the folder
readFileToString: read the contents of the file in characters
deleteQueitly: delete a file or folder and does not throw
copyFile: Copy the file
writeStringToFile: the character written to the target file, if the file does not exist, create
forceMkdir: mandatory create a folder, if the folder parent directory does not exist, create parent
write: the character written to the specified file
listFiles: lists files in a directory (according to filter)
CopyDirectory: copy the folder
forceDelete: forced to delete file
three. org.apache.commons.lang.StringUtils

isBlank: the string is empty (determined after trim)
isEmpty: whether the string is empty (no trim and determine)
the equals: if the strings are equal
join: single merge array string, separator can pass
split: split the string
EMPTY : returns the empty string
trimToNull: trim empty string after the conversion to null
replace: replacement string
four org.apache.http.util.EntityUtils.

toString: The Entity converted to strings
consume: Entity ensure that the content of all consumed. You can see the source code in another Entity of content consumed, if the user does not consume, then it will be time to call Entity consumed
toByteArray: Entity converted into a byte stream
consumeQuietly: and consume the same, but do not throw an exception
getContentCharset: get encoded content of
five. org.apache.commons.lang3.StringUtils

isBlank: the string is empty (determined after trim)
isEmpty: whether the string is empty (no trim and determine)
the equals: if the strings are equal
join: single merge array string, separator can pass
split: split the string
EMPTY : returns an empty string
replace: replacement string
capitalize: The first character uppercase
six org.apache.commons.io.FilenameUtils.

getExtension: Returns the file extension
getBaseName: Returns the file name does not contain a suffix
getName: return the full file name
concat: a combination of command-line-style file paths (see method Notes)
removeExtension: Delete extension
normalize: the path to normalization
wildcardMatch: wildcard that matches
seperatorToUnix: path separator to the unix system format, i.e. /
GetFullPath: obtaining the file path, the file name does not include the
isExtension: checking a file extension is not passed parameter (List <String>) of
VII ORG. springframework.util.StringUtils

hasText: Check if string contains text
hasLength: detecting whether the character string length is greater than 0
isEmpty: detecting whether the string is empty (if incoming object, it is determined whether the object is null)
commaDelimitedStringToArray: String to comma-delimited array
collectionToDelimitedString : the collection into CSV format string
replace replace string
7. delimitedListToStringArray: the equivalent split
uncapitalize: the first letter lowercase
collectionToDelimitedCommaString: the collection into CSV format string
tokenizeToStringArray: split and essentially the same, but it can automatically remove blank word
eight . org.apache.commons.lang.ArrayUtils

contains: if a certain string
addAll: Add the entire array
clone: clone an array
isEmpty: whether empty array
add: add elements to the array
subarray: Array taken
indexOf: find the index of an element
isEquals: compare arrays equality
toObject: base type data array into a corresponding array of Object
nine. org.apache.commons.lang.StringEscapeUtils

Reference fifteen: org.apache.commons.lang3.StringEscapeUtils
. Ten org.apache.http.client.utils.URLEncodedUtils

format: formatting parameters, returns an HTTP POST or HTTP PUT available application / x-www-form- urlencoded string
parse: URI, or the like into String List <NameValuePair>
eleven org.apache.commons.codec.digest. .DigestUtils

md5Hex: MD5 encryption, returns a 32 bit string
sha1Hex: SHA-1 encryption
sha256Hex: SHA-256 encryption
sha512Hex: SHA-512 encryption
md5: MD5 encrypted string 16 returns
twelve org.apache.commons.collections.CollectionUtils.

isEmpty: is empty
select: set of filter elements according to the conditions
transform: collection element according to the specified processing method, similar to the List Map ()
filter: the filter element, Lysi List of filter ()
Find: select as basic and
collect: and almost transform the same, but returns a new array
forAllDo: call the specified method for each element
isEqualCollection: to determine whether two sets consistent
Thirteen org.apache.commons.lang3.ArrayUtils

contains: contains a string
addAll: Add the entire array
clone: clone an array
isEmpty: whether empty array
add: add elements to the array
subarray: Array taken
indexOf: find the index of an element
isEquals: compare arrays equality
toObject: base type data array into a corresponding array of Object
fourteen. org.apache.commons.beanutils.PropertyUtils

getProperty: Get Object property value
setProperty: set the object property value
getPropertyDiscriptor: Get Attribute Descriptor
isReadable: Check the attribute accessible
copyProperties: Attribute values are copied from one object to another
getPropertyDiscriptors: Get all the properties Descriptor
isWriteable: Check the attribute write
getPropertyType: get an object attribute types
fifteen org.apache.commons.lang3.StringEscapeUtils.

unescapeHtml4: Escape HTML
escapeHtml4: unescape HTML
escapeXml: Escape xml
unescapeXml: unescape xml
escapeJava: Escape unicode encoded
escapeEcmaScript: EcmaScript escape character
unescapeJava: unescapes unicode encoded
escapeJson: json escape character
escapeXml10: turn Yi Xml10
this has now been abandoned, it is recommended to use commons-text package inside the method.

Sixteen. Org.apache.commons.beanutils.BeanUtils

copyPeoperties: Attribute values are copied from one object to another
getProperty: Get Object property value
setProperty: set the object attribute values
populate: Map according to the attribute copy
copyPeoperty: copy a single value, from one object to another
cloneBean: Cloning bean instance
now you just have to know more than 16 of the most popular tools class method, you would not be necessary and then write their own tools, and need not be repeated-create the wheel. Most of the tools by which class method name can understand its purpose, if not clear, you can look at how others are using, or go online to check their usage.

Guess you like

Origin www.cnblogs.com/coder-wzr/p/11711767.html