List of usage examples for java.io StringWriter flush
public void flush()
From source file:io.reactiverse.vertx.maven.plugin.SetupMojoTest.java
@Test public void testAddVertxMavenPlugin() throws Exception { InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-pom.xml"); assertNotNull(pomFile);// www . j a va 2 s.c om MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(pomFile); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertFalse(vmPlugin.isPresent()); Plugin vertxMavenPlugin = plugin("io.reactiverse", "vertx-maven-plugin", MojoUtils.getVersion("vertx-maven-plugin-version")); PluginExecution pluginExec = new PluginExecution(); pluginExec.addGoal("initialize"); pluginExec.addGoal("package"); pluginExec.setId("vmp-init-package"); vertxMavenPlugin.addExecution(pluginExec); vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true"))); model.getBuild().getPlugins().add(vertxMavenPlugin); model.getProperties().putIfAbsent("vertx.version", MojoUtils.getVersion("vertx-core-version")); Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}"); vertxBom.setType("pom"); vertxBom.setScope("import"); addDependencies(model, vertxBom); MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); StringWriter updatedPom = new StringWriter(); xpp3Writer.write(updatedPom, model); updatedPom.flush(); updatedPom.close(); //System.out.println(updatedPom); //Check if it has been added model = xpp3Reader.read(new StringReader(updatedPom.toString())); project = new MavenProject(model); vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
From source file:org.dia.kafka.isatools.producer.ISAToolsKafkaProducer.java
/** * Performs the parsing request to Tika/*from ww w. j a v a 2 s . co m*/ * * @param files * @return */ public static List<JSONObject> doTikaRequest(List<String> files) { List<JSONObject> jsonObjs = new ArrayList<JSONObject>(); try { Parser parser = new ISArchiveParser(); StringWriter strWriter = new StringWriter(); for (String file : files) { JSONObject jsonObject = new JSONObject(); // get metadata from tika InputStream stream = TikaInputStream.get(new File(file)); ContentHandler handler = new ToHTMLContentHandler(); Metadata metadata = new Metadata(); ParseContext context = new ParseContext(); parser.parse(stream, handler, metadata, context); // get json object jsonObject.put(SOURCE_TAG, ISATOOLS_SOURCE_VAL); JsonMetadata.toJson(metadata, strWriter); jsonObject = adjustUnifiedSchema((JSONObject) jsonParser.parse(new String(strWriter.toString()))); //TODO Tika parsed content is not used needed for now //jsonObject.put(X_TIKA_CONTENT, handler.toString()); System.out.format("[%s] Tika message: %s \n", ISAToolsKafkaProducer.class.getSimpleName(), jsonObject.toJSONString()); jsonObjs.add(jsonObject); strWriter.getBuffer().setLength(0); } strWriter.flush(); strWriter.close(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (TikaException e) { e.printStackTrace(); } return jsonObjs; }
From source file:io.fabric8.vertx.maven.plugin.SetupMojoTest.java
@Test public void testAddVertxMavenPluginWithNoBuildPom() throws Exception { InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-nobuild-pom.xml"); assertNotNull(pomFile);/* w ww . j a va2 s . c o m*/ MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(pomFile); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin"); assertFalse(vmPlugin.isPresent()); Plugin vertxMavenPlugin = plugin("io.fabric8", "vertx-maven-plugin", MojoUtils.getVersion("vertx-maven-plugin-version")); PluginExecution pluginExec = new PluginExecution(); pluginExec.addGoal("initialize"); pluginExec.addGoal("package"); pluginExec.setId("vmp-init-package"); vertxMavenPlugin.addExecution(pluginExec); vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true"))); Build build = new Build(); model.setBuild(build); build.getPlugins().add(vertxMavenPlugin); model.getProperties().putIfAbsent("vertx.version", MojoUtils.getVersion("vertx-core-version")); Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}"); vertxBom.setType("pom"); vertxBom.setScope("import"); addDependencies(model, vertxBom); MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); StringWriter updatedPom = new StringWriter(); xpp3Writer.write(updatedPom, model); updatedPom.flush(); updatedPom.close(); //System.out.println(updatedPom); //Check if it has been added model = xpp3Reader.read(new StringReader(updatedPom.toString())); project = new MavenProject(model); vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.fabric8:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
From source file:io.reactiverse.vertx.maven.plugin.SetupMojoTest.java
@Test public void testAddVertxMavenPluginWithNoBuildPom() throws Exception { InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-nobuild-pom.xml"); assertNotNull(pomFile);// w ww. j a va2 s.c o m MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(pomFile); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertFalse(vmPlugin.isPresent()); Plugin vertxMavenPlugin = plugin("io.reactiverse", "vertx-maven-plugin", MojoUtils.getVersion("vertx-maven-plugin-version")); PluginExecution pluginExec = new PluginExecution(); pluginExec.addGoal("initialize"); pluginExec.addGoal("package"); pluginExec.setId("vmp-init-package"); vertxMavenPlugin.addExecution(pluginExec); vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true"))); Build build = new Build(); model.setBuild(build); build.getPlugins().add(vertxMavenPlugin); model.getProperties().putIfAbsent("vertx.version", MojoUtils.getVersion("vertx-core-version")); Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}"); vertxBom.setType("pom"); vertxBom.setScope("import"); addDependencies(model, vertxBom); MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); StringWriter updatedPom = new StringWriter(); xpp3Writer.write(updatedPom, model); updatedPom.flush(); updatedPom.close(); //System.out.println(updatedPom); //Check if it has been added model = xpp3Reader.read(new StringReader(updatedPom.toString())); project = new MavenProject(model); vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
From source file:io.fabric8.vertx.maven.plugin.SetupMojoTest.java
@Test public void testAddVertxMavenPluginWithVertxVersion() throws Exception { System.setProperty("vertxVersion", "3.4.0"); InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-pom.xml"); assertNotNull(pomFile);//from ww w .jav a 2 s . c om MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(pomFile); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin"); assertFalse(vmPlugin.isPresent()); Plugin vertxMavenPlugin = plugin("io.fabric8", "vertx-maven-plugin", MojoUtils.getVersion("vertx-maven-plugin-version")); PluginExecution pluginExec = new PluginExecution(); pluginExec.addGoal("initialize"); pluginExec.addGoal("package"); pluginExec.setId("vmp-init-package"); vertxMavenPlugin.addExecution(pluginExec); vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true"))); model.getBuild().getPlugins().add(vertxMavenPlugin); String vertxVersion = System.getProperty("vertxVersion") == null ? MojoUtils.getVersion("vertx-core-version") : System.getProperty("vertxVersion"); model.getProperties().putIfAbsent("vertx.version", vertxVersion); Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}"); vertxBom.setType("pom"); vertxBom.setScope("import"); addDependencies(model, vertxBom); MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); StringWriter updatedPom = new StringWriter(); xpp3Writer.write(updatedPom, model); updatedPom.flush(); updatedPom.close(); //System.out.println(updatedPom); //Check if it has been added model = xpp3Reader.read(new StringReader(updatedPom.toString())); project = new MavenProject(model); vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.fabric8:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); Properties projectProps = project.getProperties(); assertNotNull(projectProps); assertFalse(projectProps.isEmpty()); assertEquals(projectProps.getProperty("vertx.version"), vertxVersion); }
From source file:io.reactiverse.vertx.maven.plugin.SetupMojoTest.java
@Test public void testAddVertxMavenPluginWithVertxVersion() throws Exception { System.setProperty("vertxVersion", "3.4.0"); InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-pom.xml"); assertNotNull(pomFile);/*from w ww.ja v a 2 s. c o m*/ MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(pomFile); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertFalse(vmPlugin.isPresent()); Plugin vertxMavenPlugin = plugin("io.reactiverse", "vertx-maven-plugin", MojoUtils.getVersion("vertx-maven-plugin-version")); PluginExecution pluginExec = new PluginExecution(); pluginExec.addGoal("initialize"); pluginExec.addGoal("package"); pluginExec.setId("vmp-init-package"); vertxMavenPlugin.addExecution(pluginExec); vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true"))); model.getBuild().getPlugins().add(vertxMavenPlugin); String vertxVersion = System.getProperty("vertxVersion") == null ? MojoUtils.getVersion("vertx-core-version") : System.getProperty("vertxVersion"); model.getProperties().putIfAbsent("vertx.version", vertxVersion); Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}"); vertxBom.setType("pom"); vertxBom.setScope("import"); addDependencies(model, vertxBom); MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); StringWriter updatedPom = new StringWriter(); xpp3Writer.write(updatedPom, model); updatedPom.flush(); updatedPom.close(); //System.out.println(updatedPom); //Check if it has been added model = xpp3Reader.read(new StringReader(updatedPom.toString())); project = new MavenProject(model); vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); Properties projectProps = project.getProperties(); assertNotNull(projectProps); assertFalse(projectProps.isEmpty()); assertEquals(projectProps.getProperty("vertx.version"), vertxVersion); }
From source file:org.openremote.controller.protocol.samsungtv.SamsungTVSession.java
private String getRegistrationPayload(String ip) throws IOException { StringWriter writer = new StringWriter(); writer.append((char) 0x64); writer.append((char) 0x00); writeBase64Text(writer, ip);/*from w w w.j a v a 2 s . c o m*/ writeBase64Text(writer, ip); writeBase64Text(writer, applicationName); writer.flush(); return writer.toString(); }
From source file:de.quist.samy.remocon.RemoteSession.java
private String getKeyPayload(Key key) throws IOException { StringWriter writer = new StringWriter(); writer.append((char) 0x00); writer.append((char) 0x00); writer.append((char) 0x00); writeBase64Text(writer, key.getValue()); writer.flush(); return writer.toString(); }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Convert a DOM node to a stringified XML representation. *//*w w w . j a v a 2s. co m*/ static public String domToStringLevel2(Node node) { if (node == null) { throw new IllegalArgumentException("Cannot stringify null Node!"); } String value = null; short nodeType = node.getNodeType(); if (nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE) { // serializer doesn't handle Node type well, only Element DOMSerializerImpl ser = new DOMSerializerImpl(); ser.setParameter(Constants.DOM_NAMESPACES, Boolean.TRUE); ser.setParameter(Constants.DOM_WELLFORMED, Boolean.FALSE); ser.setParameter(Constants.DOM_VALIDATE, Boolean.FALSE); // the receiver of the DOM DOMOutputImpl out = new DOMOutputImpl(); out.setEncoding("UTF-8"); // we write into a String StringWriter writer = new StringWriter(4096); out.setCharacterStream(writer); // out, ye characters! ser.write(node, out); writer.flush(); // finally get the String value = writer.toString(); } else { value = node.getNodeValue(); } return value; }
From source file:org.duracloud.snapshottask.snapshot.CreateSnapshotTaskRunner.java
/** * Constructs the contents of a properties file given a set of * key/value pairs/*from w w w .jav a 2s. c om*/ * * @param props snapshot properties * @return Properties-file formatted key/value pairs */ protected String buildSnapshotProps(Map<String, String> props) { Properties snapshotProperties = new Properties(); for (String key : props.keySet()) { snapshotProperties.setProperty(key, props.get(key)); } StringWriter writer = new StringWriter(); try { snapshotProperties.store(writer, null); } catch (IOException e) { throw new TaskException("Could not write snapshot properties: " + e.getMessage(), e); } writer.flush(); return writer.toString(); }