List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out)
From source file:Test.java
public static void main(String[] args) throws Exception { SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory .getDefault();/* www . ja v a 2 s . com*/ SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket( "localhost", 9999); InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); OutputStream outputStream = sslSocket.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); BufferedWriter bufferedwriter = new BufferedWriter(outputStreamWriter); String line = null; while ((line = bufferedReader.readLine()) != null) { bufferedwriter.write(line + '\n'); bufferedwriter.flush(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC"); kpGen.initialize(1024, new SecureRandom()); KeyPair pair = kpGen.generateKeyPair(); PKCS10CertificationRequest request = generateRequest(pair); PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out)); pemWrt.writeObject(request);//from w w w. j ava2 s . co m pemWrt.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { KeyGenerator kg = KeyGenerator.getInstance("DES"); kg.init(new SecureRandom()); SecretKey key = kg.generateKey(); SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); Class spec = Class.forName("javax.crypto.spec.DESKeySpec"); DESKeySpec ks = (DESKeySpec) skf.getKeySpec(key, spec); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("keyfile")); oos.writeObject(ks.getKey());/*from www . j a v a 2s. c om*/ Cipher c = Cipher.getInstance("DES/CFB8/NoPadding"); c.init(Cipher.ENCRYPT_MODE, key); CipherOutputStream cos = new CipherOutputStream(new FileOutputStream("ciphertext"), c); PrintWriter pw = new PrintWriter(new OutputStreamWriter(cos)); pw.println("Stand and unfold yourself"); pw.close(); oos.writeObject(c.getIV()); oos.close(); }
From source file:lohbihler.process.Test.java
public static void main(final String[] args) throws Exception { final ExecutorService executorService = Executors.newCachedThreadPool(); final Process process = new ProcessBuilder("cmd").start(); final InputReader input = new InputReader(process.getInputStream()); final InputReader error = new InputReader(process.getErrorStream()); executorService.execute(input);/*www . ja v a 2s . c o m*/ executorService.execute(error); final OutputStreamWriter out = new OutputStreamWriter(process.getOutputStream()); Thread.sleep(1000); System.out.println("Input: " + input.getInput()); System.out.println("Error: " + error.getInput()); System.out.println("Alive: " + process.isAlive()); System.out.println(); out.append("PING 1.1.1.1 -n 1 -w 5000\r\n"); out.flush(); for (int i = 0; i < 7; i++) { Thread.sleep(1000); System.out.println("Input: " + input.getInput()); System.out.println("Error: " + error.getInput()); System.out.println("Alive: " + process.isAlive()); System.out.println(); } out.append("PING 1.1.1.1 -n 1 -w 2000\r\n"); out.flush(); for (int i = 0; i < 4; i++) { Thread.sleep(1000); System.out.println("Input: " + input.getInput()); System.out.println("Error: " + error.getInput()); System.out.println("Alive: " + process.isAlive()); System.out.println(); } process.destroy(); executorService.shutdown(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { InputSource in = new InputSource(new FileInputStream("y.xml")); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true);/*from ww w . j a va 2 s . c om*/ Document doc = dfactory.newDocumentBuilder().parse(in); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); CachedXPathAPI path = new CachedXPathAPI(); NodeIterator nl = path.selectNodeIterator(doc, "\\abc\\"); Node n; while ((n = nl.nextNode()) != null) transformer.transform(new DOMSource(n), new StreamResult(new OutputStreamWriter(System.out))); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("test.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document oldDoc = builder.parse(is); Node oldRoot = oldDoc.getDocumentElement(); Document newDoc = builder.newDocument(); Element newRoot = newDoc.createElement("newroot"); newDoc.appendChild(newRoot);//w w w.ja v a2 s .com newRoot.appendChild(newDoc.importNode(oldRoot, true)); ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(newDoc); Writer writer = new OutputStreamWriter(out); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); writer.flush(); InputStream isNewXML = new ByteArrayInputStream(out.toByteArray()); }
From source file:com.akana.demo.freemarker.templatetester.TestXML.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*/* w w w.j a v a2s. co m*/ * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsXml", freemarker.ext.dom.NodeModel.parse(new File("/Users/ian.goldsmith/projects/freemarker/test.xml"))); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testxml.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:com.akana.demo.freemarker.templatetester.TestJSON.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*// w w w .j ava 2s . co m * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsString", FileUtils.readFileToString( new File("/Users/ian.goldsmith/projects/freemarker/test.json"), StandardCharsets.UTF_8)); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testjson.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC"); kpGen.initialize(1024, new SecureRandom()); KeyPair pair = kpGen.generateKeyPair(); PKCS10CertificationRequest request = generateRequest(pair); PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out)); pemWrt.writeObject(request);/*ww w. j a v a2 s .com*/ pemWrt.close(); }
From source file:UseStylesheetParam.java
public static void main(String[] args) throws TransformerException, TransformerConfigurationException, SAXException, IOException { if (args.length != 1) { System.err.println("Please pass one string to this program"); return;/*from ww w .j a v a2 s. co m*/ } // Get the parameter value from the command line. String paramValue = args[0]; TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource("foo.xsl")); // Set the parameter. I can't get non-null namespaces to work!! transformer.setParameter("param1", /* parameter name */ paramValue /* parameter value */ ); transformer.transform(new StreamSource("foo.xml"), new StreamResult(new OutputStreamWriter(System.out))); }