Package overit.geocall.util
Class FileUtils
java.lang.Object
overit.geocall.util.FileUtils
This class exposes a series of utility method that can be used in the File management
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckContentType(File content, String expectedType) Perform a check between the real type of the content and the one that is supposed to bestatic booleancheckContentType(InputStream content, String name, String expectedType) static booleancheckContentType(UpFile content, String expectedType) Perform a check between the real type of the content and the one that is supposed to bestatic intReturns the number of entries of the zippedWebResourcepassed as parameterstatic voidDeletes aFilestatic voidstatic booleanCopies the input File in the output Filestatic booleanMoves aFilestatic InputStreamReaderReturns theInputStreamReaderwith BOM (see www.unicode.org/faq/utf_bom.html))static InputStreamReadergetBOMInputStreamReader(InputStream is, String defCharset) Returns theInputStreamReaderwith BOM (see www.unicode.org/faq/utf_bom.html))static OutputStreamWritergetBOMOutputStreamWriter(OutputStream os, String charset) Returns theOutputStreamWriterwith BOM (see www.unicode.org/faq/utf_bom.html))static OutputStreamWritergetBOMOutputStreamWriter(OutputStream os, Charset charset) Returns theOutputStreamWriterwith BOM (see www.unicode.org/faq/utf_bom.html))static StringgetContentTypeFromStream(String resourceName, InputStream is) Gets the real content-type from the stream passed in Input.static StringnormalizeFileName(String name) Performs a replacement of the characters not allowed in the construction of a file namestatic StringPerforms a replacement of the characters not allowed in the construction of a string that will be used as querystring valuestatic WebResourceunzipFile(WebResource wr) Unzips theWebResourcespassed as parameterstatic StringunzipWebResource(WebResource wr, boolean creaDirectory) Unzips theWebResourcepassed as parameterstatic StringunzipWebResource(WebResource wr, WebResource dir, boolean creaDirectory) Unzips theWebResourcepassed as parameterstatic StringunzipWebResourceTree(WebResource wr, boolean creaDirectory) Unzips theWebResourcepassed as parameter and all its sub tree.static StringunzipWebResourceTree(WebResource wr, WebResource dir, boolean creaDirectory) Unzips theWebResourcepassed as parameter and its sub tree.static booleanvalidateFileContentType(File file, List<String> acceptedExtensions) static booleanvalidateFileContentType(UpFile upFile, List<String> acceptedExtensions) Verifies that the uploaded file has a content type that conforms to the rules defined by the "accept" attribute.
If t's not possible to find the uploaded file's contentType or the contentTypes defined by the "accept" attribute, a validation will be carried out on the type of the uploaded file based on its extension.static booleanxlsx2csv(InputStream is, OutputStream os) Transforms the source file, in XLSX format, in an output file in CSV formatstatic booleanxlsx2csv(InputStream is, String sheet, OutputStream os) Transforms the source file, in XLSX format, in an output file in CSV formatstatic voidCompresses files represented in an array of pathsstatic voidCompresses a list of files to a destination zip file
-
Constructor Details
-
FileUtils
protected FileUtils()
-
-
Method Details
-
delete
Deletes aFile- Parameters:
f- TheFileto delete
-
delete
- Throws:
IOException
-
fCopy
Copies the input File in the output File- Parameters:
inputFile- The source fileoutputFile- The destination file- Returns:
trueif the copy was successful,falseotherwise
-
fMove
Moves aFile- Parameters:
inputFile- The source fileoutputFile- The destination file- Returns:
trueif the operation is successful,falseotherwise
-
unzipFile
Unzips theWebResourcespassed as parameter- Parameters:
wr- The resource to unzip- Returns:
- The unzipped resource
-
countZipEntryes
Returns the number of entries of the zippedWebResourcepassed as parameter- Parameters:
wr- The zipped resource- Returns:
- The number of entries of the zipped resource, or -1 if there is an exception during the count
-
unzipWebResource
Unzips theWebResourcepassed as parameter- Parameters:
wr- The WebResource to unzipcreaDirectory-trueto create a new directory,falseotherwise- Returns:
nullif the operation is successful, the string that contains the message of the exsception if some orrer occurs
-
unzipWebResource
Unzips theWebResourcepassed as parameter- Parameters:
wr- The WebResource to unzipdir- The WebResource directory in which unzip the sourcecreaDirectory-trueto create a new directory,falseotherwise- Returns:
nullif the operation is successfull, the string that contains the message of the exsception if some orrer occurs
-
unzipWebResourceTree
Unzips theWebResourcepassed as parameter and all its sub tree.- Parameters:
wr- The WebResource to unzipcreaDirectory-trueto create a new directory,falseotherwise- Returns:
nullif the operation is successful, the string that contains the message of the exsception if some orrer occurs
-
unzipWebResourceTree
Unzips theWebResourcepassed as parameter and its sub tree.- Parameters:
wr- The WebResource to unzipdir- The WebResource directory in which unzip the sourcecreaDirectory-trueto create a new directory,falseotherwise- Returns:
nullif the operation is successfull, the string that contains the message of the exsception if some orrer occurs
-
xlsx2csv
Transforms the source file, in XLSX format, in an output file in CSV format- Parameters:
is- TheInputStreamthat represents the XLSX file to transformsheet- The string that defines the sheet nameos- TheOutputStreamin which write the uncompressed file- Returns:
trueif the operation is successful,falseotherwise
-
xlsx2csv
Transforms the source file, in XLSX format, in an output file in CSV format- Parameters:
is- TheInputStreamthat represents the XLSX file to transformos- TheOutputStreamin which write the uncompressed file- Returns:
trueif the operation is successful,falseotherwise
-
getBOMInputStreamReader
Returns theInputStreamReaderwith BOM (see www.unicode.org/faq/utf_bom.html))- Parameters:
is- TheInputStreamthat represents the source- Returns:
- The
InputStreamReaderwith BOM - Throws:
IOException- If an error occurs anIOExceptionwill be trown
-
getBOMInputStreamReader
public static InputStreamReader getBOMInputStreamReader(InputStream is, String defCharset) throws IOException Returns theInputStreamReaderwith BOM (see www.unicode.org/faq/utf_bom.html))- Parameters:
is- TheInputStreamthat represents the sourcedefCharset- The string that represents the default charset- Returns:
- The
InputStreamReaderwith BOM - Throws:
IOException- If an error occurs anIOExceptionwill be trown
-
getBOMOutputStreamWriter
public static OutputStreamWriter getBOMOutputStreamWriter(OutputStream os, String charset) throws IOException Returns theOutputStreamWriterwith BOM (see www.unicode.org/faq/utf_bom.html))- Parameters:
os- TheOutputStreamWriterthat represents the sourcecharset- The string that represents the charset- Returns:
- The
OutputStreamWriterwith BOM - Throws:
IOException- If an error occurs anIOExceptionwill be trown
-
getBOMOutputStreamWriter
public static OutputStreamWriter getBOMOutputStreamWriter(OutputStream os, Charset charset) throws IOException Returns theOutputStreamWriterwith BOM (see www.unicode.org/faq/utf_bom.html))- Parameters:
os- TheOutputStreamWriterthat represents the sourcecharset- The charset- Returns:
- The
OutputStreamWriterwith BOM - Throws:
IOException- If an error occurs anIOExceptionwill be trown
-
normalizeFileName
Performs a replacement of the characters not allowed in the construction of a file name- Parameters:
name- The name to be normalized- Returns:
- The normalized name
-
normalizeQueryStringName
Performs a replacement of the characters not allowed in the construction of a string that will be used as querystring value- Parameters:
name- the string to be normalized- Returns:
- the normalized string
-
checkContentType
Perform a check between the real type of the content and the one that is supposed to be- Parameters:
content- the file to checkexpectedType- the supposed file contentType- Returns:
trueif the types match,falseotherwise- Throws:
IOException- in case of some problem during the content's reading
-
checkContentType
Perform a check between the real type of the content and the one that is supposed to be- Parameters:
content- the upfile to checkexpectedType- the supposed file contentType- Returns:
trueif the types match,falseotherwise- Throws:
IOException- in case of some problem during the content's reading
-
checkContentType
public static boolean checkContentType(InputStream content, String name, String expectedType) throws IOException - Throws:
IOException
-
getContentTypeFromStream
public static String getContentTypeFromStream(String resourceName, InputStream is) throws IOException Gets the real content-type from the stream passed in Input.- Parameters:
resourceName- The name of the fileis- The InputStream from which retrieve the content-type.- Returns:
- The real content-type from the stream passed in Input.
- Throws:
IOException
-
zip
Compresses a list of files to a destination zip file- Parameters:
listFiles- A collection of files and directoriesdestZipFile- The path of the destination zip file- Throws:
FileNotFoundException- if the file is not foundIOException- if an I/O error occurs
-
zip
Compresses files represented in an array of paths- Parameters:
files- a String array containing file pathsdestZipFile- The path of the destination zip file- Throws:
FileNotFoundException- if the file is not foundIOException- if an I/O error occurs
-
validateFileContentType
Verifies that the uploaded file has a content type that conforms to the rules defined by the "accept" attribute.
If t's not possible to find the uploaded file's contentType or the contentTypes defined by the "accept" attribute, a validation will be carried out on the type of the uploaded file based on its extension.- Parameters:
upFile- The uploaded file to be validated.acceptedExtensions- A list of contentType and extensions, separated by comma, which define the file types that will be accepted.- Returns:
trueif theUpFileit's valid,falseotherwise.
-
validateFileContentType
-