List of usage examples for java.io BufferedReader readLine
public String readLine() throws IOException
From source file:com.cliqset.magicsig.util.KeyTester.java
public static void main(String[] args) { try {//from w w w. j av a2 s. c o m FileInputStream fis = new FileInputStream(keyFile); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); String line = null; while ((line = reader.readLine()) != null) { MagicKey key = new MagicKey(line.getBytes("ASCII")); RSASHA256MagicSigAlgorithm alg = new RSASHA256MagicSigAlgorithm(); byte[] sig = alg.sign(data, key); System.out.println(Base64.encodeBase64URLSafeString(sig)); boolean verified = alg.verify(data, sig, key); if (!verified) { System.out.println("FAILED - " + line); } //System.out.println(lineSplit[0] + " " + key.toString(true)); } } catch (Exception e) { e.printStackTrace(); } System.out.println("Done."); }
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 w w. java 2 s.c o m*/ 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:org.fusesource.cloudmix.tests.consumer.Main.java
public static void main(String[] args) { if (args.length > 0 && args[0].equals("-debug")) { Map<Object, Object> properties = new TreeMap<Object, Object>(); properties.putAll(System.getProperties()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { System.out.println(" " + entry.getKey() + " = " + entry.getValue()); }/* w w w. ja v a 2s.c om*/ } ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "META-INF/spring/context.xml"); applicationContext.start(); System.out.println("Enter quit to stop"); try { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (true) { String line = reader.readLine(); if (line == null || line.trim().equalsIgnoreCase("quit")) { break; } } } catch (IOException e) { System.err.println("Caught: " + e); e.printStackTrace(System.err); } applicationContext.close(); }
From source file:Main.java
public static void main(String[] args) { try {// w w w . ja va 2 s . c o m BufferedReader input = new BufferedReader(new FileReader(args[0])); ArrayList list = new ArrayList(); String line; while ((line = input.readLine()) != null) { list.add(line); } input.close(); Collections.reverse(list); PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); for (Iterator i = list.iterator(); i.hasNext();) { output.println((String) i.next()); } output.close(); } catch (IOException e) { System.err.println(e); } }
From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java
public static void main(String[] args) { try {/*from w w w. j a v a 2s .c o m*/ final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); final String name = in.readLine(); final List<RecordEntry> entries = new LinkedList<RecordEntry>(); String line; while ((line = in.readLine()) != null) { final String[] parts = line.split("\\s+"); final int length = Integer.parseInt(parts[0]); final int start = Integer.parseInt(parts[1]); final String entryName = parts[2]; entries.add(new RecordEntry(length, start, entryName)); } (new RecordClassMaker(name, entries)).execute(); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }
From source file:org.fusesource.cloudmix.tests.broker.Main.java
public static void main(String[] args) { if (verbose || (args.length > 0 && args[0].equals("-debug"))) { Map<Object, Object> properties = new TreeMap<Object, Object>(); properties.putAll(System.getProperties()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { System.out.println(" " + entry.getKey() + " = " + entry.getValue()); }/*from w ww .j a va2s. c o m*/ } ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "META-INF/spring/activemq.xml"); applicationContext.start(); System.out.println("Enter quit to stop"); try { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (true) { String line = reader.readLine(); if (line == null || line.trim().equalsIgnoreCase("quit")) { break; } } } catch (IOException e) { System.err.println("Caught: " + e); e.printStackTrace(System.err); } applicationContext.close(); }
From source file:httpclientsample.HttpClientSample.java
/** * @param args the command line arguments */// w ww.j av a 2 s.c o m public static void main(String[] args) throws IOException, JSONException { /** METHOD GET EXAMPLE **/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet("http://localhost:8000/test/api?id=100"); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } InputStreamReader isr = new InputStreamReader((response.getEntity().getContent())); BufferedReader br = new BufferedReader(isr); String output; System.out.println("Response:\n"); while ((output = br.readLine()) != null) { JSONObject jsonObj = new JSONObject(output); System.out.println("json id : " + jsonObj.get("id")); } httpClient.getConnectionManager().shutdown(); }
From source file:MainClass.java
public static void main(String args[]) { try {/*from www . j ava 2 s . c o m*/ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); while (true) { System.out.print("Radius? "); String str = br.readLine(); double radius; try { radius = Double.valueOf(str).doubleValue(); } catch (NumberFormatException nfe) { System.out.println("Incorrect format!"); continue; } if (radius <= 0) { System.out.println("Radius must be positive!"); continue; } double area = Math.PI * radius * radius; System.out.println("Area is " + area); return; } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.manning.blogapps.chapter10.examples.AuthPostJava.java
public static void main(String[] args) throws Exception { if (args.length < 4) { System.out.println("USAGE: authpost <username> <password> <filepath> <url>"); System.exit(-1);// www . ja v a 2s . c o m } String credentials = args[0] + ":" + args[1]; String filepath = args[2]; URL url = new URL(args[3]); URLConnection conn = url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(credentials.getBytes()))); File upload = new File(filepath); conn.setRequestProperty("name", upload.getName()); String contentType = "application/atom+xml; charset=utf8"; if (filepath.endsWith(".gif")) contentType = "image/gif"; else if (filepath.endsWith(".jpg")) contentType = "image/jpg"; conn.setRequestProperty("Content-type", contentType); BufferedInputStream filein = new BufferedInputStream(new FileInputStream(upload)); BufferedOutputStream out = new BufferedOutputStream(conn.getOutputStream()); byte buffer[] = new byte[8192]; for (int count = 0; count != -1;) { count = filein.read(buffer, 0, 8192); if (count != -1) out.write(buffer, 0, count); } filein.close(); out.close(); String s = null; BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((s = in.readLine()) != null) { System.out.println(s); } }
From source file:com.navercorp.client.Main.java
public static void main(String[] args) { Client clnt = null;/*from w w w . ja v a2 s. c om*/ try { CommandLine cmd = new DefaultParser() .parse(new Options().addOption("z", true, "zookeeper address (ip:port,ip:port,...)") .addOption("t", true, "zookeeper connection timeout") .addOption("c", true, "command and arguments"), args); final String connectionString = cmd.hasOption("z") ? cmd.getOptionValue("z") : "127.0.0.1:2181"; final int timeout = cmd.hasOption("t") ? Integer.valueOf(cmd.getOptionValue("t")) : 10000; clnt = new Client(connectionString, timeout); String command; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while ((command = in.readLine()) != null) { printResult(clnt.execute(command.split(" "))); } System.exit(Code.OK.n()); } catch (ParseException e) { e.printStackTrace(System.err); System.err.println(Client.getUsage()); System.exit(INVALID_ARGUMENT.n()); } catch (IOException e) { e.printStackTrace(System.err); System.exit(ZK_CONNECTION_LOSS.n()); } catch (InterruptedException e) { e.printStackTrace(System.err); System.exit(INTERNAL_ERROR.n()); } finally { if (clnt != null) { try { clnt.close(); } catch (Exception e) { ; // nothing to do } } } }