1 11 package org.eclipse.jdt.internal.corext.refactoring.nls.changes; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.NullProgressMonitor; 20 21 import org.eclipse.jdt.core.IJavaModelStatusConstants; 22 import org.eclipse.jdt.core.JavaModelException; 23 24 import org.eclipse.jdt.internal.corext.refactoring.nls.NLSUtil; 25 26 public class CreateTextFileChange extends CreateFileChange { 27 28 private final String fTextType; 29 30 public CreateTextFileChange(IPath path, String source, String encoding, String textType) { 31 super(path, source, encoding); 32 fTextType= textType; 33 } 34 35 public String getTextType() { 36 return fTextType; 37 } 38 39 public String getCurrentContent() throws JavaModelException { 40 IFile file= getOldFile(new NullProgressMonitor()); 41 if (! file.exists()) 42 return ""; InputStream stream= null; 44 try{ 45 stream= file.getContents(); 46 String encoding= file.getCharset(); 47 String c= NLSUtil.readString(stream, encoding); 48 return (c == null) ? "": c; } catch (CoreException e){ 50 throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION); 51 } finally { 52 try { 53 if (stream != null) 54 stream.close(); 55 } catch (IOException x) { 56 } 57 } 58 } 59 60 public String getPreview() { 61 return getSource(); 62 } 63 } 64 65 | Popular Tags |