List of usage examples for java.io InputStreamReader InputStreamReader
public InputStreamReader(InputStream in)
From source file:cn.lynx.emi.license.GenerateLicense.java
public static void main(String[] args) throws ClassNotFoundException, ParseException { if (args == null || args.length != 4) { System.err.println("Please provide [machine code] [cpu] [memory in gb] [yyyy-MM-dd] as parameter"); return;//from w ww . ja v a2s .co m } InputStream is = GenerateLicense.class.getResourceAsStream("/privatekey"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String key = null; try { key = br.readLine(); } catch (IOException e) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); e.printStackTrace(); return; } if (key == null) { System.err.println( "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath"); return; } String machineCode = args[0]; int cpu = Integer.parseInt(args[1]); long mem = Long.parseLong(args[2]) * 1024 * 1024 * 1024; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); long expDate = sdf.parse(args[3]).getTime(); LicenseBean lb = new LicenseBean(); lb.setCpuCount(cpu); lb.setMemCount(mem); lb.setMachineCode(machineCode); lb.setExpireDate(expDate); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(baos); os.writeObject(lb); os.close(); String serializedLicense = Base64.encodeBase64String(baos.toByteArray()); System.out.println("License:" + encrypt(key, serializedLicense)); } catch (IOException e) { e.printStackTrace(); } }
From source file:FlightInfo.java
public static void main(String args[]) { String to, from;/*from www. j a va 2 s . c o m*/ Hill ob = new Hill(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ob.setup(); try { System.out.print("From? "); from = br.readLine(); System.out.print("To? "); to = br.readLine(); ob.isflight(from, to); if (ob.btStack.size() != 0) ob.route(to); } catch (IOException exc) { System.out.println("Error on input."); } }
From source file:de.britter.beyondstringutils.CsvExample.java
public static void main(String[] args) throws Exception { InputStream is = CsvExample.class.getResourceAsStream("heros.csv"); Iterable<CSVRecord> records = CSVFormat.DEFAULT.withHeader("First Name", "Last Name").withSkipHeaderRecord() .parse(new InputStreamReader(is)); for (CSVRecord record : records) { String firstName = record.get("First Name"); String lastName = record.get("Last Name"); System.out.println(String.format("First Name: %s; Last Name: %s", firstName, lastName)); }//w w w . j av a 2s . c o m }
From source file:ElementIteratorExample.java
public static void main(String args[]) throws Exception { if (args.length != 1) { System.err.println("Usage: java ElementIteratorExample input-URL"); }/*from ww w. j a va 2 s.c o m*/ // Load HTML file synchronously URL url = new URL(args[0]); URLConnection connection = url.openConnection(); InputStream is = connection.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); HTMLEditorKit.Parser parser = new ParserDelegator(); HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0); parser.parse(br, callback, true); // Parse ElementIterator iterator = new ElementIterator(htmlDoc); Element element; while ((element = iterator.next()) != null) { AttributeSet attributes = element.getAttributes(); Object name = attributes.getAttribute(StyleConstants.NameAttribute); if ((name instanceof HTML.Tag) && ((name == HTML.Tag.H1) || (name == HTML.Tag.H2) || (name == HTML.Tag.H3))) { // Build up content text as it may be within multiple elements StringBuffer text = new StringBuffer(); int count = element.getElementCount(); for (int i = 0; i < count; i++) { Element child = element.getElement(i); AttributeSet childAttributes = child.getAttributes(); if (childAttributes.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.CONTENT) { int startOffset = child.getStartOffset(); int endOffset = child.getEndOffset(); int length = endOffset - startOffset; text.append(htmlDoc.getText(startOffset, length)); } } System.out.println(name + ": " + text.toString()); } } System.exit(0); }
From source file:FlightInfo.java
public static void main(String args[]) { String to, from;/*from www.j av a 2 s . c o m*/ Depth ob = new Depth(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ob.setup(); try { System.out.print("From? "); from = br.readLine(); System.out.print("To? "); to = br.readLine(); ob.isflight(from, to); if (ob.btStack.size() != 0) ob.route(to); } catch (IOException exc) { System.out.println("Error on input."); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(443); ss.setNeedClientAuth(true);/*from w ww . j a v a 2 s.c om*/ while (true) { Socket s = ss.accept(); SSLSession session = ((SSLSocket) s).getSession(); Certificate[] cchain = session.getPeerCertificates(); for (int j = 0; j < cchain.length; j++) { System.out.println(((X509Certificate) cchain[j]).getSubjectDN()); } PrintStream out = new PrintStream(s.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String info = null; while ((info = in.readLine()) != null) { System.out.println("now got " + info); if (info.equals("")) break; } out.println("HTTP/1.0 200 OK\nMIME_version:1.0"); out.println("Content_Type:text/html"); String c = "<html> <head></head><body> <h1> Hi,</h1></Body></html>"; out.println("Content_Length:" + c.length()); out.println(""); out.println(c); out.close(); s.close(); in.close(); } }
From source file:Main.java
public static void main(String[] arg) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); while (true) { String sLine = bf.readLine(); System.out.println("::" + sLine); }//from ww w . j a v a2 s . c o m }
From source file:WebClient.java
public static void main(String[] args) throws Exception { CookieStore store = new MyCookieStore(); CookiePolicy policy = new MyCookiePolicy(); CookieManager handler = new CookieManager(store, policy); CookieHandler.setDefault(handler); URL url = new URL("http://localhost:8080/cookieTest.jsp"); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String input;//from w ww . j a va2 s .c o m while ((input = reader.readLine()) != null) { System.out.println(input); } reader.close(); }
From source file:base64.EncodeBase64.java
public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter string to encode (input is not escaped):"); String originalString = reader.readLine(); String encodedBase64String = Base64.encodeBase64String(originalString.getBytes()); System.out.println("Your encoded Base64 string :"); System.out.println(encodedBase64String); }
From source file:FlightInfo.java
public static void main(String args[]) { String to, from;//from w w w.j av a 2 s .c o m Optimal ob = new Optimal(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); boolean done = false; FlightInfo f; ob.setup(); try { System.out.print("From? "); from = br.readLine(); System.out.print("To? "); to = br.readLine(); do { ob.isflight(from, to); if (ob.btStack.size() == 0) done = true; else { ob.route(to); ob.btStack = new Stack(); } } while (!done); // Display optimal solution. if (ob.optimal != null) { System.out.println("Optimal solution is: "); int num = ob.optimal.size(); for (int i = 0; i < num; i++) { f = (FlightInfo) ob.optimal.pop(); System.out.print(f.from + " to "); } System.out.println(to); System.out.println("Distance is " + ob.minDist); } } catch (IOException exc) { System.out.println("Error on input."); } }