// Path: src/main/java/com/raibledesigns/Constants.java
// public final class Constants {
// 
//     private Constants() {
//         // hide me
//     }
//     //~ Static fields/initializers =============================================
// 
//     /**
//      * Assets Version constant
//      */
//     public static final String ASSETS_VERSION = "assetsVersion";
//     /**
//      * The name of the ResourceBundle used in this application
//      */
//     public static final String BUNDLE_KEY = "ApplicationResources";
// 
//     /**
//      * File separator from System properties
//      */
//     public static final String FILE_SEP = System.getProperty("file.separator");
// 
//     /**
//      * User home from System properties
//      */
//     public static final String USER_HOME = System.getProperty("user.home") + FILE_SEP;
// 
//     /**
//      * The name of the configuration hashmap stored in application scope.
//      */
//     public static final String CONFIG = "appConfig";
// 
//     /**
//      * Session scope attribute that holds the locale set by the user. By setting this key
//      * to the same one that Struts uses, we get synchronization in Struts w/o having
//      * to do extra work or have two session-level variables.
//      */
//     public static final String PREFERRED_LOCALE_KEY = "org.apache.struts2.action.LOCALE";
// 
//     /**
//      * The request scope attribute under which an editable user form is stored
//      */
//     public static final String USER_KEY = "userForm";
// 
//     /**
//      * The request scope attribute that holds the user list
//      */
//     public static final String USER_LIST = "userList";
// 
//     /**
//      * The request scope attribute for indicating a newly-registered user
//      */
//     public static final String REGISTERED = "registered";
// 
//     /**
//      * The name of the Administrator role, as specified in web.xml
//      */
//     public static final String ADMIN_ROLE = "ROLE_ADMIN";
// 
//     /**
//      * The name of the User role, as specified in web.xml
//      */
//     public static final String USER_ROLE = "ROLE_USER";
// 
//     /**
//      * The name of the user's role list, a request-scoped attribute
//      * when adding/editing a user.
//      */
//     public static final String USER_ROLES = "userRoles";
// 
//     /**
//      * The name of the available roles list, a request-scoped attribute
//      * when adding/editing a user.
//      */
//     public static final String AVAILABLE_ROLES = "availableRoles";
// 
//     /**
//      * The name of the CSS Theme setting.
//      * @deprecated No longer used to set themes.
//      */
//     public static final String CSS_THEME = "csstheme";
// }


import com.raibledesigns.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

        // Create the directory if it doesn't exist
        File dirPath = new File(uploadDir);

        if (!dirPath.exists()) {
            dirPath.mkdirs();
        }

        //retrieve the file data
        InputStream stream = file.getInputStream();

        //write the file to the file specified
        OutputStream bos = new FileOutputStream(uploadDir + file.getOriginalFilename());
        int bytesRead;
        byte[] buffer = new byte[8192];

        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);
        }

        bos.close();

        //close the stream
        stream.close();

        // place the data into the request for retrieval on next page
        request.setAttribute("friendlyName", fileUpload.getName());
        request.setAttribute("fileName", file.getOriginalFilename());
        request.setAttribute("contentType", file.getContentType());
        request.setAttribute("size", file.getSize() + " bytes");
// Path: src/main/java/com/raibledesigns/Constants.java
// public final class Constants {
// 
//     private Constants() {
//         // hide me
//     }
//     //~ Static fields/initializers =============================================
// 
//     /**
//      * Assets Version constant
//      */
//     public static final String ASSETS_VERSION = "assetsVersion";
//     /**
//      * The name of the ResourceBundle used in this application
//      */
//     public static final String BUNDLE_KEY = "ApplicationResources";
// 
//     /**
//      * File separator from System properties
//      */
//     public static final String FILE_SEP = System.getProperty("file.separator");
// 
//     /**
//      * User home from System properties
//      */
//     public static final String USER_HOME = System.getProperty("user.home") + FILE_SEP;
// 
//     /**
//      * The name of the configuration hashmap stored in application scope.
//      */
//     public static final String CONFIG = "appConfig";
// 
//     /**
//      * Session scope attribute that holds the locale set by the user. By setting this key
//      * to the same one that Struts uses, we get synchronization in Struts w/o having
//      * to do extra work or have two session-level variables.
//      */
//     public static final String PREFERRED_LOCALE_KEY = "org.apache.struts2.action.LOCALE";
// 
//     /**
//      * The request scope attribute under which an editable user form is stored
//      */
//     public static final String USER_KEY = "userForm";
// 
//     /**
//      * The request scope attribute that holds the user list
//      */
//     public static final String USER_LIST = "userList";
// 
//     /**
//      * The request scope attribute for indicating a newly-registered user
//      */
//     public static final String REGISTERED = "registered";
// 
//     /**
//      * The name of the Administrator role, as specified in web.xml
//      */
//     public static final String ADMIN_ROLE = "ROLE_ADMIN";
// 
//     /**
//      * The name of the User role, as specified in web.xml
//      */
//     public static final String USER_ROLE = "ROLE_USER";
// 
//     /**
//      * The name of the user's role list, a request-scoped attribute
//      * when adding/editing a user.
//      */
//     public static final String USER_ROLES = "userRoles";
// 
//     /**
//      * The name of the available roles list, a request-scoped attribute
//      * when adding/editing a user.
//      */
//     public static final String AVAILABLE_ROLES = "availableRoles";
// 
//     /**
//      * The name of the CSS Theme setting.
//      * @deprecated No longer used to set themes.
//      */
//     public static final String CSS_THEME = "csstheme";
// }


// Path: src/main/java/com/raibledesigns/webapp/controller/FileUploadController.java
import com.raibledesigns.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


        // Create the directory if it doesn't exist
        File dirPath = new File(uploadDir);

        if (!dirPath.exists()) {
            dirPath.mkdirs();
        }

        //retrieve the file data
        InputStream stream = file.getInputStream();

        //write the file to the file specified
        OutputStream bos = new FileOutputStream(uploadDir + file.getOriginalFilename());
        int bytesRead;
        byte[] buffer = new byte[8192];

        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);
        }

        bos.close();

        //close the stream
        stream.close();

        // place the data into the request for retrieval on next page
        request.setAttribute("friendlyName", fileUpload.getName());
        request.setAttribute("fileName", file.getOriginalFilename());
        request.setAttribute("contentType", file.getContentType());
        request.setAttribute("size", file.getSize() + " bytes");
        request.setAttribute("location", dirPath.getAbsolutePath() + Constants.FILE_SEP + file.getOriginalFilename());