|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectto.etc.util.FileTool
public class FileTool
Contains some often-used file subroutines.
Method Summary | |
---|---|
static void |
closeAll(java.lang.Object... list)
This attempts to close all of the resources passed to it, without throwing exceptions. |
static void |
compareDirectories(IDirectoryDelta delta,
java.io.File a,
java.io.File b)
Compare the content of two directories, and callback methods on changes. |
static java.io.InputStream |
copyAndDumpStream(java.lang.StringBuilder tgt,
java.io.InputStream in,
java.lang.String encoding)
|
static void |
copyDir(java.io.File destd,
java.io.File srcd)
Copies an entire directory structure from src to dest. |
static void |
copyFile(java.io.File destf,
java.io.File srcf)
Copies a file. |
static void |
copyFile(java.io.OutputStream os,
java.io.InputStream is)
Copies the inputstream to the output stream. |
static void |
copyFile(java.io.Writer w,
java.io.Reader r)
Copy the input reader to the output reader. |
static void |
copyResource(java.io.Writer w,
java.lang.Class<?> cl,
java.lang.String rid)
|
static void |
deleteDir(java.io.File f)
Delete the directory and all it's contents. |
static boolean |
dirEmpty(java.io.File dirf)
Deletes all files in the directory. |
static boolean |
dirEmpty(java.io.File dirf,
java.util.Vector<java.lang.Object> elogb)
Deprecated. |
static java.lang.String |
fileNameSansExtension(java.lang.String fn)
Returns the file name excluding the suffix of the name. |
static int |
findFilenameExtension(java.lang.String fn)
Returns the start position of the filename extension in the string. |
static java.lang.String |
getFileExtension(java.lang.String fn)
Returns the extension of a file. |
static java.io.File |
getTmpDir()
Returns the java.io.tmpdir directory. |
static java.io.InputStream |
getZipContent(java.io.File src,
java.lang.String name)
|
static java.io.InputStream |
getZipContent(java.io.InputStream zipis,
java.lang.String name)
Returns a stream which is the uncompressed data stream for a zip file component. |
static byte[] |
hashBuffers(byte[][] data)
Create an MD5 hash for a buffer set. |
static java.lang.String |
hashBuffersHex(byte[][] data)
Create a HEX MD5 hash for a buffer set. |
static byte[] |
hashFile(java.io.File f)
Create an MD5 hash for a file's contents. |
static byte[] |
hashFile(java.io.InputStream is)
Hashes all data from an input stream and returns an MD5 hash. |
static java.lang.String |
hashFileHex(java.io.File f)
Hash a file and return it's hex MD5hash. |
static java.lang.String |
hashFileHex(java.io.InputStream is)
Hash an InputStream and return it's hex MD5hash. |
static byte[][] |
loadByteBuffers(java.io.File in)
Load an entire file in a byte buffer set. |
static byte[][] |
loadByteBuffers(java.io.InputStream is)
Loads a byte[][] from an input stream until exhaustion. |
static java.util.Properties |
loadProperties(java.io.File f)
Load a file as a Properties file. |
static java.util.Properties |
loadPropertiesFromZip(java.io.File f,
java.lang.String name)
Opens the jar file and tries to load the plugin.properties file from it. |
static java.util.Properties |
loadPropertiesFromZip(java.io.InputStream is,
java.lang.String name)
Opens the jar file and tries to load the plugin.properties file from it. |
static java.lang.Object |
loadSerialized(java.io.File f)
Load a single serialized object from a file. |
static java.lang.Object |
loadSerialized(java.io.InputStream is)
Load a single serialized object from a datastream. |
static java.lang.Object |
loadSerializedNullOnError(java.io.File f)
|
static java.lang.Object |
loadSerializedNullOnError(java.io.InputStream is)
Load a serialized object, and return null on any load exception. |
static org.w3c.dom.Document |
loadXmlFromZip(java.io.File f,
java.lang.String name,
boolean nsaware)
Opens the jar file and tries to load the plugin.properties file from it. |
static org.w3c.dom.Document |
loadXmlFromZip(java.io.InputStream is,
java.lang.String ident,
java.lang.String name,
boolean nsaware)
Opens the jar file and tries to load the plugin.properties file from it. |
static java.lang.ClassLoader |
makeJarLoader(java.io.File f)
Creates a classloader to load data from the given jar file. |
static java.lang.ClassLoader |
makeJarLoader(java.io.File f,
java.lang.ClassLoader parent)
|
static java.io.File |
makeTempFile(java.io.File root)
Create a temp file within the specified root directory. |
static java.io.File |
newDir(java.io.File root)
Create a temp directory within the root directory. |
static void |
prepareDir(java.io.File dir)
prepare a directory in this way: if it does not exist, create it. |
static void |
readFileAsString(java.lang.Appendable o,
java.io.File f)
|
static java.lang.String |
readFileAsString(java.io.File f)
Read a file's contents in a string using the default encoding of the platform. |
static java.lang.String |
readFileAsString(java.io.File f,
java.lang.String encoding)
Read a file into a string using the specified encoding. |
static void |
readHeadAndTail(java.lang.StringBuffer sb,
java.io.File f,
int headsize,
int tailsize)
mbp, moved here from old DaemonBase with some adaptions. |
static int |
readInt(java.io.InputStream is)
Reads a 4-byte bigendian int off the connection. |
static long |
readLong(java.io.InputStream is)
|
static void |
readStreamAsString(java.lang.Appendable o,
java.io.InputStream f,
java.lang.String enc)
|
static void |
readStreamAsString(java.lang.Appendable o,
java.io.Reader r)
|
static java.lang.String |
readStreamAsString(java.io.InputStream is,
java.lang.String enc)
|
static java.lang.String |
readStreamAsString(java.io.Reader r)
|
static java.lang.String |
readString(java.io.InputStream is)
|
static void |
save(java.io.File of,
byte[][] data)
Save the data in byte buffers to a file. |
static void |
save(java.io.OutputStream os,
byte[][] data)
Save the data in byte buffers to an output stream. |
static void |
saveProperties(java.io.File f,
java.util.Properties p)
Save a properties file. |
static void |
saveSerialized(java.io.File f,
java.io.Serializable obj)
|
static void |
saveSerialized(java.io.OutputStream os,
java.io.Serializable obj)
Save a serializable object to a datastream. |
static void |
unzip(java.io.File dest,
java.io.File zipfile)
Unzip the contents of the zipfile to the directory. |
static void |
unzip(java.io.File dest,
java.io.InputStream is)
|
static java.io.InputStream |
wrapInputStream(java.io.InputStream rawStream,
ILogSink s,
int maxinmemory)
|
static void |
writeFileFromString(java.io.File f,
java.lang.String v,
java.lang.String enc)
|
static void |
writeFileFromString(java.io.OutputStream os,
java.lang.String v,
java.lang.String enc)
|
static void |
writeInt(java.io.OutputStream os,
int val)
Sends an int fragment |
static void |
writeLong(java.io.OutputStream os,
long val)
Sends a long |
static void |
writeString(java.io.OutputStream os,
java.lang.String s)
|
static void |
zip(java.io.File zipfile,
java.io.File dir)
Zip the contents of dir or file to the zipfile. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.io.File getTmpDir()
public static java.io.File newDir(java.io.File root)
root
-
public static java.io.File makeTempFile(java.io.File root)
root
-
public static boolean dirEmpty(java.io.File dirf)
public static void deleteDir(java.io.File f)
f
- public static void prepareDir(java.io.File dir) throws java.lang.Exception
dir
- the directory that must be made existent
java.lang.Exception
- when creation fails or when removing old contents
fails.@Deprecated public static boolean dirEmpty(java.io.File dirf, java.util.Vector<java.lang.Object> elogb)
public static java.lang.String getFileExtension(java.lang.String fn)
public static int findFilenameExtension(java.lang.String fn)
public static java.lang.String fileNameSansExtension(java.lang.String fn)
public static void copyFile(java.io.File destf, java.io.File srcf) throws java.io.IOException
destf
- the destinationsrcf
- the source
java.io.IOException
- the errorpublic static void copyFile(java.io.OutputStream os, java.io.InputStream is) throws java.io.IOException
destf
- the destinationsrcf
- the source
java.io.IOException
- the errorpublic static void copyFile(java.io.Writer w, java.io.Reader r) throws java.io.IOException
w
- r
-
java.io.IOException
public static void copyDir(java.io.File destd, java.io.File srcd) throws java.io.IOException
destd
- srcd
-
java.io.IOException
public static java.lang.String readFileAsString(java.io.File f) throws java.lang.Exception
f
-
java.lang.Exception
public static void readFileAsString(java.lang.Appendable o, java.io.File f) throws java.lang.Exception
o
- f
-
java.lang.Exception
public static java.lang.String readFileAsString(java.io.File f, java.lang.String encoding) throws java.lang.Exception
f
- encoding
-
java.lang.Exception
public static void readHeadAndTail(java.lang.StringBuffer sb, java.io.File f, int headsize, int tailsize) throws java.lang.Exception
java.lang.Exception
public static java.lang.String readStreamAsString(java.io.InputStream is, java.lang.String enc) throws java.lang.Exception
java.lang.Exception
public static void readStreamAsString(java.lang.Appendable o, java.io.InputStream f, java.lang.String enc) throws java.lang.Exception
java.lang.Exception
public static void readStreamAsString(java.lang.Appendable o, java.io.Reader r) throws java.lang.Exception
java.lang.Exception
public static java.lang.String readStreamAsString(java.io.Reader r) throws java.lang.Exception
java.lang.Exception
public static void writeFileFromString(java.io.File f, java.lang.String v, java.lang.String enc) throws java.lang.Exception
java.lang.Exception
public static void writeFileFromString(java.io.OutputStream os, java.lang.String v, java.lang.String enc) throws java.lang.Exception
java.lang.Exception
public static byte[] hashFile(java.io.File f) throws java.io.IOException
java.io.IOException
public static byte[] hashBuffers(byte[][] data)
data
-
public static java.lang.String hashBuffersHex(byte[][] data)
data
-
public static byte[] hashFile(java.io.InputStream is) throws java.io.IOException
is
- The stream to read and hash.
java.io.IOException
public static java.lang.String hashFileHex(java.io.File f) throws java.io.IOException
f
-
java.io.IOException
public static java.lang.String hashFileHex(java.io.InputStream is) throws java.io.IOException
is
-
java.io.IOException
public static java.util.Properties loadProperties(java.io.File f) throws java.lang.Exception
f
-
java.lang.Exception
public static void saveProperties(java.io.File f, java.util.Properties p) throws java.lang.Exception
f
- p
-
java.lang.Exception
public static java.util.Properties loadPropertiesFromZip(java.io.File f, java.lang.String name) throws java.lang.Exception
f
-
java.lang.Exception
public static java.util.Properties loadPropertiesFromZip(java.io.InputStream is, java.lang.String name) throws java.lang.Exception
f
-
java.lang.Exception
public static org.w3c.dom.Document loadXmlFromZip(java.io.File f, java.lang.String name, boolean nsaware) throws java.lang.Exception
f
-
java.lang.Exception
public static org.w3c.dom.Document loadXmlFromZip(java.io.InputStream is, java.lang.String ident, java.lang.String name, boolean nsaware) throws java.lang.Exception
f
-
java.lang.Exception
public static java.lang.ClassLoader makeJarLoader(java.io.File f) throws java.net.MalformedURLException
f
-
java.net.MalformedURLException
java.lang.Exception
public static java.lang.ClassLoader makeJarLoader(java.io.File f, java.lang.ClassLoader parent) throws java.net.MalformedURLException
java.net.MalformedURLException
public static void copyResource(java.io.Writer w, java.lang.Class<?> cl, java.lang.String rid) throws java.lang.Exception
java.lang.Exception
public static void zip(java.io.File zipfile, java.io.File dir) throws java.lang.Exception
java.lang.Exception
public static void unzip(java.io.File dest, java.io.InputStream is) throws java.lang.Exception
java.lang.Exception
public static void unzip(java.io.File dest, java.io.File zipfile) throws java.lang.Exception
java.lang.Exception
public static java.io.InputStream getZipContent(java.io.File src, java.lang.String name) throws java.io.IOException
java.io.IOException
public static java.io.InputStream getZipContent(java.io.InputStream zipis, java.lang.String name) throws java.io.IOException
zipis
-
java.io.IOException
public static byte[][] loadByteBuffers(java.io.InputStream is) throws java.io.IOException
is
-
java.io.IOException
public static byte[][] loadByteBuffers(java.io.File in) throws java.io.IOException
in
-
java.io.IOException
public static void save(java.io.File of, byte[][] data) throws java.io.IOException
of
- data
-
java.io.IOException
public static void save(java.io.OutputStream os, byte[][] data) throws java.io.IOException
os
- data
-
java.io.IOException
public static void writeInt(java.io.OutputStream os, int val) throws java.io.IOException
val
-
java.lang.Exception
java.io.IOException
public static void writeLong(java.io.OutputStream os, long val) throws java.io.IOException
val
-
java.lang.Exception
java.io.IOException
public static void writeString(java.io.OutputStream os, java.lang.String s) throws java.io.IOException
java.io.IOException
public static int readInt(java.io.InputStream is) throws java.io.IOException
java.lang.Exception
java.io.IOException
public static long readLong(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static java.lang.String readString(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static java.io.InputStream wrapInputStream(java.io.InputStream rawStream, ILogSink s, int maxinmemory) throws java.lang.Exception
java.lang.Exception
public static java.io.InputStream copyAndDumpStream(java.lang.StringBuilder tgt, java.io.InputStream in, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static void saveSerialized(@WillClose java.io.OutputStream os, java.io.Serializable obj) throws java.io.IOException
os
- obj
-
java.io.IOException
public static void saveSerialized(java.io.File f, java.io.Serializable obj) throws java.io.IOException
java.io.IOException
@Nullable public static java.lang.Object loadSerialized(@WillNotClose java.io.InputStream is) throws java.io.IOException, java.lang.ClassNotFoundException
is
-
java.io.IOException
java.lang.ClassNotFoundException
@Nullable public static java.lang.Object loadSerialized(java.io.File f) throws java.io.IOException, java.lang.ClassNotFoundException
f
-
java.io.IOException
java.lang.ClassNotFoundException
@Nullable public static java.lang.Object loadSerializedNullOnError(@WillNotClose java.io.InputStream is)
is
-
@Nullable public static java.lang.Object loadSerializedNullOnError(java.io.File f) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public static void closeAll(@WillClose java.lang.Object... list)
list
- public static void compareDirectories(IDirectoryDelta delta, java.io.File a, java.io.File b) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |