Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.analogweb.acf;
  
  import static org.analogweb.acf.CommonsFileUploadModulesConfig.PLUGIN_MESSAGE_RESOURCE;
  
  import java.io.File;
 
 
 
 public class TemporaryUploadFolder implements Serializable {
 
     private static final long serialVersionUID = 1950934123601946837L;
 
     private static final Log log = Logs.getLog(TemporaryUploadFolder.class);
 
     protected static final String TMP_DIR = TemporaryUploadFolder.class.getPackage().getName()
             + "_" + "TMP_DIR";
 
     private File baseDir;
 
     public static TemporaryUploadFolder current(RequestContext context) {
         HttpServletRequest req;
         if (context instanceof ServletRequestContext) {
             req = ((ServletRequestContextcontext).getServletRequest();
         } else {
             return null;
         }
         Object tmpDir = req.getAttribute();
         if (!(tmpDir instanceof TemporaryUploadFolder)) {
             ApplicationProperties props = ApplicationPropertiesHolder.current();
             TemporaryUploadFolder newFolder = new TemporaryUploadFolder(new File(
                     createCurrentDirName(propscontext)));
             req.setAttribute(newFolder);
             tmpDir = req.getAttribute();
         }
         return (TemporaryUploadFoldertmpDir;
     }
 
     private static synchronized String createCurrentDirName(ApplicationProperties props,
             RequestContext context) {
         return props.getTempDir().getPath() + "/" + TemporaryUploadFolder.class.getName() + "_"
                 + System.currentTimeMillis() + "_" + context.hashCode();
     }
 
     protected TemporaryUploadFolder(File baseDir) {
         this. = baseDir;
     }
 
     protected File getBaseDir() {
         return this.;
     }
 
     public File require(Multipart multipart) {
         File base = getBaseDir();
         if (!base.exists()) {
             base.mkdirs();
             .log("DACF000005"base.toString());
         }
         File file = new File(base.getPath() + "/" + multipart.getName());
         if (!file.exists()) {
             FileOutputStream out = null;
             InputStream in = multipart.getInputStream();
             try {
                 out = new FileOutputStream(file);
                 IOUtils.copy(inout);
                 .log("DACF000006"file.getPath());
             } catch (IOException e) {
                 .log("WACF000002"multipart.getName());
                 .log("WACF000003"ebase);
                 return null;
             } finally {
                 IOUtils.closeQuietly(in);
                 IOUtils.closeQuietly(out);
             }
         } else {
             .log("DACF000007"file.getPath());
         }
         return file;
     }
 
     public static File require(RequestContext contextMultipart multipart) {
         return current(context).require(multipart);
     }
 
     public void dispose() {
         File baseDir = getBaseDir();
         if (baseDir != null && baseDir.exists()) {
            deleteRecurciverely(baseDir);
            baseDir.delete();
            .log("DACF000008"baseDir.getPath());
        }
    }
    private void deleteRecurciverely(File dir) {
        File[] listFiles = dir.listFiles();
        if (listFiles != null) {
            for (File f : listFiles) {
                if (f.isDirectory()) {
                    deleteRecurciverely(f);
                } else {
                    f.delete();
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X