Mercurial > hg > blitz_stable
comparison src/org/dancres/io/FileCopier.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.io; | |
2 | |
3 import java.io.*; | |
4 import java.nio.channels.*; | |
5 import java.nio.*; | |
6 | |
7 public class FileCopier { | |
8 private ByteBuffer theBuffer = | |
9 ByteBuffer.allocateDirect(16 * 1024 * 1024); | |
10 | |
11 public FileCopier() { | |
12 } | |
13 | |
14 /** | |
15 Pass file name and directory to copy it to | |
16 */ | |
17 public static void main(String args[]) { | |
18 try { | |
19 File myIn = new File(args[0]); | |
20 File myOut = new File(args[1]); | |
21 | |
22 FileCopier myCopier = new FileCopier(); | |
23 | |
24 long myStart = System.currentTimeMillis(); | |
25 | |
26 myCopier.copy (myIn, myOut); | |
27 | |
28 long myEnd = System.currentTimeMillis(); | |
29 | |
30 // System.out.println("Total time: " + (myEnd - myStart)); | |
31 | |
32 } catch (Exception anE) { | |
33 anE.printStackTrace(System.err); | |
34 } | |
35 } | |
36 | |
37 public void copy(File aSource, File aDestDir) throws IOException { | |
38 FileInputStream myInFile = new FileInputStream(aSource); | |
39 | |
40 FileOutputStream myOutFile = | |
41 new FileOutputStream(new File(aDestDir, aSource.getName())); | |
42 | |
43 FileChannel myIn = myInFile.getChannel(); | |
44 FileChannel myOut = myOutFile.getChannel(); | |
45 | |
46 boolean end = false; | |
47 | |
48 while (true) { | |
49 | |
50 int myBytes = myIn.read(theBuffer); | |
51 | |
52 if (myBytes != -1) { | |
53 theBuffer.flip(); | |
54 | |
55 myOut.write(theBuffer); | |
56 | |
57 theBuffer.clear(); | |
58 } else | |
59 break; | |
60 } | |
61 | |
62 myIn.close(); | |
63 // myOut.force(false); | |
64 myOut.close(); | |
65 myInFile.close(); | |
66 myOutFile.close(); | |
67 | |
68 long myEnd = System.currentTimeMillis(); | |
69 } | |
70 } |