From eb5911ac7d674b131edfb498425dc92eb1d82674 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Wed, 14 Sep 2011 17:02:06 +0000 Subject: [PATCH] --- src/zutil/db/DBConnection.java | 3 ++- src/zutil/db/DBConnectionPool.java | 6 +++--- src/zutil/io/file/FileUtil.java | 17 ++++++++++++++++- src/zutil/jee/upload/FileUploadListener.java | 3 ++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/zutil/db/DBConnection.java b/src/zutil/db/DBConnection.java index 0abd721..c49b43a 100644 --- a/src/zutil/db/DBConnection.java +++ b/src/zutil/db/DBConnection.java @@ -21,6 +21,7 @@ ******************************************************************************/ package zutil.db; +import java.io.Closeable; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -37,7 +38,7 @@ import javax.sql.DataSource; import zutil.db.handler.SimpleSQLHandler; import zutil.log.LogUtil; -public class DBConnection{ +public class DBConnection implements Closeable{ private static final Logger logger = LogUtil.getLogger(); public enum DBMS{ diff --git a/src/zutil/db/DBConnectionPool.java b/src/zutil/db/DBConnectionPool.java index f69c9bf..c6062fd 100644 --- a/src/zutil/db/DBConnectionPool.java +++ b/src/zutil/db/DBConnectionPool.java @@ -21,7 +21,7 @@ ******************************************************************************/ package zutil.db; -import java.sql.SQLException; +import java.io.Closeable; import java.util.LinkedList; import java.util.Timer; import java.util.TimerTask; @@ -33,7 +33,7 @@ import zutil.db.DBConnection.DBMS; * * @author Ziver */ -public class DBConnectionPool extends TimerTask { +public class DBConnectionPool extends TimerTask implements Closeable{ public static final long DEFAULT_TIMEOUT = 10*60*60*1000; // 10 minutes; public static final int DEFAULT_MAX_SIZE = 5; @@ -150,7 +150,7 @@ public class DBConnectionPool extends TimerTask { /** * Closes all the connections */ - public synchronized void close() throws SQLException{ + public synchronized void close(){ for( PoolItem item : inusePool ){ item.conn.forceClose(); } diff --git a/src/zutil/io/file/FileUtil.java b/src/zutil/io/file/FileUtil.java index 279521b..724243d 100644 --- a/src/zutil/io/file/FileUtil.java +++ b/src/zutil/io/file/FileUtil.java @@ -281,7 +281,7 @@ public class FileUtil { } /** - * Returns the extension of the file + * Returns the extension(without the dot) of the file. e.g. "png" "avi" * * @param file is the file * @return The extension @@ -291,5 +291,20 @@ public class FileUtil { return ""; return file.substring(file.lastIndexOf(".")+1, file.length()); } + + /** + * Replaces the current extension on the file withe the given one. + * + * @param filename is the name of the file + * @param string is the new extension, without the dot + * @return + */ + public static String changeExtension(String file, String ext) { + if( file == null ) + return null; + if( file.lastIndexOf(".") == -1 ) + return file+"."+ext; + return file.substring(0, file.lastIndexOf(".")+1)+ext; + } } diff --git a/src/zutil/jee/upload/FileUploadListener.java b/src/zutil/jee/upload/FileUploadListener.java index 58ee615..7b2ba37 100644 --- a/src/zutil/jee/upload/FileUploadListener.java +++ b/src/zutil/jee/upload/FileUploadListener.java @@ -71,11 +71,12 @@ public class FileUploadListener implements ProgressListener{ this.item = pItems; // Calculate Speed - if(speedTime == 0 || speedTime+1000