| java.lang.Object snow.utils.storage.FileUtils
FileUtils | final public class FileUtils (Code) | | All file access should be done from here
|
Inner Class :final static class JavaFileNameFilter implements FileFilter | |
Inner Class :final static class ClassFileNameFilter implements FileFilter | |
Inner Class :final static class FolderFileNameFilter implements FileFilter | |
Method Summary | |
public static void | addToZip(ZipOutputStream zos, File f, String relName) | public static void | addToZip(org.apache.tools.zip.ZipOutputStream zos, File f, String relName) better char encoding (correct charset).
can also handle attributes (readonly) ... | public static void | closeIgnoringExceptions(Closeable c) works fine. | public static void | closeIgnoringExceptions(JarFile c) | public static void | closeIgnoringExceptions(ZipFile c) | public static void | copy(File source, File dest) | public static void | extractZipFile(File file, File destFold, ProgressModalDialog pmd) Double buffered extracter, pmd used for cancel. | public static String | filesToList(List<File> files) a "; "separated list or the absolute file paths.Be careful, some apps don't want the space. | public static String | formatSize(long s) | public static void | getAllClassFilesRecurse(File root, List<File> allFiles, boolean ignoringDirsStartingWithDot) | public static void | getAllFilesRecurse(File root, List<File> allFiles, boolean withDirectories, boolean ignoringDirsStartingWithDot) if withDirectories, append also the directories
Remark: the root is not added. | public static void | getAllFilesRecurseLim(File root, List<File> allFiles, boolean withDirectories, boolean ignoringDirsStartingWithDot, int maxDepth, ProgressModalDialog pmd) Version with limited recursion depth. | public static void | getAllJavaFilesRecurse(File root, List<File> allFiles, boolean withFolders, boolean ignoringDirsStartingWithDot) | public static List<File> | getAllResourceFilesRecurse(File root, List<String> ignoredEndingsLow) | public static File | getCanonicalFileWithCase(File f) just calls the File.getCanonicalFile(). | public static String | getCanonicalName(File f) With / as separator and a / at the end for directories
CAUTION: case is NOT canonicalized. | public static String | getExtension(String fileName) Also called suffix, the text after the last dot. | public static byte[] | getFileByteContent(File file) | public static String | getFileStringContent(File file) | public static List<File> | getFilesFromList(String list, boolean onlyExisting) | public static List<File> | getFilesOnly_notRecurse(File root) | public static void | getFoldersRecurse(File root, List<File> allFiles, boolean ignoringDirsStartingWithDot) With the root itself. | public static int | getNumberOfFiles(File root) Recurse into root, but don't counts directories. | public static long | getSizeIncludingSubFiles(File root) | public static String | getStringContent(InputStream is) | public static void | gunzip(File in, File out) | public static StorageVector | loadVector(InputStream is) Loads the vector from the inputstream. | public static StorageVector | loadVectorFromFile(File file) | public static StorageVector | loadVectorFromFile(File file, boolean faultTolerant) | public static StorageVector | loadVectorWithoutClose(InputStream is) Caution: the stream is not closed, this allow you to read several vectory from the stream
a header and a body, for example. | public static StorageVector | loadZippedVectorFromFile3(File file) Works... | public static File | removeRelativePaths(File f) | public static void | saveBytesToFile(byte[] cont, File file) | public static void | saveToFile(String cont, File file) | public static void | saveVectorToFile(File file, List<Object> v) creates the folders if needed... | public static void | saveZippedVectorToFile(File file, List<Object> v) | static void | skipFully(InputStream in, long nBytes) From Gatfer more Puzzlers... | public static void | writeToFile(InputStream is, File file) |
classFileNameFilter | final public static ClassFileNameFilter classFileNameFilter(Code) | | |
folderFileNameFilter | final public static FolderFileNameFilter folderFileNameFilter(Code) | | Folders only.
|
javaFileNameFilter | final static JavaFileNameFilter javaFileNameFilter(Code) | | |
closeIgnoringExceptions | public static void closeIgnoringExceptions(Closeable c)(Code) | | works fine. (but passes through an external file).
public static void test() throws Exception
{
File gzfile = new File("c:/temp/abc.txt.gz");
GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(gzfile));
byte[] bh = "Hello world !".getBytes();
System.out.println(""+Arrays.toString(bh));
gzos.write(bh);
gzos.finish();
gzos.flush();
gzos.close();
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(gzfile));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[256];
int read = 0;
while((read=gzis.read(buf))!=-1)
{
baos.write(buf,0,read);
}
System.out.println("bh2"+ Arrays.toString(baos.toByteArray()));
}
|
closeIgnoringExceptions | public static void closeIgnoringExceptions(JarFile c)(Code) | | |
closeIgnoringExceptions | public static void closeIgnoringExceptions(ZipFile c)(Code) | | |
filesToList | public static String filesToList(List<File> files)(Code) | | a "; "separated list or the absolute file paths.Be careful, some apps don't want the space. (just remove it) |
getAllClassFilesRecurse | public static void getAllClassFilesRecurse(File root, List<File> allFiles, boolean ignoringDirsStartingWithDot)(Code) | | |
getAllFilesRecurse | public static void getAllFilesRecurse(File root, List<File> allFiles, boolean withDirectories, boolean ignoringDirsStartingWithDot)(Code) | | if withDirectories, append also the directories
Remark: the root is not added.
settings folders, starting with "." are also ignored.
in case of folders inclusion, folder are present first to their content, this
may be useful when creating a tree...
SLOW: getAllJavaFilesRecurse is quicker.
|
getAllFilesRecurseLim | public static void getAllFilesRecurseLim(File root, List<File> allFiles, boolean withDirectories, boolean ignoringDirsStartingWithDot, int maxDepth, ProgressModalDialog pmd)(Code) | | Version with limited recursion depth.
maxDepth=0 => only files.
|
getAllJavaFilesRecurse | public static void getAllJavaFilesRecurse(File root, List<File> allFiles, boolean withFolders, boolean ignoringDirsStartingWithDot)(Code) | | |
getAllResourceFilesRecurse | public static List<File> getAllResourceFilesRecurse(File root, List<String> ignoredEndingsLow)(Code) | | All files but not the files ending with the given names
|
getCanonicalFileWithCase | public static File getCanonicalFileWithCase(File f)(Code) | | just calls the File.getCanonicalFile().
The cases are corrected and ".." are "resolved".
Should be called on each file object that is compared !
Be very careful, E: and e: are denoting the same path on windows, but they string are not "equals"
|
getCanonicalName | public static String getCanonicalName(File f)(Code) | | With / as separator and a / at the end for directories
CAUTION: case is NOT canonicalized. call first getCanonicalFileWithCase() on the file !
|
getExtension | public static String getExtension(String fileName)(Code) | | Also called suffix, the text after the last dot.
If none, returns the whole name.
Makes sense on linux, where files named path/to/prop are often seen.
So we had a "prop" file.
|
getFoldersRecurse | public static void getFoldersRecurse(File root, List<File> allFiles, boolean ignoringDirsStartingWithDot)(Code) | | With the root itself.
|
getNumberOfFiles | public static int getNumberOfFiles(File root)(Code) | | Recurse into root, but don't counts directories.
|
getSizeIncludingSubFiles | public static long getSizeIncludingSubFiles(File root)(Code) | | |
loadVectorWithoutClose | public static StorageVector loadVectorWithoutClose(InputStream is) throws Exception(Code) | | Caution: the stream is not closed, this allow you to read several vectory from the stream
a header and a body, for example.
|
loadZippedVectorFromFile3 | public static StorageVector loadZippedVectorFromFile3(File file) throws Exception(Code) | | Works... but not perfect, not "on the fly". Needs a fully unpack.
|
removeRelativePaths | public static File removeRelativePaths(File f)(Code) | | remove the ".." in the path (resolve them!)
|
saveBytesToFile | public static void saveBytesToFile(byte[] cont, File file) throws Exception(Code) | | |
|
|