private void writeCommandFile ( final IProgressMonitor monitor ) throws Exception { final String data = "# These commands must be executed on the target instance" + NL + this.commandBuilder; try ( final ByteArrayInputStream input = new ByteArrayInputStream ( data.getBytes () ) ) { this.commandFile.create ( input, IResource.KEEP_HISTORY, monitor ); } }
private void writeCommandFile ( final IProgressMonitor monitor ) throws Exception { final String data = "# These commands must be executed on the target instance" + NL + this.commandBuilder; try ( final ByteArrayInputStream input = new ByteArrayInputStream ( data.getBytes () ) ) { this.commandFile.create ( input, IResource.KEEP_HISTORY, monitor ); } }
String fileContents = ...; IFile file = ...; file.create(new ByteArrayInputStream(fileContents.getBytes()), true, null); FileEditorInput input = new FileEditorInput(file); PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().openEditor(input, THE_EDITOR_ID);
Bundle bundle = Platform.getBundle( "your.plugin.id" ); InputStream stream = FileLocator.openStream( bundle, "path.in.plugin", false ); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( "your.project" ); IFile file = project.getFile( "something/abc.txt" ); file.create( stream, true, null );
protected void createFileIfRequired(IFile file) { try { if ((file != null) && !file.exists()) { ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]); file.create(inputStream, true, null); // createEmptyXMLCatalog(file); } } catch (Exception e) { } } }
private static void createNewFile(IFile file, String newContent, IProgressMonitor monitor) throws CoreException { ensureExists(file.getParent(), monitor); try { file.create(new ByteArrayInputStream(newContent.getBytes("UTF-8")), false, monitor); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, e.getMessage(), e)); } }
private static void createNewFile(IFile file, String newContent, IProgressMonitor monitor) throws CoreException { ensureExists(file.getParent(), monitor); try { file.create(new ByteArrayInputStream(newContent.getBytes("UTF-8")), false, monitor); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, e.getMessage(), e)); } }
private static void createNewFile(IFile file, String newContent, IProgressMonitor monitor) throws CoreException { ensureExists(file.getParent(), monitor); try { file.create(new ByteArrayInputStream(newContent.getBytes("UTF-8")), false, monitor); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, e.getMessage(), e)); } }
private void addJar(File jarFile, IProject project, IProgressMonitor monitor) throws CoreException { String jarName = jarFile.getName(); IFile file = project.getFile(jarName); monitor.subTask(NLS.bind(PDEUIMessages.NewProjectCreationOperation_copyingJar, jarName)); try (InputStream in = new FileInputStream(jarFile)) { file.create(in, true, monitor); } catch (IOException fnfe) { } }
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); } } }
public static void createEmptyFile(IFile newFile) throws CoreException { if (newFile.getParent() instanceof IFolder) { prepareFolder((IFolder)newFile.getParent()); } try (InputStream inputStream = new ByteArrayInputStream(new byte[0])) { newFile.create(inputStream, true, null); } catch (Exception e) { throw new CoreException(LiferayCore.createErrorStatus(e)); } }
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); }
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 { 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) { } }