List of usage examples for java.io FileWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:net.itransformers.idiscover.v2.core.listeners.node.GraphmlFileLogGroovyDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); File graphmlDir = new File(baseDir, graphmlDirName); if (!graphmlDir.exists()) graphmlDir.mkdir();// ww w . j a v a 2 s .c om String deviceName = discoveryResult.getNodeId(); if (deviceName == null) return; //This is a case of a subnetKind of a node or other nodes without nodeId. DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult .getDiscoveredData("deviceData"); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JaxbMarshalar.marshal(discoveredDeviceData, out, "DiscoveredDevice"); } catch (JAXBException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } StringReader reader = new StringReader(out.toString()); StringWriter graphmlWriter = new StringWriter(); transformRawDataToGraphml(reader, graphmlWriter); try { final String fileName = "node-" + deviceName + ".graphml"; // String fullFileName = path + File.separator + fileName; final File nodeFile = new File(graphmlDir, fileName); //System.out.println(new String(graphmlWriter.toString())); String graphml; graphml = new XmlFormatter().format(graphmlWriter.toString()); FileUtils.writeStringToFile(nodeFile, graphml); File undirectedGraphmls = new File(graphmlDir.getParent(), "undirected" + ".graphmls"); if (!undirectedGraphmls.exists()) { undirectedGraphmls.createNewFile(); } FileWriter writer = new FileWriter(undirectedGraphmls, true); writer.append(String.valueOf(fileName)).append("\n"); writer.close(); } catch (IOException e) { logger.debug("Unformated xml is not in correct format: \n" + graphmlWriter.toString()); e.printStackTrace(); } catch (ParserConfigurationException e) { logger.debug("Unformated xml is not in correct format: \n" + graphmlWriter.toString()); e.printStackTrace(); } catch (SAXException e) { logger.debug("Unformated xml is not in correct format: \n" + graphmlWriter.toString()); e.printStackTrace(); } }
From source file:org.sonar.server.startup.GeneratePluginIndex.java
void writeIndex(File indexFile) throws IOException { FileUtils.forceMkdir(indexFile.getParentFile()); FileWriter writer = new FileWriter(indexFile, false); try {/*from ww w .j a v a 2 s . c o m*/ for (PluginMetadata metadata : repository.getMetadata()) { if (!repository.isDisabled(metadata.getKey())) { writer.append(RemotePlugin.create((DefaultPluginMetadata) metadata).marshal()); writer.append(CharUtils.LF); } } writer.flush(); } finally { IOUtils.closeQuietly(writer); } }
From source file:org.silverpeas.core.admin.domain.repository.SQLInternalDomainRepositoryIT.java
private void populateFile(File tmpFile) throws IOException { FileWriter writer = new FileWriter(tmpFile); try {/*from ww w. jav a 2s . c om*/ writer.append("property.Number = 5\n"); writer.append( "property.ResourceFile = org.silverpeas.domains.multilang" + ".templateDomainSQLBundle\n"); writer.append("property_1.Name = title\n"); writer.append("property_1.Type = STRING\n"); writer.append("property_1.MapParameter = title\n"); writer.append("property_2.Name = company\n"); writer.append("property_2.Type = STRING\n"); writer.append("property_2.MapParameter = company\n"); writer.append("property_3.Name = position\n"); writer.append("property_3.Type = STRING\n"); writer.append("property_3.MapParameter = position\n"); writer.append("property_4.Name = boss\n"); writer.append("property_4.Type = USERID\n"); writer.append("property_4.MapParameter = boss\n"); writer.append("property_5.Name = test\n"); writer.append("property_5.Type = BOOLEAN\n"); writer.append("property_5.MapParameter = test\n"); } finally { IOUtils.closeQuietly(writer); } }
From source file:pt.ist.vaadinframework.annotation.EmbeddedAnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { final Set<String> actions = new HashSet<String>(); final File file = new File(LOG_FILENAME); if (file.exists()) { try {/* www. j a va 2 s .c o m*/ final String contents = FileUtils.readFileToString(file); for (final String line : contents.split(ENTRY_SEPERATOR)) { actions.add(line); } } catch (final IOException e) { e.printStackTrace(); } } final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(EmbeddedComponent.class); for (final Element element : elements) { if (element instanceof TypeElement) { final TypeElement typeElement = (TypeElement) element; actions.add(typeElement.getQualifiedName().toString()); } else { System.out.println("Skipping processing of element: " + element.getClass().getName() + ", this type was not expected!"); } } FileWriter fileWriter = null; try { fileWriter = new FileWriter(LOG_FILENAME, false); for (final String action : actions) { fileWriter.append(action); fileWriter.write(ENTRY_SEPERATOR); } } catch (final IOException e) { e.printStackTrace(); } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (final IOException e) { e.printStackTrace(); } } } return true; }
From source file:org.silverpeas.admin.domain.repository.SQLInternalDomainRepositoryTest.java
private void populateFile(File tmpFile) throws IOException { FileWriter writer = new FileWriter(tmpFile); try {// w w w.ja v a2 s . co m writer.append("property.Number = 4\n"); writer.append( "property.ResourceFile = com.stratelia.silverpeas.domains.multilang.templateDomainSQLBundle\n"); writer.append("property_1.Name = title\n"); writer.append("property_1.Type = STRING\n"); writer.append("property_1.MapParameter = title\n"); writer.append("property_2.Name = company\n"); writer.append("property_2.Type = STRING\n"); writer.append("property_2.MapParameter = company\n"); writer.append("property_3.Name = position\n"); writer.append("property_3.Type = STRING\n"); writer.append("property_3.MapParameter = position\n"); writer.append("property_4.Name = boss\n"); writer.append("property_4.Type = USERID\n"); writer.append("property_4.MapParameter = boss\n"); } finally { IOUtils.closeQuietly(writer); } }
From source file:net.grinder.engine.agent.LocalScriptTestDriveService.java
private void appendingMessageOn(File file, String msg) { FileWriter fileWriter = null; try {/*from w w w.j a v a2s. c om*/ fileWriter = new FileWriter(file, true); fileWriter.append("\n\n").append(msg); } catch (IOException e) { LOGGER.error("Error during appending validation messages", e); } finally { IOUtils.closeQuietly(fileWriter); } }
From source file:org.xwiki.mail.internal.factory.files.SerializedFilesMimeMessageIteratorTest.java
private void createSerializedMessage(String messageId) throws IOException { File messageFile = new File(this.batchDirectory, URLEncoder.encode(messageId, "UTF-8")); messageFile.createNewFile();//from w ww. j a va 2 s. c o m String newLine = System.getProperty("line.separator"); FileWriter fileWriter = new FileWriter(messageFile, true); // Unique string is <hashcode>.<id>.<currentTime>.JavaMail.<suffix> fileWriter.append("Message-ID: " + messageId + newLine); fileWriter.append("MIME-Version: 1.0" + newLine); fileWriter.append("Content-Type: text/plain; charset=us-ascii" + newLine); fileWriter.append("Content-Transfer-Encoding: 7bit" + newLine); fileWriter.append("Lorem ipsum dolor sit amet, consectetur adipiscing elit"); fileWriter.close(); }
From source file:org.fcrepo.importexport.integration.ExecutableJarIT.java
@Test public void testConfigFileExport() throws Exception { // Create a repository resource final FcrepoResponse response = create(url); assertEquals(SC_CREATED, response.getStatusCode()); assertEquals(url, response.getLocation()); // Create test config file final File configFile = File.createTempFile("config-test", ".txt"); final FileWriter writer = new FileWriter(configFile); writer.append("-d\n"); writer.append(TARGET_DIR);/* w ww . j av a2s . c om*/ writer.append("\n"); writer.append("-m\n"); writer.append("export\n"); writer.append("-r\n"); writer.append(url.toString()); writer.append("\n"); writer.flush(); // Run an export process final Process process = startJarProcess("-c", configFile.getAbsolutePath(), "-u", "fedoraAdmin:password"); // Verify assertTrue("Process did not exit before timeout!", process.waitFor(TIMEOUT_SECONDS, TimeUnit.SECONDS)); assertEquals("Did not exit with success status!", 0, process.exitValue()); assertTrue(new File(TARGET_DIR, TransferProcess.encodePath(url.getPath() + ArgParser.DEFAULT_RDF_EXT)) .exists()); assertTrue(new File(System.getProperty("java.io.tmpdir"), ArgParser.CONFIG_FILE_NAME).exists()); }
From source file:net.itransformers.idiscover.v2.core.listeners.Neo4JGraphmlLoggerLogDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); File xsltFile = new File(xsltFileName); File graphmlDir = new File(baseDir, graphmDirName); GraphDatabaseService graphdb = new org.neo4j.rest.graphdb.RestGraphDatabase(graphDbUrl); if (!graphmlDir.exists()) graphmlDir.mkdir();/*from w w w . j ava2 s . c o m*/ String deviceName = discoveryResult.getNodeId(); DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult .getDiscoveredData(dataType); ByteArrayOutputStream graphMLOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JaxbMarshalar.marshal(discoveredDeviceData, out, "DiscoveredDevice"); } catch (JAXBException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } XsltTransformer transformer = new XsltTransformer(); try { transformer.transformXML(new ByteArrayInputStream(out.toByteArray()), xsltFile, graphMLOutputStream, null, null); } catch (Exception e) { logger.error(e.getMessage(), e); } final String fileName = "node-" + deviceName + ".graphml"; final File nodeFile = new File(graphmlDir, fileName); String unformatedGraphml = new String(graphMLOutputStream.toByteArray()); try { String graphml = new XmlFormatter().format(unformatedGraphml); FileUtils.writeStringToFile(nodeFile, graphml); FileWriter writer = new FileWriter(new File(labelDirName, "undirected" + ".graphmls"), true); writer.append(String.valueOf(fileName)).append("\n"); writer.close(); } catch (IOException e) { logger.debug("Unformated xml is not in correct format: \n" + unformatedGraphml); e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } Neo4jGraphmlMerger neo4jMerger = new Neo4jGraphmlMerger(graphdb, "v1"); Transaction tx = graphdb.beginTx(); try { tx = graphdb.beginTx(); neo4jMerger.merge(nodeFile); tx.success(); } catch (Exception e) { if (tx != null) tx.failure(); } finally { if (tx != null) tx.finish(); } }
From source file:net.itransformers.idiscover.v2.core.listeners.node.Neo4JGraphmlLoggerLogDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); File xsltFile = new File(xsltFileName); File graphmlDir = new File(baseDir, graphmlDirName); GraphDatabaseService graphdb = new org.neo4j.rest.graphdb.RestGraphDatabase(graphDbUrl); if (!graphmlDir.exists()) graphmlDir.mkdir();/* ww w.j a v a 2 s .co m*/ String deviceName = discoveryResult.getNodeId(); DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult .getDiscoveredData(dataType); ByteArrayOutputStream graphMLOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JaxbMarshalar.marshal(discoveredDeviceData, out, "DiscoveredDevice"); } catch (JAXBException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } XsltTransformer transformer = new XsltTransformer(); try { transformer.transformXML(new ByteArrayInputStream(out.toByteArray()), xsltFile, graphMLOutputStream); } catch (Exception e) { logger.error(e.getMessage(), e); } final String fileName = "node-" + deviceName + ".graphml"; final File nodeFile = new File(graphmlDir, fileName); String unformatedGraphml = new String(graphMLOutputStream.toByteArray()); try { String graphml = new XmlFormatter().format(unformatedGraphml); FileUtils.writeStringToFile(nodeFile, graphml); FileWriter writer = new FileWriter(new File(labelDirName, "undirected" + ".graphmls"), true); writer.append(String.valueOf(fileName)).append("\n"); writer.close(); } catch (IOException e) { logger.debug("Unformated xml is not in correct format: \n" + unformatedGraphml); e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } Neo4jGraphmlMerger neo4jMerger = new Neo4jGraphmlMerger(graphdb, "v1"); Transaction tx = graphdb.beginTx(); try { tx = graphdb.beginTx(); neo4jMerger.merge(nodeFile); tx.success(); } catch (Exception e) { if (tx != null) tx.failure(); } finally { if (tx != null) tx.finish(); } }