public class FileHelper
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileHelper.MimeTypes |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ESCPAE_HTML |
static java.lang.String |
PROTOCOL_FILE |
Constructor and Description |
---|
FileHelper()
Constructor of FileHelper
|
FileHelper(java.io.File file)
Constructor of FileHelper
|
FileHelper(java.io.File file,
boolean createDirs)
Constructor of FileHelper
|
FileHelper(java.lang.String resourceURL)
Constructor of FileHelper
|
FileHelper(java.lang.String resourceURL,
boolean createDirs) |
FileHelper(java.net.URL resourceURL)
Constructor of FileHelper
|
FileHelper(java.net.URL resourceURL,
boolean createDirs)
Constructor of FileHelper
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
absolutePath(java.lang.String relative,
java.lang.String absoluteTo,
boolean urlMode) |
static java.lang.String |
bytesIntoHumanReadable(long bytes) |
static long |
calculateChecksum(java.io.InputStream is)
Calculates the checksum of the given InputStream.
|
static long |
calculateChecksum(java.io.InputStream is,
java.util.zip.Checksum algorithm)
Calculates the checksum of the given InputStream.
|
static java.lang.String |
cleanFileName(java.lang.String fileName) |
static java.lang.String |
cleanFileName(java.lang.String fileName,
char replacement) |
void |
closeFileEntry()
Close all output streams of the FileHelper instance.
|
static void |
closeStream(java.io.Closeable s) |
static java.lang.String |
concatPaths(java.lang.String templateLocation,
java.lang.String templateName) |
static void |
copy(java.io.File source,
java.io.File destination)
Copy a file from source to destination
|
static void |
copy(java.net.URL source,
java.io.File destination)
Copy a file from source to destination
|
static void |
copy(java.net.URL source,
java.net.URL destination)
Copy a file from source to destination
|
static java.io.OutputStream |
decodeZipBase64(java.io.InputStream in,
java.io.OutputStream out,
boolean base64,
boolean zip) |
static void |
deleteDir(java.io.File[] file,
boolean deep) |
static void |
deleteDir(java.io.File file,
boolean deep) |
static boolean |
deleteFile(java.io.File tempFile) |
static boolean |
deleteFile(java.lang.String file) |
static java.io.OutputStream |
encode(java.io.InputStream inStream,
java.io.OutputStream out,
boolean base64,
boolean zip,
boolean doFlush) |
static java.io.OutputStream |
encode(java.io.InputStream inStream,
java.io.OutputStream out,
boolean base64,
boolean zip,
boolean doFlush,
boolean buffered) |
static boolean |
fileExist(java.io.File file)
check if a file exists.
|
static boolean |
fileExist(java.lang.String file)
check if a file exists.
|
java.io.File[] |
getAllDrives() |
static java.io.File |
getDirectory(java.io.File source) |
static java.lang.String |
getDirectory(java.lang.String completeFile) |
static java.lang.String |
getDirectory(java.lang.String completeFile,
boolean returnFileIfNone) |
static java.io.File |
getDirectory(java.net.URL fileToOpen) |
static java.lang.String |
getFileName(java.io.File completeFile) |
static java.lang.String |
getFileName(java.lang.String fileName) |
static java.lang.String |
getFileName(java.lang.String fileName,
boolean includeExt) |
static java.lang.String |
getFileNameExtension(java.io.File file) |
static java.lang.String |
getFileNameExtension(java.io.File file,
boolean includeDot) |
static java.lang.String |
getFileNameExtension(java.lang.String fileName,
boolean includeDot) |
static JSONObject |
getFileSystemInfo() |
static java.lang.StringBuffer |
getFileSystemOverview() |
long |
getFreeSpace() |
static java.io.Reader |
getReader(org.w3c.dom.ls.LSInput xsdInput) |
static boolean |
isChecksumValid(java.io.InputStream is,
long checksum)
Checks if the passed Inputstream has the same checksum as the passed checksum value.
|
static boolean |
isChecksumValid(java.io.InputStream is,
long checksum,
java.util.zip.Checksum algorithm)
Checks if the passed Inputstream has the same checksum as the passed checksum value.
|
static boolean |
isFileTextResource(java.lang.String fileName) |
static boolean |
isTextResourceExtension(java.lang.String extension) |
static void |
main(java.lang.String[] args) |
static boolean |
mkdirs(java.io.File file,
boolean includingLeaf)
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.
|
void |
openFileEntry(java.net.URL filename)
Open a FileOutputStream for the given URL.
|
void |
openFileEntry(java.net.URL filename,
boolean createDirs)
Open a FileOutputStream for the given URL.
|
static int[] |
parseLines(byte[] seekbuffer,
int rows,
java.lang.StringBuffer sb) |
static byte[] |
read(java.io.InputStream in)
Reads a file and returns the content as bytearray.
|
static byte[] |
read(java.io.Reader in) |
static java.lang.String |
readAsString(java.io.InputStream in,
java.lang.String encoding)
Reads a file and returns the content as String.
|
static java.lang.String |
readAsString(java.io.Reader in) |
static java.lang.String[][] |
readDelimFile(java.io.LineNumberReader reader,
java.lang.String delim) |
static java.lang.String[][] |
readDelimFile(java.net.URL fileUrl,
java.lang.String delim) |
static byte[] |
readFile(java.io.File file)
Reads a file and returns the content as bytearray.
|
static byte[] |
readFile(java.lang.String filename)
Reads a file and returns the content as bytearray.
|
static byte[] |
readFile(java.net.URL fileUrl)
Reads a file and returns the content as bytearray.
|
static byte[] |
readFile(java.net.URL fileUrl,
boolean resolve) |
static java.lang.String |
readFileAsString(java.io.File file) |
static java.lang.String |
readFileAsString(org.w3c.dom.ls.LSInput xsdInput) |
static java.lang.String |
readFileAsString(org.w3c.dom.ls.LSInput xsdInput,
int bufferLen) |
static java.lang.String |
readFileAsString(java.net.URL fileUrl) |
static java.lang.String |
readFileAsString(java.net.URL fileUrl,
java.lang.String encoding)
Reads a file and returns the content as String.
|
static java.lang.String |
relativePath(java.lang.String absolute,
java.lang.String relativeTo,
boolean urlMode) |
static java.lang.String |
removeFileName(java.lang.String completeFile) |
static java.lang.String |
removeFileNameExtension(java.lang.String fileName) |
static java.lang.String |
replaceFileExtension(java.lang.String fileName,
java.lang.String extension) |
static java.lang.String |
replaceFileName(java.lang.String file,
java.lang.String newName) |
static void |
save(java.lang.Object myObject,
java.lang.String filename)
Save a Java object into a file using java.io.ObjectOutputStream.
|
static void |
save(java.lang.StringBuffer buffer,
java.io.File file,
java.lang.String encoding) |
static boolean |
save(java.lang.String buffer,
java.io.File file) |
static void |
save(java.lang.String buffer,
java.io.File file,
java.lang.String encoding) |
static java.io.File |
saveTempFile(java.lang.String buffer,
java.lang.String prefix,
java.lang.String suffix,
java.io.File dir,
boolean deleteOnExit) |
static java.lang.String |
tail(java.lang.String fileName,
int lineCount) |
static void |
tail(java.lang.String fileName,
int lineCount,
int bufferSize,
java.io.Writer pw,
java.lang.String escapeAs) |
static void |
tail(java.lang.String fileName,
int lineCount,
java.io.PrintWriter writer,
java.lang.String escapeAs) |
static java.lang.StringBuffer |
tailLines(int rows,
java.lang.StringBuffer seekString) |
static java.io.OutputStream |
write(byte[] content,
OutputWrapper out) |
static java.io.OutputStream |
write(java.io.InputStream inStream,
java.io.OutputStream outstream) |
static java.io.OutputStream |
write(java.io.InputStream inStream,
java.io.OutputStream outstream,
boolean doFlush) |
static java.io.OutputStream |
write(java.io.InputStream inStream,
java.io.OutputStream outstream,
boolean doFlush,
boolean useBuffedOut) |
static java.io.OutputStream |
write(java.io.InputStream inStream,
java.io.OutputStream outstream,
boolean doFlush,
boolean useBuffedOut,
java.util.zip.CRC32 crc) |
static java.io.OutputStream |
write(java.io.InputStream inStream,
java.io.OutputStream outstream,
java.lang.String srcEncoding) |
static java.io.OutputStream |
write(java.io.InputStream inStream,
OutputWrapper out) |
static java.io.OutputStream |
write(java.io.Reader inReader,
java.io.OutputStream outwriter) |
static java.io.Writer |
write(java.io.Reader inReader,
java.io.Writer outwriter) |
static void |
write(java.lang.String buffer,
java.io.Writer writer) |
FileHelper |
writeIntoFile(byte[] in)
Write's the byte sequence into the opened outputstream.
|
FileHelper |
writeIntoFile(char[] in)
Write's the char sequence into the opened outputstream.
|
FileHelper |
writeIntoFile(java.io.InputStream in)
Streams the InputStream into the opened outputstream.
|
FileHelper |
writeIntoFile(java.io.Reader in)
Streams the Reader into the opened outputstream.
|
FileHelper |
writeIntoFile(java.lang.String in)
Write's the String into the opened outputstream.
|
public static final java.lang.String PROTOCOL_FILE
public static final java.lang.String ESCPAE_HTML
public FileHelper(java.lang.String resourceURL) throws java.io.FileNotFoundException, java.net.MalformedURLException
resourceURL
- java.io.FileNotFoundException
java.net.MalformedURLException
public FileHelper(java.lang.String resourceURL, boolean createDirs) throws java.io.FileNotFoundException, java.net.MalformedURLException
java.io.FileNotFoundException
java.net.MalformedURLException
public FileHelper(java.net.URL resourceURL) throws java.io.FileNotFoundException
resourceURL
- java.io.FileNotFoundException
public FileHelper(java.net.URL resourceURL, boolean createDirs) throws java.io.FileNotFoundException
resourceURL
- java.io.FileNotFoundException
public FileHelper(java.io.File file) throws java.io.FileNotFoundException, java.net.MalformedURLException
file
- java.io.FileNotFoundException
java.net.MalformedURLException
public FileHelper(java.io.File file, boolean createDirs) throws java.io.FileNotFoundException, java.net.MalformedURLException
file
- java.io.FileNotFoundException
java.net.MalformedURLException
public FileHelper() throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static final boolean deleteFile(java.io.File tempFile)
public static java.lang.String bytesIntoHumanReadable(long bytes)
public static void save(java.lang.Object myObject, java.lang.String filename)
myObject
- filename
- ObjectOutputStream
public static void closeStream(java.io.Closeable s)
public static byte[] readFile(java.lang.String filename) throws java.io.IOException
filename
- java.io.IOException
public static byte[] readFile(java.io.File file) throws java.io.IOException
file
- java.io.IOException
public static byte[] readFile(java.net.URL fileUrl) throws java.io.IOException
fileUrl
- java.io.IOException
public static byte[] readFile(java.net.URL fileUrl, boolean resolve) throws java.io.IOException
java.io.IOException
public static byte[] read(java.io.InputStream in) throws java.io.IOException
fileUrl
- java.io.IOException
public static byte[] read(java.io.Reader in) throws java.io.IOException
java.io.IOException
public static java.lang.String readAsString(java.io.Reader in) throws java.io.IOException
java.io.IOException
public static java.lang.String removeFileNameExtension(java.lang.String fileName)
public static java.lang.String getFileNameExtension(java.io.File file)
public static java.lang.String getFileNameExtension(java.io.File file, boolean includeDot)
public static java.lang.String getFileName(java.lang.String fileName, boolean includeExt)
public static java.lang.String getFileNameExtension(java.lang.String fileName, boolean includeDot)
public static java.lang.String readFileAsString(java.net.URL fileUrl) throws java.io.IOException
java.io.IOException
public static java.lang.String readFileAsString(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String[][] readDelimFile(java.net.URL fileUrl, java.lang.String delim) throws java.io.IOException
java.io.IOException
public static java.lang.String[][] readDelimFile(java.io.LineNumberReader reader, java.lang.String delim) throws java.io.IOException
java.io.IOException
public static java.lang.String readFileAsString(java.net.URL fileUrl, java.lang.String encoding) throws java.io.IOException
fileUrl
- java.io.IOException
public static java.lang.String readFileAsString(org.w3c.dom.ls.LSInput xsdInput) throws java.io.IOException
java.io.IOException
public static java.lang.String readFileAsString(org.w3c.dom.ls.LSInput xsdInput, int bufferLen) throws java.io.IOException
java.io.IOException
public static java.io.Reader getReader(org.w3c.dom.ls.LSInput xsdInput) throws java.io.IOException
java.io.IOException
public static java.lang.String readAsString(java.io.InputStream in, java.lang.String encoding) throws java.io.IOException
fileUrl
- java.io.IOException
public static java.io.OutputStream encode(java.io.InputStream inStream, java.io.OutputStream out, boolean base64, boolean zip, boolean doFlush) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream encode(java.io.InputStream inStream, java.io.OutputStream out, boolean base64, boolean zip, boolean doFlush, boolean buffered) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream decodeZipBase64(java.io.InputStream in, java.io.OutputStream out, boolean base64, boolean zip) throws java.io.IOException
java.io.IOException
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.InputStream inStream, java.io.OutputStream outstream) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.InputStream inStream, java.io.OutputStream outstream, boolean doFlush) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.InputStream inStream, java.io.OutputStream outstream, boolean doFlush, boolean useBuffedOut) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.InputStream inStream, java.io.OutputStream outstream, boolean doFlush, boolean useBuffedOut, java.util.zip.CRC32 crc) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(byte[] content, OutputWrapper out) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.InputStream inStream, OutputWrapper out) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.InputStream inStream, java.io.OutputStream outstream, java.lang.String srcEncoding) throws java.io.IOException
java.io.IOException
public static java.io.Writer write(java.io.Reader inReader, java.io.Writer outwriter) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream write(java.io.Reader inReader, java.io.OutputStream outwriter) throws java.io.IOException
java.io.IOException
public static void save(java.lang.StringBuffer buffer, java.io.File file, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static void save(java.lang.String buffer, java.io.File file, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static boolean save(java.lang.String buffer, java.io.File file)
public static java.io.File saveTempFile(java.lang.String buffer, java.lang.String prefix, java.lang.String suffix, java.io.File dir, boolean deleteOnExit) throws java.io.IOException
java.io.IOException
public static void write(java.lang.String buffer, java.io.Writer writer) throws java.io.IOException
java.io.IOException
public static boolean fileExist(java.io.File file)
file
- public static boolean fileExist(java.lang.String file)
file
- public void openFileEntry(java.net.URL filename) throws java.io.FileNotFoundException
filename
- java.io.FileNotFoundException
public void openFileEntry(java.net.URL filename, boolean createDirs) throws java.io.FileNotFoundException
filename
- java.io.FileNotFoundException
public void closeFileEntry() throws java.io.IOException
java.io.IOException
public FileHelper writeIntoFile(java.io.InputStream in) throws java.io.IOException
in
- java.io.IOException
public FileHelper writeIntoFile(java.io.Reader in) throws java.io.IOException
in
- java.io.IOException
public FileHelper writeIntoFile(char[] in) throws java.io.IOException
in
- java.io.IOException
public FileHelper writeIntoFile(byte[] in) throws java.io.IOException
in
- java.io.IOException
public FileHelper writeIntoFile(java.lang.String in) throws java.io.IOException
in
- java.io.IOException
public static void copy(java.io.File source, java.io.File destination) throws java.io.IOException
source
- java.net.URLdestination
- java.net.URLjava.io.IOException
public static void copy(java.net.URL source, java.io.File destination) throws java.io.IOException
source
- java.net.URLdestination
- java.net.URLjava.io.IOException
public static void copy(java.net.URL source, java.net.URL destination) throws java.io.IOException
source
- java.net.URLdestination
- java.net.URLjava.io.IOException
public static boolean deleteFile(java.lang.String file)
public static void deleteDir(java.io.File file, boolean deep)
public static void deleteDir(java.io.File[] file, boolean deep)
public static boolean mkdirs(java.io.File file, boolean includingLeaf)
true
if and only if the directory was created, along with all necessary parent directories; false
otherwisejava.lang.SecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String)
method does not permit the named directory and all necessary parent directories and to be createdpublic static java.io.File getDirectory(java.net.URL fileToOpen)
public static java.io.File getDirectory(java.io.File source)
public static java.lang.String tail(java.lang.String fileName, int lineCount)
public static void tail(java.lang.String fileName, int lineCount, java.io.PrintWriter writer, java.lang.String escapeAs)
public static void tail(java.lang.String fileName, int lineCount, int bufferSize, java.io.Writer pw, java.lang.String escapeAs) throws java.io.IOException
java.io.IOException
public static int[] parseLines(byte[] seekbuffer, int rows, java.lang.StringBuffer sb) throws java.io.IOException
java.io.IOException
public static java.lang.StringBuffer tailLines(int rows, java.lang.StringBuffer seekString) throws java.io.IOException
java.io.IOException
public static java.lang.String getDirectory(java.lang.String completeFile)
public static java.lang.String removeFileName(java.lang.String completeFile)
public static java.lang.String getDirectory(java.lang.String completeFile, boolean returnFileIfNone)
public long getFreeSpace()
public java.io.File[] getAllDrives()
public static java.lang.StringBuffer getFileSystemOverview()
public static JSONObject getFileSystemInfo()
public static java.lang.String getFileName(java.io.File completeFile)
public static java.lang.String replaceFileName(java.lang.String file, java.lang.String newName)
public static java.lang.String getFileName(java.lang.String fileName)
public static java.lang.String replaceFileExtension(java.lang.String fileName, java.lang.String extension)
public static long calculateChecksum(java.io.InputStream is)
InputStream
- which holds the file data to calculate its checksumpublic static long calculateChecksum(java.io.InputStream is, java.util.zip.Checksum algorithm)
InputStream
- which holds the file data to calculate its checksumChecksum
- which defines the algorithm to calculate the checksumpublic static boolean isChecksumValid(java.io.InputStream is, long checksum)
InputStream
- which holds the file data to calculate its checksumlong
- value which holds the expected checksum for the passed InputStreampublic static boolean isChecksumValid(java.io.InputStream is, long checksum, java.util.zip.Checksum algorithm)
InputStream
- which holds the file data to calculate its checksumlong
- value which holds the expected checksum for the passed InputStreamChecksum
- which defines the algorithm to calculate the checksumpublic static java.lang.String absolutePath(java.lang.String relative, java.lang.String absoluteTo, boolean urlMode)
public static java.lang.String relativePath(java.lang.String absolute, java.lang.String relativeTo, boolean urlMode) throws java.lang.Exception
java.lang.Exception
public static java.lang.String cleanFileName(java.lang.String fileName)
public static java.lang.String cleanFileName(java.lang.String fileName, char replacement)
public static final boolean isTextResourceExtension(java.lang.String extension)
public static boolean isFileTextResource(java.lang.String fileName)
public static java.lang.String concatPaths(java.lang.String templateLocation, java.lang.String templateName)