From: Eric P. <th...@us...> - 2010-01-24 21:01:47
|
Update of /cvsroot/sandev/sand/apps/basics/src/org/sandev/basics/util In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv386 Modified Files: FileUtil.java Log Message: Factored and fixed for heavy load usage. Index: FileUtil.java =================================================================== RCS file: /cvsroot/sandev/sand/apps/basics/src/org/sandev/basics/util/FileUtil.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** FileUtil.java 30 Nov 2005 04:10:27 -0000 1.1.1.1 --- FileUtil.java 24 Jan 2010 21:01:37 -0000 1.2 *************** *** 1,5 **** /* * SAND development/deployment environment ! * Copyright (C) 2005 SAND Services Inc. * * This library is free software; you can redistribute it and/or --- 1,5 ---- /* * SAND development/deployment environment ! * Copyright (C) 2005,2010 SAND Services Inc. * * This library is free software; you can redistribute it and/or *************** *** 43,63 **** throws IOException { OutputStream fileOut=null; InputStream fileIn=null; try { - File newdir=new File(newpath); - if(!newdir.exists()) { - newdir.mkdirs(); } - File srcfile=new File(currpath,filename); if(!srcfile.exists()) { throw new IOException( "copyfile srcfile " + srcfile + " not found."); } fileIn=new BufferedInputStream(new FileInputStream(srcfile)); - File outfile=new File(newpath,filename); fileOut=new BufferedOutputStream(new FileOutputStream(outfile)); byte[] buf=new byte[8*1024]; ! int bytesread=buf.length; ! while(bytesread==buf.length) { ! bytesread=fileIn.read(buf,0,buf.length); fileOut.write(buf,0,bytesread); } } finally { --- 43,72 ---- throws IOException { + File newdir=new File(newpath); + if(!newdir.exists()) { + newdir.mkdirs(); } + File srcfile=new File(currpath,filename); + File outfile=new File(newpath,filename); + copyfile(srcfile,outfile); + } + + + /** + * Copy the specified file srcfile to outfile + */ + public static void copyfile(File srcfile,File outfile) + throws IOException + { OutputStream fileOut=null; InputStream fileIn=null; try { if(!srcfile.exists()) { throw new IOException( "copyfile srcfile " + srcfile + " not found."); } fileIn=new BufferedInputStream(new FileInputStream(srcfile)); fileOut=new BufferedOutputStream(new FileOutputStream(outfile)); byte[] buf=new byte[8*1024]; ! int bytesread; ! while((bytesread=fileIn.read(buf))>0) { fileOut.write(buf,0,bytesread); } } finally { |