1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.io.*; 14 15 import org.eclipse.compare.IStreamMerger; 16 import org.eclipse.core.resources.IEncodedStorage; 17 import org.eclipse.core.resources.IStorage; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.mapping.IStorageMerger; 20 import org.eclipse.team.internal.ui.TeamUIPlugin; 21 22 27 public class StorageStreamMerger implements IStorageMerger { 28 29 private IStreamMerger merger; 30 31 public StorageStreamMerger(IStreamMerger merger) { 32 this.merger = merger; 33 } 34 35 public IStatus merge(OutputStream output, String outputEncoding, IStorage ancestorStorage, IStorage targetStorage, IStorage otherStorage, IProgressMonitor monitor) throws CoreException { 36 InputStream ancestorStream = null; 37 InputStream remoteStream = null; 38 InputStream targetStream = null; 39 try { 40 ancestorStream = new BufferedInputStream(ancestorStorage.getContents()); 41 remoteStream = new BufferedInputStream(otherStorage.getContents()); 42 targetStream = new BufferedInputStream(targetStorage.getContents()); 43 IStatus status = merger.merge(output, outputEncoding, 44 ancestorStream, getEncoding(ancestorStorage, outputEncoding), 45 targetStream, getEncoding(targetStorage, outputEncoding), 46 remoteStream, getEncoding(otherStorage, outputEncoding), 47 monitor); 48 if (status.isOK()) 49 return status; 50 if (status.getCode() == IStreamMerger.CONFLICT) 51 return new Status(status.getSeverity(), status.getPlugin(), CONFLICT, status.getMessage(), status.getException()); 52 return status; 53 } finally { 54 try { 55 if (ancestorStream != null) 56 ancestorStream.close(); 57 } catch (IOException e) { 58 } 60 try { 61 if (remoteStream != null) 62 remoteStream.close(); 63 } catch (IOException e) { 64 } 66 try { 67 if (targetStream != null) 68 targetStream.close(); 69 } catch (IOException e) { 70 } 72 } 73 } 74 75 private String getEncoding(IStorage ancestorStorage, String outputEncoding) { 76 if (ancestorStorage instanceof IEncodedStorage) { 77 IEncodedStorage es = (IEncodedStorage) ancestorStorage; 78 try { 79 String charSet = es.getCharset(); 80 if (charSet != null) 81 return charSet; 82 } catch (CoreException e) { 83 TeamUIPlugin.log(e); 84 } 85 } 86 return outputEncoding; 87 } 88 89 92 public boolean canMergeWithoutAncestor() { 93 return false; 94 } 95 96 } 97 | Popular Tags |