Java Code Examples for com.intellij.openapi.vfs.VirtualFile#getOutputStream()
The following examples show how to use
com.intellij.openapi.vfs.VirtualFile#getOutputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SOAPKitScaffoldingAction.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
private void writeMuleXmlFile(Element element, VirtualFile muleConfig) { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); InputStream inputStream = null; try { String outputString = xout.outputString(element); logger.debug("*** OUTPUT STRING IS " + outputString); OutputStreamWriter writer = new OutputStreamWriter(muleConfig.getOutputStream(this)); writer.write(outputString); writer.flush(); writer.close(); } catch (Exception e) { logger.error("Unable to write file: " + e); e.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); } }
Example 2
Source File: ViewController.java From CleanArchitecturePlugin with Apache License 2.0 | 5 votes |
public static void createLayout(String directory, String className, String type) throws Exception { final String INDENT_SPACE = "{http://xml.apache.org/xslt}indent-amount"; final String nsUri = "http://www.w3.org/2000/xmlns/"; final String androidUri = "http://schemas.android.com/apk/res/android"; final String toolsUri = "http://schemas.android.com/tools"; VirtualFile parent = getResPackage(); // Res package in android project VirtualFile layoutDirectory = parent.findChild("layout"); VirtualFile newXmlFile = layoutDirectory.createChildData(null, type.toLowerCase() + "_" + getEntityConfig().getEntityName().toLowerCase() + ".xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element root = doc.createElement("RelativeLayout"); root.setAttributeNS(nsUri, "xmlns:android", androidUri); root.setAttributeNS(nsUri, "xmlns:tools", toolsUri); root.setAttribute("android:id", "@+id/container"); root.setAttribute("android:layout_width", "match_parent"); root.setAttribute("android:layout_height", "match_parent"); root.setAttribute("tools:context", directory + "." + className); doc.appendChild(root); OutputStream os = newXmlFile.getOutputStream(null); PrintWriter out = new PrintWriter(os); StringWriter writer = new StringWriter(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(INDENT_SPACE, "4"); transformer.transform(new DOMSource(doc), new StreamResult(writer)); out.println(writer.getBuffer().toString()); out.close(); }
Example 3
Source File: FileUtils.java From JHelper with GNU Lesser General Public License v3.0 | 5 votes |
public static OutputWriter getOutputWriter(VirtualFile virtualFile, Object requestor) { try { return new OutputWriter(virtualFile.getOutputStream(requestor)); } catch (IOException e) { throw new NotificationException("Couldn't open virtual file to write", e); } }
Example 4
Source File: IntellijFile.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Sets the content of the file. * * @param input an input stream to write into the file * @throws IOException if the file does not exist or could not be written to * @see IOUtils#copy(InputStream, OutputStream) */ private void setContentsInternal(@Nullable InputStream input) throws IOException { VirtualFile virtualFile = getVirtualFile(); if (!existsInternal(virtualFile)) { throw new FileNotFoundException( "Could not set contents of " + this + " as it does not exist or is not valid."); } try (InputStream in = input == null ? new ByteArrayInputStream(new byte[0]) : input; OutputStream out = virtualFile.getOutputStream(this)) { IOUtils.copy(in, out); } }
Example 5
Source File: VirtualFileImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException { if (myFileInfo != null) { VirtualFile localFile = myFileInfo.getLocalFile(); if (localFile != null) { return localFile.getOutputStream(requestor, newModificationStamp, newTimeStamp); } } throw new UnsupportedOperationException(); }
Example 6
Source File: TemplateUtils.java From CppTools with Apache License 2.0 | 5 votes |
public static void createOrResetFileContent(VirtualFile sourcePathDir, String fileName, StringBufferInputStream inputStream) throws IOException { VirtualFile child = sourcePathDir.findChild(fileName); if (child == null) child = sourcePathDir.createChildData(CppModuleBuilder.class, fileName); OutputStream outputStream = child.getOutputStream(CppModuleBuilder.class); FileUtil.copy(inputStream, outputStream); outputStream.flush(); outputStream.close(); }