Example usage for java.io InputStreamReader InputStreamReader

List of usage examples for java.io InputStreamReader InputStreamReader

Introduction

In this page you can find the example usage for java.io InputStreamReader InputStreamReader.

Prototype

public InputStreamReader(InputStream in) 

Source Link

Document

Creates an InputStreamReader that uses the default charset.

Usage

From source file:ReadZip.java

public static void main(String args[]) {
    try {/* w  w  w . jav a2 s  .c  o m*/
        ZipFile zf = new ZipFile("ReadZip.zip");
        Enumeration entries = zf.entries();

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        while (entries.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) entries.nextElement();
            System.out.println("Read " + ze.getName() + "?");
            String inputLine = input.readLine();
            if (inputLine.equalsIgnoreCase("yes")) {
                long size = ze.getSize();
                if (size > 0) {
                    System.out.println("Length is " + size);
                    BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
                    String line;
                    while ((line = br.readLine()) != null) {
                        System.out.println(line);
                    }
                    br.close();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:DateFormatFile.java

public static void main(String[] args) throws IOException {
    DateFormatFile df = new DateFormatFile();
    BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
    String line;//from   w ww .j  a v  a2s .  co m
    while ((line = is.readLine()) != null) {
        df.process(line);
    }
}

From source file:SSLSimpleClient.java

public static void main(String[] args) throws Exception {
    SocketFactory sf = SSLSocketFactory.getDefault();
    Socket s = sf.createSocket(args[0], Integer.parseInt(args[1]));

    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    PrintWriter pw = new PrintWriter(s.getOutputStream());
    pw.println("from java2s.");
    pw.flush();//w  w w.ja va 2 s .  co m
    System.out.println(br.readLine());
    s.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket socket = new Socket("localhost", 12900);
    System.out.println("Started client  socket at " + socket.getLocalSocketAddress());
    BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    BufferedWriter socketWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));

    String promptMsg = "Please enter a  message  (Bye  to quit):";
    String outMsg = null;//from ww w .  ja v  a  2 s .com

    System.out.print(promptMsg);
    while ((outMsg = consoleReader.readLine()) != null) {
        if (outMsg.equalsIgnoreCase("bye")) {
            break;
        }
        // Add a new line to the message to the server,
        // because the server reads one line at a time.
        socketWriter.write(outMsg);
        socketWriter.write("\n");
        socketWriter.flush();

        // Read and display the message from the server
        String inMsg = socketReader.readLine();
        System.out.println("Server: " + inMsg);
        System.out.println(); // Print a blank line
        System.out.print(promptMsg);
    }
    socket.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ServerSocket ss = new ServerSocket(80);
    while (true) {
        Socket s = ss.accept();/*  ww  w  . ja v a2s  .c  o  m*/
        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");
        out.println("MIME_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:InputOutputDemoStandardInputOutput.java

public static void main(String[] a) throws Exception {

    //Write characters to standard output and standard error:
    System.out.println("std output");
    System.err.println("std error");
    //Read characters from standard input (the keyboard):
    System.out.print("Type some characters and press Enter: ");
    BufferedReader bisr = new BufferedReader(new InputStreamReader(System.in));
    String response = bisr.readLine();
    System.out.println("You typed: '" + response + "'");
    //Read a byte from standard input (the keyboard):
    System.out.print("Type one character and press Enter: ");
    byte b = (byte) System.in.read();
    System.out.println("First byte of your input is: " + b);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Socket sock = ssock.accept();
    ssock.close();//from w  w  w  . j  a  va  2 s  .c  o  m

    PrintStream pstream = new PrintStream(sock.getOutputStream());
    pstream.print("count? ");
    BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    String line = input.readLine();
    pstream.println("");
    int count = Integer.parseInt(line);
    for (int i = count; i >= 0; i--) {
        pstream.println(i);
    }
    pstream.close();
    sock.close();
}

From source file:POP3Demo.java

public static void main(String[] args) throws Exception {
    int POP3Port = 110;
    Socket client = new Socket("127.0.0.1", POP3Port);
    InputStream is = client.getInputStream();
    BufferedReader sockin = new BufferedReader(new InputStreamReader(is));
    OutputStream os = client.getOutputStream();
    PrintWriter sockout = new PrintWriter(os, true);
    String cmd = "user Smith";
    sockout.println(cmd);/*from w ww  .  java2  s  .  co m*/
    String reply = sockin.readLine();
    cmd = "pass ";
    sockout.println(cmd + "popPassword");
    reply = sockin.readLine();
    cmd = "stat";
    sockout.println(cmd);
    reply = sockin.readLine();
    if (reply == null)
        return;
    cmd = "retr 1";
    sockout.println(cmd);
    if (cmd.toLowerCase().startsWith("retr") && reply.charAt(0) == '+')
        do {
            reply = sockin.readLine();
            System.out.println("S:" + reply);
            if (reply != null && reply.length() > 0)
                if (reply.charAt(0) == '.')
                    break;
        } while (true);
    cmd = "quit";
    sockout.println(cmd);
    client.close();
}

From source file:BufferedSocketClient.java

  public static void main(String args[]) throws Exception {
  Socket socket1;//from ww  w. ja  v  a  2s  .com
  int portNumber = 1777;
  String str = "initialize";

  socket1 = new Socket(InetAddress.getLocalHost(), portNumber);

  BufferedReader br = new BufferedReader(new InputStreamReader(socket1.getInputStream()));

  PrintWriter pw = new PrintWriter(socket1.getOutputStream(), true);

  pw.println(str);

  while ((str = br.readLine()) != null) {
    System.out.println(str);
    pw.println("bye");

    if (str.equals("bye"))
      break;
  }

  br.close();
  pw.close();
  socket1.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    Authenticator.setDefault(new DialogAuthenticator());

    URL u = new URL("secure url");
    InputStream in = u.openStream();
    in = new BufferedInputStream(in);
    Reader r = new InputStreamReader(in);
    int c;/* w  w  w .  j ava 2s .c  o  m*/
    while ((c = r.read()) != -1) {
        System.out.print((char) c);
    }
}