IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class); if (file == null) throw new FileNotFoundException(); String content = IOUtils.toString(file.getContents(), file.getCharset());
@Override public String getCharset() { try { return file.getCharset(false); } catch (CoreException e) { return null; } }
private String getCharSetName(IFile file) { try { return file.getCharset(); } catch (CoreException e) { return "unknown"; //$NON-NLS-1$ } }
private String getCharSetName(IFile file) { try { return file.getCharset(); } catch (CoreException e) { return "unknown"; //$NON-NLS-1$ } }
private String getCharSetName(IFile file) { try { return file.getCharset(); } catch (CoreException e) { return "unknown"; //$NON-NLS-1$ } }
public String getFileEncoding() { try { return file.getCharset(); } catch (CoreException e) { return "UTF-8"; } }
private void initializeReader() throws CoreException, IOException { if (fReader != null) { fReader.close(); } String charset= fFile.getCharset(); fReader= new InputStreamReader(getInputStream(charset), charset); fReaderPos= 0; }
public static String getEncoding(String path) { try { return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)).getCharset(); } catch (CoreException exception) { return null; } }
public static String getEncoding(String workspacePath) { try { return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(workspacePath)).getCharset(); } catch (CoreException exception) { return null; } }
public static String getEncoding(String path) { try { return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)).getCharset(); } catch (CoreException exception) { return null; } }
private static CreateFileChange createUndoChange(IFile file, IPath path, long stampToRestore, String source) { String encoding; try { encoding= file.getCharset(false); } catch (CoreException e) { encoding= null; } return new CreateFileChange(path, source, encoding, stampToRestore); }
public static String getEncoding(String workspacePath) { try { return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(workspacePath)).getCharset(); } catch (CoreException exception) { return null; } }
private void initializeReader() throws CoreException, IOException { if (fReader != null) { fReader.close(); } String charset = fFile.getCharset(); fReader = new InputStreamReader(getInputStream(charset), charset); fReaderPos = 0; }
public void createXMLDocument(IFile newFile, String xmlFileName) throws Exception { String charset = newFile.getCharset(); ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); newFile.setContents(inputStream, true, true, null); inputStream.close(); }
@Override public Charset getCharset() { try { return Charset.forName(file.getCharset()); } catch (CoreException e) { SonarLintLogger.get().error("Unable to determine charset of file " + file, e); return Charset.defaultCharset(); } }
private void createPackageHtml(IPackageFragmentRoot root, IProgressMonitor monitor) throws CoreException { IWorkspace workspace= ResourcesPlugin.getWorkspace(); IFolder createdPackage= workspace.getRoot().getFolder(fCreatedPackageFragment.getPath()); IFile packageHtml= createdPackage.getFile(PACKAGE_HTML_FILENAME); String charset= packageHtml.getCharset(); String content= buildPackageHtmlContent(root, charset); try { packageHtml.create(new ByteArrayInputStream(content.getBytes(charset)), false, monitor); } catch (UnsupportedEncodingException e) { String message= "charset " + charset + " not supported by platform"; //$NON-NLS-1$ //$NON-NLS-2$ throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, message, e)); } }
public String getEncoding() throws CoreException { if(resource instanceof XtextResource) { return ((XtextResource) resource).getEncoding(); } return getFile().getCharset(); }
@Override public String getCharset() { IFile file = getTargetFile(); try { if (file != null) return file.getCharset(); } catch (CoreException e) { } return ResourcesPlugin.getEncoding(); } }
protected BufferValidationState(IFile file) { fFile= file; fExisted= file.exists(); fDerived= file.isDerived(); fWasDirty= isDirty(fFile); String encoding; try { encoding= file.getCharset(true); } catch (CoreException e) { encoding= null; } fEncoding= encoding; }
private String getLocalEncoding() { IResource resource = getResource(getCurrentFileRevision()); if (resource instanceof IFile) { IFile file = (IFile) resource; try { return file.getCharset(); } catch (CoreException e) { TeamUIPlugin.log(e); } } return null; }