1 /******************************************************************************* 2 * Copyright (c) 2005, 2007 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.compare.patch; 12 13 import java.io.InputStream; 14 15 import org.eclipse.core.resources.IEncodedStorage; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IAdaptable; 18 19 /** 20 * Interface that represents a hunk. A hunk is a portion of a patch. It 21 * identifies where the hunk is to be located in the target file. One use of 22 * this interface is a means to communicate to content merge viewers that one of 23 * the sides of a compare input is a patch hunk. Clients can determine which 24 * side it is by adapting the side to this interface (see {@link IAdaptable}. 25 * <p> 26 * This interface is not intended to be implemented by clients but can be 27 * obtained from an {@link IFilePatchResult} 28 * </p> 29 * 30 * @since 3.3 31 * 32 */ 33 public interface IHunk { 34 35 /** 36 * Return a label that can be used to describe the hunk. 37 * @return a label that can be used to describe the hunk 38 */ 39 public String getLabel(); 40 41 /** 42 * Return the start position of the hunk in the target file. 43 * 44 * @return the start position of the hunk in the target file. 45 */ 46 public int getStartPosition(); 47 48 /** 49 * Return the original contents from which the hunk was generated. 50 * The returned contents usually only represent a portion of the 51 * file from which the hunk was generated. 52 * @return the original contents from which the hunk was generated 53 */ 54 public InputStream getOriginalContents(); 55 56 /** 57 * Return the contents that contain the modifications for this hunk. 58 * The returned contents usually only represent a portion of the 59 * file that was modified. 60 * @return the contents that contain the modifications for this hunk 61 */ 62 public InputStream getPatchedContents(); 63 64 /** 65 * Returns the name of a charset encoding to be used when decoding the contents 66 * of this hunk into characters. Returns <code>null</code> if a proper 67 * encoding cannot be determined. 68 * <p> 69 * Note that this method does not check whether the result is a supported 70 * charset name. Callers should be prepared to handle 71 * <code>UnsupportedEncodingException</code> where this charset is used. 72 * </p> 73 * 74 * @return the name of a charset, or <code>null</code> 75 * @exception CoreException if an error happens while determining 76 * the charset. See any refinements for more information. 77 * @see IEncodedStorage 78 */ 79 public String getCharset() throws CoreException; 80 81 82 } 83