Index: lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/Bundler.java =================================================================== diff -u -rb9b98ebbb13be77cbaead9bf33a4e855e43871b1 -rc312315c2012a964e9414b6682ae35af94b4d576 --- lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/Bundler.java (.../Bundler.java) (revision b9b98ebbb13be77cbaead9bf33a4e855e43871b1) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/export/web/action/Bundler.java (.../Bundler.java) (revision c312315c2012a964e9414b6682ae35af94b4d576) @@ -23,82 +23,49 @@ /* $Id$ */ package org.lamsfoundation.lams.learning.export.web.action; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.List; +import org.apache.commons.io.FileUtils; import org.apache.log4j.Logger; /** * Superclass for any files "bundled" as part of the export portfolio. For code reuse. - * + * */ public class Bundler { - protected static Logger log = Logger.getLogger(Bundler.class); + protected static Logger log = Logger.getLogger(Bundler.class); - /** + /** * */ - public Bundler() { - super(); - } + public Bundler() { + super(); + } - protected void createDirectories(List directoriesRequired) { - - for ( String directoryPath: directoriesRequired) { - File dir = new File(directoryPath); - if ( ! dir.exists() && ! dir.mkdirs() ) { - log.error("Unable to create directory for export portfolio: "+directoryPath); - } - } + protected void createDirectories(List directoriesRequired) { + + for (String directoryPath : directoriesRequired) { + File dir = new File(directoryPath); + if (!dir.exists() && !dir.mkdirs()) { + log.error("Unable to create directory for export portfolio: " + directoryPath); + } } + } - protected void copyFile(String filePath, File file) throws IOException { - - FileInputStream is = new FileInputStream(file); - OutputStream os = null; - try { - - int bufLen = 1024; // 1 Kbyte - byte[] buf = new byte[1024]; // output buffer - os = new FileOutputStream(filePath); - - BufferedInputStream in = new BufferedInputStream(is); - int len = 0; - while((len = in.read(buf,0,bufLen)) != -1){ - os.write(buf,0,len); - } - - } catch ( IOException e ) { - String message = "Unable to write out file needed for export portfolio. File was "+filePath; - log.error(message,e); - throw e; - - } finally { - - try { - if ( is != null ) - is.close(); - } catch (IOException e1) { - String message = "Unable to close input export portfolio file due to IOException"; - log.warn(message,e1); - } - - try { - if ( os != null ) - os.close(); - } catch (IOException e2) { - String message = "Unable to close output export portfolio file due to IOException"; - log.warn(message,e2); - } - } - - + protected void copyFile(String destDirStr, File srcFile) throws IOException { + + log.debug("Copying file " + srcFile + " to " + destDirStr); + File destDir = new File(destDirStr); + + try { + FileUtils.copyFileToDirectory(srcFile, destDir); + } catch (IOException e) { + String message = "Unable to write out file needed for export portfolio. File was " + srcFile; + log.error(message, e); } + } } \ No newline at end of file