List of usage examples for java.io FileWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:org.duracloud.services.duplication.result.DuplicationResultListener.java
private void write(File file, String text) { boolean append = true; FileWriter writer; try {// w w w .j ava 2s .co m writer = new FileWriter(file, append); writer.append(text); writer.append(newline); writer.close(); } catch (IOException e) { StringBuilder sb = new StringBuilder("Error writing event: '"); sb.append(text); sb.append("' to file: "); sb.append(file.getAbsolutePath()); sb.append(", exception: "); sb.append(e.getMessage()); log.error(sb.toString()); } }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest.java
@Test public void testDefaultConfig() throws Exception { Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); File conf = folder1.newFile("accumulo-site.xml"); FileWriter out = new FileWriter(conf); out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.append("<configuration>\n"); out.append("<property>\n"); out.append("<name>general.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("<property>\n"); out.append("<name>general.vfs.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("</configuration>\n"); out.close();/*from ww w. j a v a 2 s . c o m*/ Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object()); ClassLoader acl = AccumuloVFSClassLoader.getClassLoader(); Assert.assertTrue((acl instanceof VFSClassLoader)); Assert.assertTrue((acl.getParent() instanceof URLClassLoader)); }
From source file:gov.nih.nci.caintegrator.domain.application.AbstractPersistedAnalysisJob.java
/** * Writes the job description to the given file. * @param file to write to.// w w w. j a v a 2s . co m * @throws IOException if unable to write to file. */ public void writeJobDescriptionToFile(File file) throws IOException { FileWriter fw = new FileWriter(file); fw.append(toString()); fw.flush(); fw.close(); }
From source file:net.itransformers.idiscover.v2.core.listeners.node.GraphmlFileLogDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); File xsltFile = new File(projectPath, xsltFileName); File graphmlDir = new File(baseDir, graphmlDirName); if (!graphmlDir.exists()) graphmlDir.mkdir();//www . j a va2 s .c o m 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 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); } catch (Exception e) { logger.error(e.getMessage(), e); } 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(graphMLOutputStream.toByteArray())); String graphml = new XmlFormatter().format(new String(graphMLOutputStream.toByteArray())); 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) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest.java
@Test public void testCacheDirectoryConfigured() throws Exception { Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); String cacheDir = "/some/random/cache/dir"; File conf = folder1.newFile("accumulo-site.xml"); FileWriter out = new FileWriter(conf); out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.append("<configuration>\n"); out.append("<property>\n"); out.append("<name>general.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("<property>\n"); out.append("<name>" + AccumuloVFSClassLoader.VFS_CACHE_DIR + "</name>\n"); out.append("<value>" + cacheDir + "</value>\n"); out.append("</property>\n"); out.append("</configuration>\n"); out.close();//from w w w . ja va2 s.c om Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object()); AccumuloVFSClassLoader.getClassLoader(); FileSystemManager manager = AccumuloVFSClassLoader.generateVfs(); UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator"); File tempDir = Whitebox.getInternalState(replicator, "tempDir"); String tempDirParent = tempDir.getParent(); String tempDirName = tempDir.getName(); Assert.assertTrue(cacheDir.equals(tempDirParent)); Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-")); Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser"))); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest.java
@Test public void testDefaultContextConfigured() throws Exception { Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); // Copy jar file to TEST_DIR FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar")); File conf = folder1.newFile("accumulo-site.xml"); FileWriter out = new FileWriter(conf); out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.append("<configuration>\n"); out.append("<property>\n"); out.append("<name>general.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("<property>\n"); out.append("<name>general.vfs.classpaths</name>\n"); out.append("<value>" + new File(folder1.getRoot(), "HelloWorld.jar").toURI() + "</value>\n"); out.append("</property>\n"); out.append("</configuration>\n"); out.close();/*from ww w. j av a2 s.c o m*/ Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object()); ClassLoader acl = AccumuloVFSClassLoader.getClassLoader(); Assert.assertTrue((acl instanceof VFSClassLoader)); Assert.assertTrue((acl.getParent() instanceof VFSClassLoader)); VFSClassLoader arvcl = (VFSClassLoader) acl.getParent(); Assert.assertEquals(1, arvcl.getFileObjects().length); // We can't be sure what the authority/host will be due to FQDN mappings, so just check the path Assert.assertTrue(arvcl.getFileObjects()[0].getURL().toString().contains("HelloWorld.jar")); Class<?> clazz1 = arvcl.loadClass("test.HelloWorld"); Object o1 = clazz1.newInstance(); Assert.assertEquals("Hello World!", o1.toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest.java
@Test public void testDefaultCacheDirectory() throws Exception { Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); File conf = folder1.newFile("accumulo-site.xml"); FileWriter out = new FileWriter(conf); out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.append("<configuration>\n"); out.append("<property>\n"); out.append("<name>general.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("<property>\n"); out.append("<name>general.vfs.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("</configuration>\n"); out.close();/* w ww . j a v a 2 s.c o m*/ Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object()); AccumuloVFSClassLoader.getClassLoader(); FileSystemManager manager = AccumuloVFSClassLoader.generateVfs(); UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator"); File tempDir = Whitebox.getInternalState(replicator, "tempDir"); String tempDirParent = tempDir.getParent(); String tempDirName = tempDir.getName(); String javaIoTmpDir = System.getProperty("java.io.tmpdir"); // trim off any final separator, because java.io.File does the same. if (javaIoTmpDir.endsWith(File.separator)) { javaIoTmpDir = javaIoTmpDir.substring(0, javaIoTmpDir.length() - File.separator.length()); } Assert.assertTrue(javaIoTmpDir.equals(tempDirParent)); Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-")); Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser"))); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); }
From source file:com.gnizr.web.action.export.ExportNetscapeBookmarks.java
private void writePostBody(FileWriter fwriter) throws IOException { fwriter.append("</DL><p>"); }
From source file:net.thucydides.maven.plugin.GenerateThucydidesJUnitStoriesMojo.java
private void createJavaClass(String name, String text) throws IOException { File pd = new File(outputDirectory, packageForStoryStubs.replaceAll("\\.", "/")); pd.mkdirs();/* w ww. j ava 2 s .com*/ FileWriter out = new FileWriter(new File(pd, name + "IT" + ".java")); try { out.append(text); } finally { out.flush(); out.close(); } }
From source file:com.gnizr.web.action.export.ExportNetscapeBookmarks.java
private void writePreBody(FileWriter fwriter) throws IOException { fwriter.append("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"); fwriter.append("<!-- This is an automatically generated file. DO NOT EDIT! -->\n"); fwriter.append("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n"); fwriter.append("<TITLE>Bookmarks saved by "); fwriter.append(getLoggedInUser().getUsername()); fwriter.append("</TITLE>\n"); fwriter.append("<H1>Bookmarks saved by "); fwriter.append(getLoggedInUser().getUsername()); fwriter.append("</H1>\n"); fwriter.append("<DL><p>\n"); }