Package java.io

Examples of java.io.BufferedReader


        URL url = new URL(buf.toString());

        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        InputStream in = con.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        Matcher matcher;
        Pattern pattern = Pattern.compile("<tr><td>(\\d+):(\\d+)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td></tr>");

        String line = reader.readLine();
        while (line != null) {

            matcher = pattern.matcher(line);
            if (matcher.find()) {
                // System.out.println("h: "+matcher.group(1)+"; m: "+matcher.group(2)+"; title: "+matcher.group(3)+"; short: "+matcher.group(4)+"; desc: "+matcher.group(5));
                int h = Integer.parseInt(matcher.group(1));
                int m = Integer.parseInt(matcher.group(2));
                String title = matcher.group(3);
                String shortInfo = matcher.group(4);
                String description = matcher.group(5);

                ProgramFrame frame = new ProgramFrame();
                frame.addProgramField(ProgramField.create(ProgramFieldType.START_TIME_TYPE, h * 60 + m));
                frame.addProgramField(ProgramField.create(ProgramFieldType.TITLE_TYPE, title));
                frame.addProgramField(ProgramField.create(ProgramFieldType.SHORT_DESCRIPTION_TYPE, shortInfo));
                frame.addProgramField(ProgramField.create(ProgramFieldType.DESCRIPTION_TYPE, description));
                dispatcher.dispatchProgramFrame(frame, date);

            }
            line = reader.readLine();
        }
    }
View Full Code Here


  }

  public void restoreSessions(ServletContext servletContext) {
    File store = sessions == null?null:getPersistentFile(servletContext);
    if (store != null && store.exists()) {
      BufferedReader bfr = null;
      try {
        bfr = new BufferedReader(new FileReader(store));

        AcmeSession session;
        while ((session = AcmeSession.restore(bfr,
            Math.abs(expiredIn) * 60, servletContext, sessions)) != null)
          if (session.checkExpired() == false)
            sessions.put(session.getId(), session);
      } catch (IOException ioe) {
        log("TJWS: problem in sessions deserialization for "+servletContext, ioe);
      } finally {
        if (bfr != null)
          try {
            bfr.close();
          } catch (Exception e) {

          }
      }
    }
View Full Code Here

      // expiredIn = -expiredIn;
    keepAliveCleaner = new KeepAliveCleaner();
    keepAliveCleaner.start();
    File fsessions = getPersistentFile();
    if (fsessions != null && fsessions.exists()) {
      BufferedReader br = null;
      try {
        br = new BufferedReader(new FileReader(fsessions));
        sessions = HttpSessionContextImpl.restore(br,
            Math.abs(expiredIn) * 60, this);
      } catch (IOException ioe) {
        log("TJWS: IO error in restoring sessions.", ioe);
      } catch (Exception e) {
        log("TJWS: Unexpected problem in restoring sessions.", e);
      } finally {
        if (br != null)
          try {
            br.close();
          } catch (IOException ioe) {
          }
      }
    }
    if (sessions == null)
View Full Code Here

    try {
      chat = new SimpleChat("topicChat", user);

      // Read from command line
      BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));

      // Loop until the word "exit" is typed

      System.out.println("User: " + user + " connected !");
      System.out.println("Type your phrases and press 'ENTER' ...");
      System.out.println("Type 'exit' or 'quit' to abandon the chat.");

      while(true) {
        String s = commandLine.readLine( );
        if ( s.equalsIgnoreCase("exit") || s.equalsIgnoreCase("quit") ) {
          chat.close( ); // close down connection
          System.exit(0);// exit program
        } else
          chat.writeMessage(s);
View Full Code Here

              cs = default_charset;
           
          }
            }           
           
            BufferedReader rd = new BufferedReader(new InputStreamReader(
            get.getResponseBodyAsStream(), cs));
           
            char[] cbuf = new char[1];
            int read_idx = 1;
            do{
              rd.mark(read_idx++);
              if(rd.read(cbuf)==-1)
                break;
              if(cbuf[0]!='<')
                continue;
              rd.reset();
              break;
            }while(true);
            return (Channel)parser.parse(rd);
          }
          else{
View Full Code Here

      WSEndpoint<?>     endPoint   = codec.getEndpoint();
      //JAXBContextImpl   context   = (JAXBContextImpl)endPoint.getSEIModel().getJAXBContext();
     
      StringBuffer   buffer   = new StringBuffer();
      try{
        BufferedReader reader  = new BufferedReader(new InputStreamReader(DefaultEndpointDocument.class.getResourceAsStream("default.html"))); //$NON-NLS-1$
        String       line   = reader.readLine();
        while(line != null){
          buffer.append(line+"\n"); //$NON-NLS-1$
          line = reader.readLine();
        }
        reader.close();
      }catch(Throwable th){
        th.printStackTrace();
      }
      String templateMain = buffer.toString();
      templateMain    = templateMain.replaceAll("#SERIVICE_NAME#", endPoint.getServiceName().getLocalPart()); //$NON-NLS-1$
View Full Code Here

        Socket connection = AsyncSocketFactory.createSocket(server, port, timeout);
        try {
            PrintStream out = new PrintStream(connection.getOutputStream());
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                try {
                    out.println(query);
                    StringBuffer sb = new StringBuffer();

                    String line;
                    while ((line = in.readLine()) != null) {
                        sb.append(line).append(lineSeparator);
                        line = line.trim();
                        if (! line.startsWith("%") && ! line.startsWith("#")) {
                            int fs = line.indexOf(":");
                            if (fs > 0) {
                                String name = line.substring(0, fs);
                                String value = line.substring(fs + 1).trim();
                                response.data.put(name, value);
                            }
                        }
                    }
                    response.summary = sb.toString();

                    Response newResponse = null;
                    String referral = (String) response.getData().get("ReferralServer");

                    if (referral != null) {
                        try {
                            URLParser url = new URLParser(referral);
                            if ("whois".equals(url.getProtocol())) {
                                newResponse = lookup(url.getHost(), url.getPort() == -1 ? 43 : url.getPort(), query,
                                        timeout, lineSeparator);
                            }
                        } catch (IOException e) {
                            System.out.println("Could not contact " + referral);
                        }
                    }
                    if (newResponse != null) {
                        response = newResponse;
                    }
                } finally {
                    in.close();
                }
            } finally {
                out.close();
            }
        } finally {
View Full Code Here

        if (Charset.isSupported(charsetName)) {
            charset = Charset.forName(charsetName);
        }

        StringBuffer out = new StringBuffer();
        BufferedReader r = new BufferedReader(new InputStreamReader(is, charset), 4096);
        try {
            String b;
            while ((b = r.readLine()) != null) {
                out.append(b).append("\n");
            }
        } finally {
            r.close();
        }

        return out.toString();
    }
View Full Code Here

            }       
    }

    public void readDefaultHeaderFile() {
        if(_defaultHeaderFile.exists()){
            BufferedReader breader = null;
            try {
                breader = new BufferedReader(new FileReader(_defaultHeaderFile));
                StringBuffer sb = new StringBuffer();
   
                String tmp;
                do {
                    tmp = breader.readLine();
                    if (tmp != null) {
                        sb.append(tmp);
                    }
                } while (tmp != null);
   
                _defaultHeader = sb.toString();
            }
            catch (FileNotFoundException e) {
                Plugin.getDefault().logError("File not found : " + _defaultHeaderFile.getAbsolutePath(), e);
            }
            catch (IOException e) {
                Plugin.getDefault().logError("Unable to read file : " + _defaultHeaderFile.getAbsolutePath(), e);
            }finally{
                try {
                    breader.close();
                }
                catch (IOException e) {
                    Plugin.getDefault().logError("Unable to close reader for file : " + _defaultHeaderFile.getAbsolutePath(), e);
                }
            }
View Full Code Here

 
  @SuppressWarnings("unchecked")
  private void processPostBody(Map<String,Object> jsonMap,ServletRequest request){
    StringBuffer  buffer  = new StringBuffer();
    try{
      BufferedReader   reader  = new BufferedReader(new InputStreamReader(request.getInputStream()));
      String       line   = reader.readLine();
      while(line != null){
        buffer.append(line);
        line = reader.readLine();
      }
      reader.close();
    }catch(Throwable th){
      th.printStackTrace();
    }
    String content = buffer.toString().trim();
    if(content.startsWith("{")){
      // JSON
      JSONReader   reader = new JSONReader();
      Object     object = reader.read(content);
      if(object instanceof Map){
        jsonMap.putAll((Map<String, ? extends Object>) object);
      }
    } else if(content.startsWith("JOSN=")){
      JSONReader   reader = new JSONReader();
      Object     object = reader.read(content.substring(4));
      if(object instanceof Map){
        jsonMap.putAll((Map<String, ? extends Object>) object);
      }
    } else {
      // As parmeter
View Full Code Here

TOP

Related Classes of java.io.BufferedReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.