Пример #1
0
 // update the modified time of the given file, or create it
 public static void touch(java.io.File file) throws ServiceException {
   if (file.exists()) {
     file.setLastModified((new java.util.Date()).getTime());
   } else {
     create(file);
   }
 }
Пример #2
0
 // creates a new, empty file; if file is null, a temporary file is created
 public static java.io.File create(java.io.File file) throws ServiceException {
   try {
     if (file == null) {
       file = java.io.File.createTempFile("tundra", null);
     } else {
       java.io.File parent = file.getParentFile();
       if (parent != null) parent.mkdirs(); // automatically create directories if required
       if (!file.createNewFile())
         tundra.exception.raise(
             "Unable to create file because it already exists: "
                 + tundra.support.file.normalize(file));
     }
   } catch (java.io.IOException ex) {
     tundra.exception.raise(ex);
   }
   return file;
 }
Пример #3
0
 // renames a file
 public static void rename(java.io.File source, java.io.File target) throws ServiceException {
   if (source != null && target != null) {
     if (!exists(source) || exists(target) || !source.renameTo(target)) {
       tundra.exception.raise(
           "Unable to rename file "
               + tundra.support.file.normalize(source)
               + " to "
               + tundra.support.file.normalize(target));
     }
   }
 }
Пример #4
0
 // deletes a file
 public static void remove(java.io.File file) throws ServiceException {
   if (file != null && exists(file) && !file.delete()) {
     tundra.exception.raise("Unable to remove file: " + tundra.support.file.normalize(file));
   }
 }
Пример #5
0
 // returns the length of the given file in bytes
 public static long length(java.io.File file) throws ServiceException {
   return file == null ? 0 : file.length();
 }
Пример #6
0
 // returns whether the given file can be executed by this process
 public static boolean executable(java.io.File file) throws ServiceException {
   return file == null ? false : file.canExecute();
 }
Пример #7
0
 // returns whether the given file can be read by this process
 public static boolean readable(java.io.File file) throws ServiceException {
   return file == null ? false : file.canRead();
 }
Пример #8
0
 // returns whether the given file exists
 public static boolean exists(java.io.File file) throws ServiceException {
   return file == null ? false : file.exists() && file.isFile();
 }
Пример #9
0
 // --- <<IS-START-SHARED>> ---
 // returns the mime type for the given file
 public static String type(java.io.File file) throws ServiceException {
   String type = null;
   if (file != null) type = com.wm.app.b2b.server.MimeTypes.getTypeFromName(file.getName());
   if (type == null) type = "application/octet-stream";
   return type;
 }