List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader 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;// www .j a v a 2s . c om } 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 w w w .j a v a 2 s .com 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:Main.java
public static void main(String[] args) throws IOException { FileOutputStream f = new FileOutputStream("test.zip"); CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32()); ZipOutputStream zos = new ZipOutputStream(csum); BufferedOutputStream out = new BufferedOutputStream(zos); zos.setComment("A test of Java Zipping"); for (int i = 0; i < args.length; i++) { System.out.println("Writing file " + args[i]); BufferedReader in = new BufferedReader(new FileReader(args[i])); zos.putNextEntry(new ZipEntry(args[i])); int c;//from w ww .ja v a 2s.c o m while ((c = in.read()) != -1) out.write(c); in.close(); } out.close(); System.out.println("Checksum: " + csum.getChecksum().getValue()); System.out.println("Reading file"); FileInputStream fi = new FileInputStream("test.zip"); CheckedInputStream csumi = new CheckedInputStream(fi, new Adler32()); ZipInputStream in2 = new ZipInputStream(csumi); BufferedInputStream bis = new BufferedInputStream(in2); ZipEntry ze; while ((ze = in2.getNextEntry()) != null) { System.out.println("Reading file " + ze); int x; while ((x = bis.read()) != -1) System.out.write(x); } System.out.println("Checksum: " + csumi.getChecksum().getValue()); bis.close(); }
From source file:ASCII2NATIVE.java
public static void main(String[] args) { File f = new File("c:\\mydb.script"); File f2 = new File("c:\\mydb3.script"); if (f.exists() && f.isFile()) { // convert param-file BufferedReader br = null; StringBuffer sb = new StringBuffer(); String line;//from ww w . ja v a2s .com try { br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "JISAutoDetect")); while ((line = br.readLine()) != null) { System.out.println(ascii2Native(line)); sb.append(ascii2Native(line)).append(";\n");//.append(";\n\r") } BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f2), "utf-8")); out.append(sb.toString()); out.flush(); out.close(); } catch (FileNotFoundException e) { System.err.println("file not found - " + f); } catch (IOException e) { System.err.println("read error - " + f); } finally { try { if (br != null) br.close(); } catch (Exception e) { } } } else { // // convert param-data // System.out.print(ascii2native(args[i])); // if (i + 1 < args.length) // System.out.print(' '); } }
From source file:LowerCaseReader.java
public static void main(String[] args) throws Exception { String fileName = "test.txt"; LowerCaseReader lcr = new LowerCaseReader(new FileReader(fileName)); int c = -1;/*from w w w .j a v a2s . c om*/ while ((c = lcr.read()) != -1) { System.out.print((char) c); } lcr.close(); BufferedReader br = new BufferedReader(new LowerCaseReader(new FileReader(fileName))); String str = null; while ((str = br.readLine()) != null) { System.out.println(str); } br.close(); }
From source file:com.idega.util.Stripper.java
public static void main(String[] args) { // Stripper stripper1 = new Stripper(); if (args.length != 2) { System.err.println("Auli. tt a hafa tvo parametra me essu, innskr og tskr"); return;// w ww . j ava 2 s . c o m } BufferedReader in = null; BufferedWriter out = null; try { in = new BufferedReader(new FileReader(args[0])); } catch (java.io.FileNotFoundException e) { System.err.println("Auli. Error : " + e.toString()); return; } try { out = new BufferedWriter(new FileWriter(args[1])); } catch (java.io.IOException e) { System.err.println("Auli. Error : " + e.toString()); IOUtils.closeQuietly(in); return; } try { String input = in.readLine(); int count = 0; while (input != null) { int index = input.indexOf("\\CVS\\"); if (index > -1) { System.out.println("Skipping : " + input); count++; } else { out.write(input); out.newLine(); } input = in.readLine(); } System.out.println("Skipped : " + count); } catch (java.io.IOException e) { System.err.println("Error reading or writing file : " + e.toString()); } try { in.close(); out.close(); } catch (java.io.IOException e) { System.err.println("Error closing files : " + e.toString()); } }
From source file:DemoPreparedStatementSetCharacterStream.java
public static void main(String[] args) throws Exception { String fileName = "charDataFile.txt"; Reader fileReader = null;/* w w w . j av a 2 s . c om*/ long fileLength = 0; Connection conn = null; PreparedStatement pstmt = null; try { File file = new File(fileName); fileLength = file.length(); fileReader = (Reader) new BufferedReader(new FileReader(file)); System.out.println("fileName=" + fileName); System.out.println("fileLength=" + fileLength); conn = getConnection(); // begin transaction conn.setAutoCommit(false); // prepare SQL query for inserting a new row using SetCharacterStream() String query = "insert into char_stream_table (id, char_stream_column) values(?, ?)"; // create PrepareStatement object pstmt = conn.prepareStatement(query); pstmt.setString(1, fileName); pstmt.setCharacterStream(2, fileReader, (int) fileLength); // execute query, and return number of rows created int rowCount = pstmt.executeUpdate(); System.out.println("rowCount=" + rowCount); // end transaction conn.commit(); } finally { pstmt.close(); conn.close(); } }
From source file:FlightInfo.java
public static void main(String args[]) { String to, from;/*from www . ja va 2s. co 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:math2605.gn_qua.java
/** * @param args the command line arguments *///from ww w. jav a 2 s. co m public static void main(String[] args) { //get file name System.out.println("Please enter a file name:"); Scanner scanner = new Scanner(System.in); String fileName = scanner.nextLine(); List<String[]> pairs = new ArrayList<>(); //get coordinate pairs and add to arraylist try { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] pair = line.split(","); pairs.add(pair); } br.close(); } catch (Exception e) { System.out.println(e.getMessage()); } System.out.println("Please enter the value of a:"); double a = scanner.nextInt(); System.out.println("Please enter the value of b:"); double b = scanner.nextInt(); System.out.println("Please enter the value of c:"); double c = scanner.nextInt(); //init B, vector with 3 coordinates RealMatrix B = new Array2DRowRealMatrix(3, 1); B.setEntry(0, 0, a); B.setEntry(1, 0, b); B.setEntry(2, 0, c); System.out.println("Please enter the number of iteration for the Gauss-newton:"); //init N, number of iterations int N = scanner.nextInt(); //init r, vector of residuals RealMatrix r = new Array2DRowRealMatrix(pairs.size(), 1); setR(pairs, a, b, c, r); //init J, Jacobian of r RealMatrix J = new Array2DRowRealMatrix(pairs.size(), 3); setJ(pairs, a, b, c, r, J); System.out.println("J"); System.out.println(J); System.out.println("r"); System.out.println(r); RealMatrix sub = findQR(J, r); for (int i = N; i > 0; i--) { B = B.subtract(sub); double B0 = B.getEntry(0, 0); double B1 = B.getEntry(1, 0); double B2 = B.getEntry(2, 0); //CHANGE ABC TO USE B0, B1, B2 setR(pairs, B0, B1, B2, r); setJ(pairs, B0, B1, B2, r, J); } System.out.println("B"); System.out.println(B.toString()); }
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);// w w w . j a v a2s . 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(); } }