public void run(IProgressMonitor myMonitor) throws InvocationTargetException, InterruptedException { try { file.setContents(new ByteArrayInputStream(newContent), false, true, myMonitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } });
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(); }
public void execute(IProgressMonitor pm) throws InvocationTargetException { try { String taskName= Utilities.getString(bundle, "taskName"); //$NON-NLS-1$ pm.beginTask(taskName, IProgressMonitor.UNKNOWN); file.setContents(sa.getContents(), false, true, pm); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { pm.done(); } } };
/** * Writes content to file, within the workspace. A change event is emitted. */ public static void setContent(IFile file, String content) throws CoreException { Assert.isNotNull(file, "file can not be null"); if (content == null) { content = ""; } try (InputStream newContent = new ByteArrayInputStream(content.getBytes())) { file.setContents(newContent, IResource.FORCE, null); } catch (IOException e) { throw new CoreException(StatusFactory.newErrorStatus("Can not write to " + file.getRawLocation(), e)); } }
/** * Saves the server configuration using the given {@link FileEditorInput}. * * @param fei * the {@link FileEditorInput} * @throws ServerConfigurationWriterException * @throws CoreException * @throws IOException */ private void saveConfiguration( FileEditorInput fei, IProgressMonitor monitor ) throws CoreException, IOException { String xml = serverXmlIO.toXml( serverConfiguration ); fei.getFile().setContents( new ByteArrayInputStream( xml.getBytes() ), true, true, monitor ); }
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (newFile.exists()) { newFile.setContents(new ByteArrayInputStream(docbook.getBytes("utf-8")), false, true, //$NON-NLS-1$ monitor); } else { newFile.create(new ByteArrayInputStream(docbook.getBytes("utf-8")), false, monitor); //$NON-NLS-1$ } newFile.setCharset("utf-8", monitor); //$NON-NLS-1$ } catch (Exception e) { throw new InvocationTargetException(e); } } };
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (newFile.exists()) { newFile.setContents(new ByteArrayInputStream(xhtmlContent.getBytes("utf-8")), false, true, //$NON-NLS-1$ monitor); } else { newFile.create(new ByteArrayInputStream(xhtmlContent.getBytes("utf-8")), false, monitor); //$NON-NLS-1$ } newFile.setCharset("utf-8", monitor); //$NON-NLS-1$ } catch (Exception e) { throw new InvocationTargetException(e); } } };
/** * Save installation descriptor. * * @param currentContainer An IProject with the UIMA nature * @param insd The installation descriptor object * @throws CoreException if there is problem accessing the corresponding resource * @throws IOException if there is problem writing to the corresponding resource */ public static void saveInstallationDescriptor(IContainer currentContainer, InstallationDescriptor insd) throws CoreException, IOException { IFile installFile = currentContainer.getFile(new Path(INSTALLATION_DESCRIPTOR_PATH)); installFile.setContents(InstallationDescriptorHandler.getInstallationDescriptorAsStream(insd), false, true, null); }
public void writeToFile(IFile file) throws CoreException { final InputStream source = new ByteArrayInputStream(writeToString().getBytes(Charset.availableCharsets().get("UTF-8"))); if (file.exists()) { file.setContents(source, false, true, null); } else { file.create(source, false, null); } } }
private void saveManifest() throws CoreException, IOException { ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream(); Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage); manifest.write(manifestOutput); ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray()); IFile manifestFile= fJarPackage.getManifestFile(); if (manifestFile.isAccessible()) { if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath().toString())) manifestFile.setContents(fileInput, true, true, null); } else manifestFile.create(fileInput, true, null); }
private void createLoggerFile(IJavaProject project, IProgressMonitor monitor) throws CoreException { String fileName = "org/jbpm/eclipse/wizard/project/logback-test.xml.template"; IFolder folder = project.getProject().getFolder("src/main/resources"); FileUtils.createFolder(folder, monitor); IFile file = folder.getFile("logback-test.xml"); InputStream inputstream = getClass().getClassLoader().getResourceAsStream(fileName); if (!file.exists()) { file.create(inputstream, true, monitor); } else { file.setContents(inputstream, true, false, monitor); } }
protected void saveToIFile(IFile iFile, InputStream in) throws Exception { validateEdit(iFile); if (iFile.exists()) iFile.setContents(in, true, true, null); else { mkdirs(iFile.getFullPath().removeLastSegments(1), ResourcesPlugin.getWorkspace().getRoot()); iFile.create(in, true, null); } }
private void saveManifest() throws CoreException, IOException { ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream(); Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage); manifest.write(manifestOutput); ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray()); IFile manifestFile= fJarPackage.getManifestFile(); if (manifestFile.isAccessible()) { if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath(), false)) manifestFile.setContents(fileInput, true, true, null); } else manifestFile.create(fileInput, true, null); }
private void saveManifest() throws CoreException, IOException { ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream(); Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage); manifest.write(manifestOutput); ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray()); IFile manifestFile= fJarPackage.getManifestFile(); if (manifestFile.isAccessible()) { if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath(), false)) manifestFile.setContents(fileInput, true, true, null); } else manifestFile.create(fileInput, true, null); }
private void copyFile(String fileName, InputStream input, IContainer dst, boolean binary, IProgressMonitor monitor) throws CoreException { monitor.subTask(fileName); IFile dstFile = dst.getFile(new Path(fileName)); try (InputStream stream = getProcessedStream(fileName, input, binary)) { if (dstFile.exists()) { dstFile.setContents(stream, true, true, monitor); } else { dstFile.create(stream, true, monitor); } } catch (IOException e) { } }
protected void saveToIFile(IFile iFile, InputStream in) throws Exception { validateEdit(iFile); if (iFile.exists()) iFile.setContents(in, true, true, null); else { mkdirs(iFile.getFullPath().removeLastSegments(1), ResourcesPlugin.getWorkspace().getRoot()); iFile.create(in, true, null); } }
private void copyFile(String fileName, InputStream input, IContainer dst, boolean binary, IProgressMonitor monitor) throws CoreException { String targetFileName = getProcessedString(fileName, fileName); monitor.subTask(targetFileName); IFile dstFile = dst.getFile(new Path(targetFileName)); try (InputStream stream = getProcessedStream(fileName, input, binary)) { if (dstFile.exists()) { dstFile.setContents(stream, true, true, monitor); } else { dstFile.create(stream, true, monitor); } } catch (IOException e) { } }
private void copyFile(String fileName, InputStream input, IContainer dst, boolean binary, IProgressMonitor monitor) throws CoreException { String targetFileName = getProcessedString(fileName, fileName); monitor.subTask(targetFileName); IFile dstFile = dst.getFile(new Path(targetFileName)); try (InputStream stream = getProcessedStream(fileName, input, binary)) { if (dstFile.exists()) { dstFile.setContents(stream, true, true, monitor); } else { dstFile.create(stream, true, monitor); } } catch (IOException e) { } }
public boolean okPressed() { try { Object o = getSelectedEdition(); FileRevisionTypedElement right = (FileRevisionTypedElement) ((ICompareInput)o).getRight(); IFile file = (IFile)getCompareResult(); file.setContents(right.getContents(), false, true, null); } catch (CoreException e) { Utils.handle(e); return false; } return true; } };
@Override public boolean okPressed() { try { Object o = getSelectedEdition(); FileRevisionTypedElement right = (FileRevisionTypedElement) ((ICompareInput)o).getRight(); IFile file = (IFile)getCompareResult(); file.setContents(right.getContents(), false, true, null); } catch (CoreException e) { Utils.handle(e); return false; } return true; } };