InputStream is= ((IStreamContentAccessor)ti).getContents(); String newContent= trimTextBlock(is, buffer.getLineDelimiter());
String content= JavaCompareUtilities.readString((IStreamContentAccessor)ti); String newContent= trimTextBlock(content, buffer.getLineDelimiter());
	public void run(ISelection selection) {				String errorTitle= CompareMessages.getString("ReplaceFromHistory.title"); //$NON-NLS-1$		String errorMessage= CompareMessages.getString("ReplaceFromHistory.internalErrorMessage"); //$NON-NLS-1$		Shell shell= getShell();				IMember input= getEditionElement(selection);		if (input == null) {			String invalidSelectionMessage= CompareMessages.getString("ReplaceFromHistory.invalidSelectionMessage"); //$NON-NLS-1$			MessageDialog.openInformation(shell, errorTitle, invalidSelectionMessage);			return;		}				IFile file= getFile(input);		if (file == null) {			MessageDialog.openError(shell, errorTitle, errorMessage);			return;		}												boolean inEditor= beingEdited(file);		if (inEditor)			input= (IMember) getWorkingCopy(input);		// get a TextBuffer where to insert the text		TextBuffer buffer= null;		try {			buffer= TextBuffer.acquire(file);						if (! buffer.makeCommittable(shell).isOK())				return;			ResourceBundle bundle= ResourceBundle.getBundle(BUNDLE_NAME);			EditionSelectionDialog d= new EditionSelectionDialog(shell, bundle);			d.setHelpContextId(IJavaHelpContextIds.REPLACE_ELEMENT_WITH_HISTORY_DIALOG);						ITypedElement target= new JavaTextBufferNode(buffer, inEditor);			ITypedElement[] editions= buildEditions(target, file);			ITypedElement ti= null;			if (fPrevious) {				ti= d.selectPreviousEdition(target, editions, input);				if (ti == null) {					MessageDialog.openInformation(shell, errorTitle, CompareMessages.getString("ReplaceFromHistory.parsingErrorMessage"));	//$NON-NLS-1$					return;				}			} else				ti= d.selectEdition(target, editions, input);									if (ti instanceof IStreamContentAccessor) {								InputStream is= ((IStreamContentAccessor)ti).getContents();				String newContent= trimTextBlock(is, buffer.getLineDelimiter());				if (newContent == null) {					MessageDialog.openError(shell, errorTitle, errorMessage);					return;				}								CompilationUnit root= AST.parsePartialCompilationUnit(input.getCompilationUnit(), 0, false);				BodyDeclaration node= (BodyDeclaration)ASTNodes.getParent(NodeFinder.perform(root, input.getNameRange()), BodyDeclaration.class);				if (node == null) {					MessageDialog.openError(shell, errorTitle, errorMessage);					return;				}								ASTRewrite rewriter= new ASTRewrite(root);				rewriter.markAsReplaced(node, rewriter.createPlaceholder(newContent, ASTRewrite.getPlaceholderType(node)));								if (inEditor) {					JavaEditor je= getEditor(file);					if (je != null)						je.setFocus();				}								applyChanges(rewriter, buffer, shell, inEditor);							}	 	} catch(InvocationTargetException ex) {			ExceptionHandler.handle(ex, shell, errorTitle, errorMessage);					} catch(InterruptedException ex) {			// shouldn't be called because is not cancable			Assert.isTrue(false);					} catch(CoreException ex) {			ExceptionHandler.handle(ex, shell, errorTitle, errorMessage);					} finally {			if (buffer != null)				TextBuffer.release(buffer);		}	}