Revision: 656
http://stripes.svn.sourceforge.net/stripes/?rev=656&view=rev
Author: bengunter
Date: 2007-12-10 07:13:33 -0800 (Mon, 10 Dec 2007)
Log Message:
-----------
Use a 1KB buffer instead of single-byte reads in saveViaCopy() because it
dramatically improves performance.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/action/FileBean.java
Modified: trunk/stripes/src/net/sourceforge/stripes/action/FileBean.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/action/FileBean.java
2007-12-10 00:01:00 UTC (rev 655)
+++ trunk/stripes/src/net/sourceforge/stripes/action/FileBean.java
2007-12-10 15:13:33 UTC (rev 656)
@@ -191,19 +191,37 @@
* @param toFile the file to save to
*/
protected void saveViaCopy(File toFile) throws IOException {
- BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(toFile));
- BufferedInputStream in = new BufferedInputStream(new
FileInputStream(this.file));
+ OutputStream out = null;
+ InputStream in = null;
+ try {
+ out = new FileOutputStream(toFile);
+ in = new FileInputStream(this.file);
- int b;
- while ((b = in.read()) != -1) {
- out.write(b);
- }
+ byte[] buffer = new byte[1024];
+ for (int count; (count = in.read(buffer)) > 0;) {
+ out.write(buffer, 0, count);
+ }
- in.close();
- out.close();
+ out.close();
+ out = null;
+ in.close();
+ in = null;
- this.file.delete();
- this.saved = true;
+ this.file.delete();
+ this.saved = true;
+ }
+ finally {
+ try {
+ if (out != null)
+ out.close();
+ }
+ catch (Exception e) {}
+ try {
+ if (in != null)
+ in.close();
+ }
+ catch (Exception e) {}
+ }
}
/**
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development