X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Futil%2FFileFunctions.java;h=7ade9aa2546eb14dd77d74fc2dad57a55809cafd;hb=6b6b6215ebe066b81f1fa6b0c71a532ca7b4fc3f;hp=a49c1498b4e6f7c4f1cb7eabb4c36358dfc32b12;hpb=afcbbd1dee154b4d24a4a77dacc7e07503dd182c;p=mir.git diff --git a/source/mir/util/FileFunctions.java b/source/mir/util/FileFunctions.java index a49c1498..7ade9aa2 100755 --- a/source/mir/util/FileFunctions.java +++ b/source/mir/util/FileFunctions.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2005 The Mir-coders group * * This file is part of Mir. * @@ -29,205 +29,9 @@ */ package mir.util; -import gnu.regexp.RE; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class FileFunctions { - protected static final int FILE_COPY_BUFFER_SIZE = 65536; - - private FileFunctions() { - } - - public static void copyFile(File aSourceFile, File aDestinationFile) throws IOException { - BufferedInputStream inputStream; - BufferedOutputStream outputStream; - int nrBytesRead; - byte[] buffer = new byte[FILE_COPY_BUFFER_SIZE]; - - inputStream = new BufferedInputStream( - new FileInputStream(aSourceFile)); - try { - File directory = new File(aDestinationFile.getParent()); - if (directory!=null && !directory.exists()){ - directory.mkdirs(); - } - outputStream = new BufferedOutputStream( - new FileOutputStream(aDestinationFile),8192); - try { - do { - nrBytesRead = inputStream.read(buffer); - if (nrBytesRead>0) - outputStream.write(buffer, 0, nrBytesRead); - } - while (nrBytesRead>=0); - } - finally { - outputStream.close(); - } - } - finally { - inputStream.close(); - } - } - - public static void copyDirectory(File aSourceDirectory, File aDestinationDirectory) throws IOException { - int i; - File sourceFile; - File destinationFile; - File[] files = aSourceDirectory.listFiles(); - - if (!aDestinationDirectory.exists()) - aDestinationDirectory.mkdirs(); - - for (i=0; i0) { - outputStream.write(buffer, 0, count); - count=inputStream.read(buffer); - } - } - finally { - outputStream.close(); - inputStream.close(); - } - aSource.delete(); - } - } - - /** - * Reads the content of a file into a string - */ - public static String readFileIntoString(String fileName) - throws IOException - { - return new String(readFileIntoByteArray(fileName)); - } - /** - * Reads the content of a file into an array of bytes - */ - public static byte[] readFileIntoByteArray(String fileName) - throws IOException - { - FileInputStream input = new FileInputStream(fileName); - int size= input.available(); - byte result[]= new byte[size]; - input.read(result); - return result; - } - - public static class RegExpFileFilter implements FilenameFilter { - private RE expression; - - public RegExpFileFilter(String anExpression) { - try { - expression = new RE(anExpression); - } - catch (Throwable t) { - throw new RuntimeException(t.getMessage()); - } - } - - public boolean accept(File aDir, String aName) { - return expression.isMatch(aName) && !new File(aDir, aName).isDirectory(); - } - } - - public static class DirectoryFilter implements FilenameFilter { - public DirectoryFilter() { - } - - public boolean accept(File aDir, String aName) { - return new File(aDir, aName).isDirectory(); - } - } - - public static List getDirectoryContentsAsList(File aDirectory, FilenameFilter aFilter) { - Object[] contents = aDirectory.list(aFilter); - if (contents==null) - return Collections.EMPTY_LIST; - return Arrays.asList(contents); - } - - public static String getExtension(String aPath) { - int position = aPath.lastIndexOf('.'); - if (position>=0) { - return aPath.substring(position+1); - } - return ""; - } - - public static boolean isAbsolutePath(String aPath) { - return new File(aPath).isAbsolute(); - } - - public static File getAbsoluteOrRelativeFile(File aParentIfRelative, String aPath) { - if (isAbsolutePath(aPath)) { - return new File(aPath); - } - return new File(aParentIfRelative, aPath); - } -} +/** + * @deprecated Use mir.util.FileRoutines instead + */ +public class FileFunctions extends FileRoutines { +} \ No newline at end of file