public class FileUtil extends Object
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
compressDir(String dirPath,
String archiveName)
Compresses local directory to the archiveName
|
static void |
copy(InputStream is,
OutputStream os)
writes the data from the input stream to the provided output stream
|
static BufferedReader |
createBufferedUtf8Reader(File file)
Opens a file given by a path and returns its
BufferedReader using the
UTF-8 encoding |
static BufferedReader |
createBufferedUtf8Reader(InputStream is)
Creates a
BufferedReader on the top of the given InputStream using the
UTF-8 encoding |
static BufferedReader |
createBufferedUtf8Reader(String path)
Opens a file given by a path and returns its
BufferedReader using the
UTF-8 encoding |
static BufferedReader |
createBufferedUtf8Reader(URL url)
Opens a URL and returns its
BufferedReader using the UTF-8 encoding |
static BufferedWriter |
createBufferedUtf8Writer(File file)
Opens a file given by a path and returns its
BufferedWriter using the
UTF-8 encoding |
static BufferedWriter |
createBufferedUtf8Writer(String path)
Opens a file given by a path and returns its
BufferedWriter using the
UTF-8 encoding |
static BufferedWriter |
createBufferedUtf8Writer(String path,
boolean append)
Opens a file given by a path and returns its
BufferedWriter using the
UTF-8 encoding |
static File |
createTempDir()
Create a new temporary directory.
|
static File |
createTempDir(String baseDir)
Create a new temporary directory.
|
static CSVWriter |
createUtf8CsvEscapingWriter(File file)
Creates a UTF-8
CSVWriter of the given file. |
static CSVReader |
createUtf8CsvReader(File file)
Creates a UTF-8
CSVReader of the given file. |
static CSVReader |
createUtf8CsvReader(File file,
char separator)
Creates a UTF-8
CSVReader of the given file. |
static CSVReader |
createUtf8CsvReader(InputStream inputStream)
Creates a UTF-8
CSVReader of the given inputStream. |
static CSVReader |
createUtf8CsvReader(InputStream inputStream,
char separator)
Creates a UTF-8
CSVReader of the given inputStream. |
static CSVWriter |
createUtf8CsvWriter(File file)
Creates a UTF-8
CSVWriter of the given file. |
static CSVWriter |
createUtf8CsvWriter(OutputStream outputStream)
Creates a UTF-8
CSVWriter of the given outputStream. |
static String[] |
getCsvHeader(URL url,
char separator)
Retrieves CSV headers from an URL
|
static String[] |
getCsvHeader(URL url,
CsvConfiguration csvConfiguration)
Retrieves CSV headers from an URL
|
static File |
getFile(String fileName)
Constructs a new File and checks if it exists
|
static File |
getFile(String fileName,
boolean ignoreMissingFile)
Constructs a new File and optionally checks if it exists
|
static String |
getFileName(URL url)
returns the last element of the URL's path
|
static CSVReader |
getResourceAsCsvReader(String path)
Creates a UTF-8
CSVReader of the resource on classpath represented by
given path. |
static File |
getTempFile()
Create a new temporary file.
|
static net.sf.json.JSONObject |
readJSONFromFile(String fileName)
Reads a JSON object from a file
|
static String |
readStringFromClasspath(String path,
Class c)
Reads the entire
InputStream and returns its content as a single String |
static String |
readStringFromFile(String fileName)
Reads the entire file and returns its content as a single
String |
static String |
readStringFromStream(InputStream is)
Reads the entire
InputStream and returns its content as a single String |
static boolean |
recursiveDelete(File fileOrDir)
Recursively delete file or directory
|
static void |
writeJSONToFile(net.sf.json.JSON content,
String fileName)
Writes a JSON object to a file.
|
static void |
writeStringToFile(String content,
String fileName)
Writes a string to a file.
|
static void |
writeStringToFile(String content,
String fileName,
boolean append)
Writes a string to a file.
|
public static void compressDir(String dirPath, String archiveName) throws IOException
dirPath
- path to the directoryarchiveName
- the name of the ZIP archive that is going to be createdIOException
public static void copy(InputStream is, OutputStream os) throws IOException
is
- os
- IOException
public static File createTempDir() throws IOException
recursiveDelete(File)
to clean this directory up since it isn't
deleted automaticallyIOException
- if there is an error creating the temporary directorypublic static File createTempDir(String baseDir) throws IOException
recursiveDelete(File)
to clean this directory up since it isn't
deleted automaticallyroot
- directory where new directory will be createdIOException
- if there is an error creating the temporary directorypublic static File getTempFile() throws IOException
IOException
- if there is an error creating the temporary filepublic static boolean recursiveDelete(File fileOrDir)
fileOrDir
- the file or dir to deletepublic static void writeStringToFile(String content, String fileName) throws IOException
content
- the contentfileName
- the fileIOException
public static void writeStringToFile(String content, String fileName, boolean append) throws IOException
content
- the contentfileName
- the fileappend
- should be the content appended?IOException
public static String readStringFromFile(String fileName) throws IOException
String
fileName
- the fileIOException
public static void writeJSONToFile(net.sf.json.JSON content, String fileName) throws IOException
content
- the contentfileName
- the fileIOException
public static net.sf.json.JSONObject readJSONFromFile(String fileName) throws IOException
fileName
- the fileIOException
public static String readStringFromStream(InputStream is) throws IOException
InputStream
and returns its content as a single String
is
- the fileIOException
public static String readStringFromClasspath(String path, Class c) throws IOException
InputStream
and returns its content as a single String
path
- the loacation of the file on the CLASSPATH (e.g. /com/gooddata/processor/COMMANDS.txt)c
- Class for determining the Java classloaderIOException
public static String[] getCsvHeader(URL url, CsvConfiguration csvConfiguration) throws IOException
url
- CSV urlIOException
- in case of IO issuespublic static String[] getCsvHeader(URL url, char separator) throws IOException
url
- CSV urlIOException
- in case of IO issuespublic static File getFile(String fileName, boolean ignoreMissingFile) throws IOException
fileName
- file nameignoreMissingFile
- flag that ignores the fact that the file doesn't existsIOException
- if the file doesn't exists and the ignoreMissingFile is falsepublic static File getFile(String fileName) throws IOException
fileName
- file nameIOException
- if the file doesn't existspublic static String getFileName(URL url)
url
- to parsepublic static BufferedReader createBufferedUtf8Reader(String path) throws IOException
BufferedReader
using the
UTF-8 encodingpath
- path to a file to be readIOException
public static BufferedWriter createBufferedUtf8Writer(String path) throws IOException
BufferedWriter
using the
UTF-8 encodingpath
- path to a file to write toIOException
public static BufferedWriter createBufferedUtf8Writer(String path, boolean append) throws IOException
BufferedWriter
using the
UTF-8 encodingpath
- path to a file to write toappend
- should be the content appended?IOException
public static BufferedReader createBufferedUtf8Reader(File file) throws IOException
BufferedReader
using the
UTF-8 encodingfile
- file to be readIOException
public static BufferedWriter createBufferedUtf8Writer(File file) throws IOException
BufferedWriter
using the
UTF-8 encodingfile
- file to write toIOException
public static BufferedReader createBufferedUtf8Reader(URL url) throws IOException
BufferedReader
using the UTF-8 encodingurl
- to be readIOException
public static BufferedReader createBufferedUtf8Reader(InputStream is) throws IOException
BufferedReader
on the top of the given InputStream
using the
UTF-8 encodingis
- file to be readIOException
public static CSVReader getResourceAsCsvReader(String path) throws IOException
CSVReader
of the resource on classpath represented by
given path. Calls Class.getResourceAsStream(String)
internally to create
the underlying InputStream
.path
- IOException
public static CSVReader createUtf8CsvReader(File file) throws IOException
CSVReader
of the given file.file
- IOException
public static CSVReader createUtf8CsvReader(File file, char separator) throws IOException
CSVReader
of the given file.file
- separator
- field separatorIOException
public static CSVReader createUtf8CsvReader(InputStream inputStream, char separator) throws IOException
CSVReader
of the given inputStream.inputStream
- separator
- field separatorIOException
public static CSVReader createUtf8CsvReader(InputStream inputStream) throws IOException
CSVReader
of the given inputStream.inputStream
- IOException
public static CSVWriter createUtf8CsvWriter(File file) throws IOException
CSVWriter
of the given file.file
- IOException
public static CSVWriter createUtf8CsvWriter(OutputStream outputStream) throws IOException
CSVWriter
of the given outputStream.outputStream
- IOException
public static CSVWriter createUtf8CsvEscapingWriter(File file) throws IOException
CSVWriter
of the given file.file
- IOException
Copyright © 2014. All rights reserved.