List of usage examples for java.io InputStreamReader InputStreamReader
public InputStreamReader(InputStream in)
From source file:NewFingerServer.java
public static void main(String[] arguments) throws Exception { ServerSocketChannel sockChannel = ServerSocketChannel.open(); sockChannel.configureBlocking(false); InetSocketAddress server = new InetSocketAddress("localhost", 79); ServerSocket socket = sockChannel.socket(); socket.bind(server);//w w w.jav a 2s . c o m Selector selector = Selector.open(); sockChannel.register(selector, SelectionKey.OP_ACCEPT); while (true) { selector.select(); Set keys = selector.selectedKeys(); Iterator it = keys.iterator(); while (it.hasNext()) { SelectionKey selKey = (SelectionKey) it.next(); it.remove(); if (selKey.isAcceptable()) { ServerSocketChannel selChannel = (ServerSocketChannel) selKey.channel(); ServerSocket selSocket = selChannel.socket(); Socket connection = selSocket.accept(); InputStreamReader isr = new InputStreamReader(connection.getInputStream()); BufferedReader is = new BufferedReader(isr); PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()), false); pw.println("NIO Finger Server"); pw.flush(); String outLine = null; String inLine = is.readLine(); if (inLine.length() > 0) { outLine = inLine; } readPlan(outLine, pw); pw.flush(); pw.close(); is.close(); connection.close(); } } } }
From source file:de.zib.vold.userInterface.ABI.java
public static void main(String[] args) { ABI abi = new ABI(); while (true) { try {//from w ww . j a v a 2 s .c o m InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); System.out.print("#: "); String s = br.readLine(); if (null == s) break; String[] a = s.split("\\s+"); if (a.length < 1) { System.out.println("ERROR: The following commands are valid:"); System.out.println("ERROR: insert <source> <scope> <type> <keyname> {<value> }*"); System.out.println("ERROR: lookup <scope> <type> <keyname>"); System.out.println("ERROR: exit"); continue; } else if (a[0].equals("lookup") || a[0].equals("l")) { if (a.length < 4) { System.out.println("ERROR: Syntax for lookup is:"); System.out.println("ERROR: lookup <scope> <type> <keyname>"); continue; } Map<Key, Set<String>> result; try { result = abi.frontend.lookup(new Key(a[1], a[2], a[3])); } catch (VoldException e) { System.out.println( "An internal error occured: " + e.getClass().getName() + ": " + e.getMessage()); continue; } for (Map.Entry<Key, Set<String>> entry : result.entrySet()) { Key k = entry.getKey(); System.out.println("+Found ('" + k.get_scope() + "', '" + k.get_type() + "', '" + k.get_keyname() + "')"); for (String v : entry.getValue()) { System.out.println("-" + v); } } } else if (a[0].equals("insert") || a[0].equals("i")) { if (a.length < 5) { System.out.println("ERROR: Syntax for insert is:"); System.out.println("ERROR: insert <source> <scope> <type> <keyname> {<value> }*"); continue; } Key k = new Key(a[2], a[3], a[4]); Set<String> values = new HashSet<String>(); for (int i = 5; i < a.length; ++i) { values.add(a[i]); } try { abi.frontend.insert(a[1], k, values, DateTime.now().getMillis()); } catch (VoldException e) { System.out.println( "An internal error occured: " + e.getClass().getName() + ": " + e.getMessage()); continue; } } else if (a[0].equals("exit") || a[0].equals("x")) { break; } else { System.out.println("ERROR: Unknown command!"); System.out.println("ERROR: The following commands are valid:"); System.out.println("ERROR: insert <source> <scope> <type> <keyname> {<value> }*"); System.out.println("ERROR: lookup <scope> <type> <keyname>"); System.out.println("ERROR: exit"); } } catch (IOException e) { e.printStackTrace(); } } System.exit(0); }
From source file:com.sap.core.odata.fit.mapping.MappingTest.java
public static void main(final String[] args) { final TestServer server = new TestServer(); try {/*from ww w .j a v a2s . c om*/ server.startServer(MapFactory.class); System.out.println("Press any key to exit"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } catch (final IOException e) { e.printStackTrace(System.err); } finally { server.stopServer(); } }
From source file:com.honnix.yaacs.adapter.http.ui.ACHttpClientCli.java
public static void main(String[] args) { ACHttpClientCli acHttpClientCli = new ACHttpClientCli(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { acHttpClientCli.help();/* w ww . ja v a2 s . c o m*/ String cmd = null; try { cmd = br.readLine(); } catch (IOException e) { e.printStackTrace(); // NOPMD by honnix on 3/29/08 10:35 PM System.err.println(BAD_INPUT); // NOPMD by honnix on 3/29/08 10:35 PM continue; } if ("li".equals(cmd)) { try { acHttpClientCli.handleLogin(br); } catch (Exception e) { e.printStackTrace(); // NOPMD by honnix on 3/29/08 10:35 PM System.err.println("Error logging in."); // NOPMD by honnix on 3/29/08 10:35 PM } } else if ("lo".equals(cmd)) { try { acHttpClientCli.handleLogout(); } catch (Exception e) { e.printStackTrace(); // NOPMD by honnix on 3/29/08 10:35 PM System.err.println("Error logging out."); // NOPMD by honnix on 3/29/08 10:35 PM } } if ("p".equals(cmd)) { try { acHttpClientCli.handlePut(br); } catch (Exception e) { e.printStackTrace(); // NOPMD by honnix on 3/29/08 10:35 PM System.err.println("Error putting album cover."); // NOPMD by honnix on 3/29/08 10:36 PM } } else if ("r".equals(cmd)) { try { acHttpClientCli.handleRetrieve(br); } catch (Exception e) { e.printStackTrace(); // NOPMD by honnix on 3/29/08 10:35 PM System.err.println("Error retrieving album cover list."); // NOPMD by honnix on 3/29/08 10:36 PM } } else if ("q".equals(cmd)) { break; } } }
From source file:cc.vidr.datum.tools.Console.java
public static void main(String[] args) throws IOException { System.out.print("Warming up... "); System.out.flush();/*from w w w. jav a2 s . c o m*/ QA.query(""); System.out.println("Ready."); System.out.println("Ask me a question. Leave a blank line to exit."); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { int numServers = Server.getNumServers(); int numFacts = Server.getNumFacts(); System.out.print("> "); String q = in.readLine(); if (q == null || q.isEmpty()) { System.out.println("Bye."); break; } Literal[] facts; if (q.startsWith("?-")) { try { Program program = new Program(q.substring(2)); Clause[] query = program.parse(); facts = Server.query(query[0].getHead()); } catch (RecognitionException e) { facts = new Literal[0]; } } else { facts = QA.query(q); } for (Literal fact : facts) printFact(fact, 0); if (facts.length == 0) System.out.println("I don't know."); if (DEBUG) { System.err.println((Server.getNumServers() - numServers) + " servers spawned"); System.err.println((Server.getNumFacts() - numFacts) + " facts retrieved/generated"); } } }
From source file:URLReader.java
public static void main(String[] args) throws Exception { URL yahoo = new URL("http://www.yahoo.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream())); String inputLine;// w w w . j av a 2s . co m while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }
From source file:Connect.java
public static void main(String[] args) { try { // Handle exceptions below // Get our command-line arguments String hostname = args[0]; int port = Integer.parseInt(args[1]); String message = ""; if (args.length > 2) for (int i = 2; i < args.length; i++) message += args[i] + " "; // Create a Socket connected to the specified host and port. Socket s = new Socket(hostname, port); // Get the socket output stream and wrap a PrintWriter around it PrintWriter out = new PrintWriter(s.getOutputStream()); // Sent the specified message through the socket to the server. out.print(message + "\r\n"); out.flush(); // Send it now. // Get an input stream from the socket and wrap a BufferedReader // around it, so we can read lines of text from the server. BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); // Before we start reading the server's response tell the socket // that we don't want to wait more than 3 seconds s.setSoTimeout(3000);//from w w w . j av a 2 s.c o m // Now read lines from the server until the server closes the // connection (and we get a null return indicating EOF) or until // the server is silent for 3 seconds. try { String line; while ((line = in.readLine()) != null) // If we get a line System.out.println(line); // print it out. } catch (SocketTimeoutException e) { // We end up here if readLine() times out. System.err.println("Timeout; no response from server."); } out.close(); // Close the output stream in.close(); // Close the input stream s.close(); // Close the socket } catch (IOException e) { // Handle IO and network exceptions here System.err.println(e); } catch (NumberFormatException e) { // Bad port number System.err.println("You must specify the port as a number"); } catch (ArrayIndexOutOfBoundsException e) { // wrong # of args System.err.println("Usage: Connect <hostname> <port> message..."); } }
From source file:com.kasabi.data.movies.freebase.FreebaseMovies2RDF.java
public static void main(String[] args) throws Exception { String filename = "/backups/tmp/freebase-datadump-quadruples.tsv.bz2"; BufferedReader in = new BufferedReader( new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(filename)))); String line;//from w w w .j ava 2s .c o m int count = 0; Model model = MoviesCommon.createModel(); String prev_subject = null; while ((line = in.readLine()) != null) { count++; String[] tokens = line.split("\\t"); if (tokens.length > 0) { String subject = tokens[0].trim(); if (!subject.equals(prev_subject)) { process(model); model = MoviesCommon.createModel(); } prev_subject = subject; if ((tokens.length == 3) && (tokens[0].trim().length() > 0) && (tokens[1].trim().length() > 0) && (tokens[2].trim().length() > 0)) { output_resource(model, tokens[0], tokens[1], tokens[2]); } else if ((tokens.length == 4) && (tokens[0].trim().length() > 0) && (tokens[1].trim().length() > 0) && (tokens[3].trim().length() > 0)) { if (tokens[2].trim().length() == 0) { output_literal(model, tokens[0], tokens[1], tokens[3]); } else { if (tokens[2].startsWith(LANG)) { output_literal_lang(model, tokens[0], tokens[1], tokens[3], tokens[2]); } else { if (tokens[1].equals("/type/object/key")) { output_literal2(model, tokens[0], tokens[1], tokens[2], tokens[3]); } else if ((tokens[1].equals("/type/object/name")) && (tokens[2].startsWith("/guid/"))) { output_literal2(model, tokens[0], tokens[1], tokens[2], tokens[3]); } else { log.warn("Unexpected data at {}, ignoring: {}", count, line); } } } } else { if (tokens.length < 3) { log.warn("Line {} has only {} tokens: {}", new Object[] { count, tokens.length, line }); } else { log.warn("Line {} has one or more empty tokens: {}", new Object[] { count, line }); } } } if (count % 1000000 == 0) log.info("Processed {} lines...", count); } }
From source file:CalcoloRitardiLotti.java
public static void main(String[] args) { String id_ref = "cbededce-269f-48d2-8c25-2359bf246f42"; String requestString = "http://dati.openexpo2015.it/catalog/api/action/datastore_search?resource_id=" + id_ref;// w ww . j av a 2 s . com HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(requestString); try { HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String result = ""; String resline = ""; Calendar c = Calendar.getInstance(); Date current = Date.valueOf( c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH)); while ((resline = rd.readLine()) != null) result += resline; //System.out.println(jsonObject.toString()); if (result != null) { JSONObject jsonObject = new JSONObject(result); JSONObject resultJson = (JSONObject) jsonObject.get("result"); JSONArray records = (JSONArray) resultJson.get("records"); Date temp1, temp2; //System.out.printf(records.toString()); long diffInizioFineLavori; long ritardo; long den = (24 * 60 * 60 * 1000); JSONObject temp; DefaultCategoryDataset cdata = new DefaultCategoryDataset(); String partialQuery; DefaultPieDataset data = new DefaultPieDataset(); String totalQuery = ""; int countSospesi = 0; int countConclusi = 0; int countVerifica = 0; int countInCorso = 0; int countCollaudo = 0; String stato; for (int i = 0; i < records.length(); i++) { temp = (JSONObject) records.get(i); temp1 = Date.valueOf((temp.getString("Data Consegna Lavori")).substring(0, 10)); temp2 = Date.valueOf((temp.getString("Data Fine lavori")).substring(0, 10)); diffInizioFineLavori = (long) (temp2.getTime() - temp1.getTime()) / den; stato = temp.getString("STATO"); if (stato.equals("Concluso")) countConclusi++; else if (stato.equals("In corso")) countInCorso++; else if (stato.contains("Verifiche")) countVerifica++; else if (stato.contains("Collaudo sospeso") || stato.contains("sospeso")) countSospesi++; else countCollaudo++; if (!temp.getString("STATO").equals("Concluso") && temp2.getTime() < current.getTime()) ritardo = (long) (current.getTime() - temp2.getTime()) / den; else ritardo = 0; cdata.setValue(ritardo, String.valueOf(i + 1), String.valueOf(i + 1)); System.out.println( "Opera: " + temp.getString("Oggetto del lotto") + " | id: " + temp.getInt("_id")); System.out.println("Data consegna lavoro: " + temp.getString("Data Consegna Lavori") + " | Data fine lavoro: " + temp.getString("Data Fine lavori")); System.out.println("STATO: " + temp.getString("STATO")); System.out.println("Differenza in giorni: " + diffInizioFineLavori + " | Numero giorni contrattuali: " + temp.getString("numero di giorni contrattuali")); System.out.println("Ritardo accumulato: " + ritardo); System.out.println("----------------------------------"); partialQuery = "\nid: " + temp.getInt("_id") + "\nOpera:" + temp.getString("Oggetto del lotto") + "\n" + "Data consegna lavoro: " + temp.getString("Data Consegna Lavori") + "Data fine lavoro: " + temp.getString("Data Fine lavori") + "\n" + "STATO: " + temp.getString("STATO") + "\n" + "Differenza in giorni: " + diffInizioFineLavori + " - Numero giorni contrattuali: " + temp.getString("numero di giorni contrattuali") + "\n" + "Ritardo accumulato: " + ritardo + "\n" + "----------------------------------\n"; totalQuery = totalQuery + partialQuery; } JFreeChart chart1 = ChartFactory.createBarChart3D("RITARDI AL " + current, "Id lotto", "ritardo(in giorni)", cdata); ChartRenderingInfo info = null; ChartUtilities.saveChartAsPNG( new File(System.getProperty("user.dir") + "/istogramma" + current + ".png"), chart1, 1500, 1500, info, true, 10); FileUtils.writeStringToFile(new File(current + "_1.txt"), totalQuery); data.setValue("Conclusi: " + countConclusi, countConclusi); data.setValue("Sospeso: " + countSospesi, countSospesi); data.setValue("In Corso: " + countInCorso, countInCorso); data.setValue("Verifica: " + countVerifica, countVerifica); data.setValue("Collaudo: " + countCollaudo, countCollaudo); JFreeChart chart2 = ChartFactory.createPieChart3D("Statistiche del " + current, data, true, true, true); ChartUtilities.saveChartAsPNG(new File(System.getProperty("user.dir") + "/pie" + current + ".png"), chart2, 800, 450); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.sankalp.characterreader.CharacterReader.java
public static void main(String[] args) throws IOException { double learningRate = 0.55; List<NeuralNetwork.Layer> hiddenLayerList = new ArrayList(); hiddenLayerList.add(new NeuralNetwork.Layer(50)); NeuralNetwork neuralNetwork = new NeuralNetwork(new NeuralNetwork.Layer(28 * 28), new NeuralNetwork.Layer(10), hiddenLayerList, learningRate); int trainingSampleCount = 60000; TrainingData trainingData = new TrainingData(new File("/home/sankalpkulshrestha/mnist/train-images/"), trainingSampleCount, new File("/home/sankalpkulshrestha/mnist/train-labels.csv")); int totalEpochs = 30; for (int index = 0; index < totalEpochs; index++) { System.out.println("---------- EPOCH " + index + " ----------"); neuralNetwork.train(trainingData); TrainingData testData = new TrainingData(new File("/home/sankalpkulshrestha/mnist/test-images/"), 10000, new File("/home/sankalpkulshrestha/mnist/test-labels.csv")); System.out.println("Training over"); double accuracy = neuralNetwork.measureAccuracy(testData); System.out.println(accuracy); if (index < totalEpochs - 1) { trainingData.shuffle();//www. j av a 2 s .c o m trainingData.reset(); } } System.out.println("Model trained. Enter image file names:"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int number = -1; List<String> expectedOutputList = FileUtils .readLines(new File("/home/sankalpkulshrestha/mnist/test-labels.csv"), "UTF-8"); while ((number = Integer.parseInt(br.readLine())) != -1) { int output = neuralNetwork.test(new TrainingData.Sample( new File("/home/sankalpkulshrestha/mnist/test-images/" + number + ".jpg"), 0)); System.out.println(output); } }