public final class IOUtils extends Object
Utility class built on top of the java.io
package helping WUIC to deal with
I/O.
Modifier and Type | Class and Description |
---|---|
static class |
IOUtils.CrcMessageDigest
A
CRC32 is wrapped inside this class which is a MessageDigest . |
Modifier and Type | Field and Description |
---|---|
static String |
STD_SEPARATOR
The slash character is the standard separator used internally, even on windows platform.
|
static int |
WUIC_BUFFER_LEN
Length of a memory buffer used in WUIC.
|
static int |
ZIP_MAGIC_NUMBER
All ZIP files begins with this magic number.
|
Modifier and Type | Method and Description |
---|---|
static Path |
buildPath(String path)
Returns a hierarchy of
paths represented by the given String . |
static Path |
buildPath(String path,
DirectoryPathFactory factory)
Returns a hierarchy of
paths represented by the given String . |
static void |
close(Closeable... closeableArray)
Tries to close the given objects and log the
IOException at INFO level
to make the code more readable when we assume that the IOException won't be managed. |
static int |
copyStream(InputStream is,
OutputStream os)
Copies the data from the given input stream into the given output stream and doesn't wrap any
IOException . |
static void |
copyStreamToWriterIoe(InputStream is,
Writer writer,
String cs)
Copies the data from the given input stream into the given writer and does not wrap the
IOException . |
static void |
delete(File file)
Deletes the
File quietly. |
static byte[] |
digest(byte[]... bytes)
Digests each
byte array in the given array and return the corresponding signature. |
static byte[] |
digest(String... strings)
Digests each
String in the given array and return the corresponding signature. |
static Boolean |
isArchive(File file)
Checks if the path path points to a a valid ZIP archive.
|
static Boolean |
isArchive(InputStream inputStream)
Checks if the given stream points represents a valid ZIP archive.
|
static List<String> |
listFile(DirectoryPath parent,
Pattern pattern)
Lists all the files from the given directory matching the given pattern.
|
static List<String> |
listFile(DirectoryPath parent,
Pattern pattern,
List<String> skipStartsWithList)
Searches as specified in
listFile(com.github.wuic.path.DirectoryPath, java.util.regex.Pattern) with
a list that contains all begin paths to ignore. |
static List<String> |
listFile(DirectoryPath parent,
String relativePath,
Pattern pattern,
List<String> skipStartsWithList)
Lists the files matching the given pattern in the directory path and its subdirectory represented by
a specified
relativePath . |
static List<String> |
listFile(DirectoryPath parent,
String relativePath,
String endWith,
List<String> skipStartsWithList)
Lists the files ending with the given
Sting in the directory path.. |
static String |
mergePath(String... paths)
Merges the given
String array with the standard separator . |
static MessageDigest |
newMessageDigest()
Returns a new
MessageDigest based on CRC algorithm. |
static String |
normalizePathSeparator(String path)
Makes sure a given path uses the slash character has path separator by replacing all backslashes.
|
static String |
readString(InputStreamReader reader)
Reads the given reader and returns its content in a
String . |
public static final String STD_SEPARATOR
public static final int WUIC_BUFFER_LEN
public static final int ZIP_MAGIC_NUMBER
public static MessageDigest newMessageDigest()
Returns a new MessageDigest
based on CRC algorithm.
public static byte[] digest(String... strings)
Digests each String
in the given array and return the corresponding signature.
strings
- the string arraypublic static byte[] digest(byte[]... bytes)
Digests each byte
array in the given array and return the corresponding signature.
bytes
- the byte arrayspublic static String mergePath(String... paths)
Merges the given String
array with the standard separator
.
paths
- the paths to be mergedpublic static String normalizePathSeparator(String path)
Makes sure a given path uses the slash character has path separator by replacing all backslashes.
path
- the path to normalizepublic static void close(Closeable... closeableArray)
Tries to close the given objects and log the IOException
at INFO level
to make the code more readable when we assume that the IOException
won't be managed.
Also ignore null
parameters.
closeableArray
- the objects to closepublic static String readString(InputStreamReader reader) throws IOException
Reads the given reader and returns its content in a String
.
reader
- the readerIOException
- if an I/O error occurspublic static void copyStreamToWriterIoe(InputStream is, Writer writer, String cs) throws IOException
Copies the data from the given input stream into the given writer and does not wrap the IOException
.
is
- the InputStream
writer
- the Writer
cs
- the charset to use to convert byte array to char arrayIOException
- in an I/O error occurspublic static int copyStream(InputStream is, OutputStream os) throws IOException
Copies the data from the given input stream into the given output stream and doesn't wrap any IOException
.
is
- the InputStream
os
- the OutputStream
IOException
- in an I/O error occurspublic static Boolean isArchive(File file) throws IOException
Checks if the path path points to a a valid ZIP archive.
file
- the path to checktrue
if path is an archive, false
otherwiseIOException
public static Boolean isArchive(InputStream inputStream) throws IOException
Checks if the given stream points represents a valid ZIP archive.
inputStream
- the stream to checktrue
if the stream should be an archive, false
otherwiseIOException
public static List<String> listFile(DirectoryPath parent, Pattern pattern) throws IOException
Lists all the files from the given directory matching the given pattern.
For instance, if a directory /foo contains a path in foo/oof/path.js, calling this method with an Pattern
.* will result in an array containing the String
oof/path.js
.
parent
- the directorypattern
- the pattern to filter filesIOException
- if any I/O error occurspublic static List<String> listFile(DirectoryPath parent, Pattern pattern, List<String> skipStartsWithList) throws IOException
Searches as specified in listFile(com.github.wuic.path.DirectoryPath, java.util.regex.Pattern)
with
a list that contains all begin paths to ignore.
parent
- the directorypattern
- the pattern to filter filesskipStartsWithList
- a list that contains all begin paths to ignoreIOException
- if any I/O error occurspublic static List<String> listFile(DirectoryPath parent, String relativePath, String endWith, List<String> skipStartsWithList) throws IOException
Lists the files ending with the given Sting
in the directory path..
parent
- the parentrelativePath
- the directory path relative to the parentendWith
- the directory path relative to the parentskipStartsWithList
- a list that contains all begin paths to ignoreIOException
- if any I/O error occurspublic static List<String> listFile(DirectoryPath parent, String relativePath, Pattern pattern, List<String> skipStartsWithList) throws IOException
Lists the files matching the given pattern in the directory path and its subdirectory represented by
a specified relativePath
.
parent
- the parentrelativePath
- the directory path relative to the parentpattern
- the pattern which filters filesskipStartsWithList
- a list that contains all begin paths to ignoreIOException
- if any I/O error occurspublic static Path buildPath(String path, DirectoryPathFactory factory) throws IOException
Returns a hierarchy of paths
represented by the given String
. The given DirectoryPathFactory
is used to create directories.
path
- the path hierarchyfactory
- the factory.Path
of the hierarchy with its parentIOException
- if any I/O error occurspublic static Path buildPath(String path) throws IOException
Returns a hierarchy of paths
represented by the given String
.
Uses a FsDirectoryPathFactory
to create instances.
path
- the path hierarchyPath
of the hierarchy with its parentIOException
- if any I/O error occursCopyright © 2012-2015. All Rights Reserved.