1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.io.*; 14 import java.nio.channels.FileChannel ; 15 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.team.internal.ccvs.core.CVSException; 19 import org.eclipse.team.internal.ccvs.core.CVSStatus; 20 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 21 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 22 import org.eclipse.team.internal.core.TeamPlugin; 23 import org.eclipse.ui.IWorkbenchPart; 24 25 public class FileDiffOperation extends DiffOperation { 26 27 FileOutputStream os; 28 PrintStream printStream; 29 File file; 30 File tempFile; 31 32 public FileDiffOperation(IWorkbenchPart part, ResourceMapping[] mappings, LocalOption[] options, File file, boolean isMultiPatch, boolean includeFullPathInformation, IPath patchRoot) { 33 super(part, mappings, options, isMultiPatch, includeFullPathInformation, patchRoot, file.getAbsolutePath()); 34 IPath teamLocation= TeamPlugin.getPlugin().getStateLocation(); 35 IPath tempFilePath = teamLocation.append(new Path(IPath.SEPARATOR + "tempDiff" + System.currentTimeMillis())); tempFile = tempFilePath.toFile(); 37 this.file = file; 38 } 39 40 public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 41 super.execute(monitor); 42 43 if (tempFile.length() == 0) { 44 tempFile.delete(); 45 reportEmptyDiff(); 46 return; 47 } 48 49 if (this.isMultiPatch && 50 (!patchHasContents && !patchHasNewFiles)){ 51 tempFile.delete(); 52 reportEmptyDiff(); 53 return; 54 } 55 56 copyFile(); 57 } 58 59 protected void copyFile() throws CVSException { 60 FileChannel tempFileChannel=null; 61 FileChannel fileChannel=null; 62 try { 63 tempFileChannel = new FileInputStream(tempFile).getChannel(); 64 fileChannel = new FileOutputStream(file).getChannel(); 65 66 long size= tempFileChannel.size(); 67 long bytesTransferred = fileChannel.transferFrom(tempFileChannel, 0, size); 68 while (bytesTransferred != size){ 69 bytesTransferred += fileChannel.transferFrom(tempFileChannel, bytesTransferred, size); 71 } 72 } catch (IOException e) { 73 throw CVSException.wrapException(e); 74 } finally { 75 if (tempFileChannel!=null) 76 try { 77 tempFileChannel.close(); 78 } catch (IOException e) { 79 throw CVSException.wrapException(e); 80 } 81 82 if (fileChannel!=null) 83 try { 84 fileChannel.close(); 85 } catch (IOException e) { 86 throw CVSException.wrapException(e); 87 } 88 89 if (tempFile != null) 90 tempFile.delete(); 91 } 92 } 93 94 97 protected PrintStream openStream() throws CVSException { 98 try { 99 os = new FileOutputStream(tempFile); 100 return new PrintStream(os); 101 } catch (FileNotFoundException e) { 102 IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, CVSUIMessages.GenerateDiffFileOperation_0, e); 103 throw new CVSException(status); 104 } 105 } 106 107 } 108 | Popular Tags |