1 package net.sourceforge.phpeclipse.mover;
4 * Copy the file from the source to the target directory.
8 import java.io.FileInputStream;
9 import java.io.FileOutputStream;
10 import java.io.IOException;
12 import net.sourceforge.phpeclipse.views.PHPConsole;
14 public class CopyMover extends DefaultMover {
16 * buffer, for obvious reasons access to this buffer must
19 protected byte[] bytes = new byte[1024];
22 * Return the name the file would have after moving. In this case,
23 * it's left unchanged.
24 * @param file file the mover would have to move
25 * @return the extension it would give the file in the target directory
27 public String getTargetName(File file) {
28 return file.getName();
32 * Creates a CopyMover.
33 * @param console reports error to the PHPConsole
35 public CopyMover(PHPConsole console) {
41 * @param sourceFile the file to move
42 * @param targetDir the directory to copy the result to
43 * @return file or null if the file was ignored
45 public File move(File sourceFile, File targetDir) {
47 File targetFile = new File(targetDir, getTargetName(sourceFile));
48 if (targetFile.exists())
49 if (targetFile.lastModified() >= sourceFile.lastModified())
51 synchronized (bytes) {
52 FileInputStream in = new FileInputStream(sourceFile);
53 FileOutputStream out = new FileOutputStream(targetFile);
54 for (int len = in.read(bytes); len != -1; len = in.read(bytes)) {
55 out.write(bytes, 0, len);
61 } catch (IOException e) {
62 fConsole.write(e.toString());