Package java.io

Examples of java.io.BufferedReader


        String insertStartMarker =
            Localizer.getMessage("jspc.webinc.insertStart");
        String insertEndMarker =
            Localizer.getMessage("jspc.webinc.insertEnd");

        BufferedReader reader = new BufferedReader(openWebxmlReader(webXml));
        BufferedReader fragmentReader = new BufferedReader(
                openWebxmlReader(new File(webxmlFile)));
        PrintWriter writer = new PrintWriter(openWebxmlWriter(webXml2));

        // Insert the <servlet> and <servlet-mapping> declarations
        boolean inserted = false;
        int current = reader.read();
        while (current > -1) {
            if (current == '<') {
                String element = getElement(reader);
                if (!inserted && insertBefore.contains(element)) {
                    // Insert generated content here
                    writer.println(insertStartMarker);
                    while (true) {
                        String line = fragmentReader.readLine();
                        if (line == null) {
                            writer.println();
                            break;
                        }
                        writer.println(line);
                    }
                    writer.println(insertEndMarker);
                    writer.println();
                    writer.write(element);
                    inserted = true;
                } else if (element.equals(insertStartMarker)) {
                    // Skip the previous auto-generated content
                    while (true) {
                        current = reader.read();
                        if (current < 0) {
                            throw new EOFException();
                        }
                        if (current == '<') {
                            element = getElement(reader);
                            if (element.equals(insertEndMarker)) {
                                break;
                            }
                        }
                    }
                    current = reader.read();
                    while (current == '\n' || current == '\r') {
                        current = reader.read();
                    }
                    continue;
                } else {
                    writer.write(element);
                }
            } else {
                writer.write(current);
            }
            current = reader.read();
        }
        writer.close();

        reader.close();
        fragmentReader.close();

        FileInputStream fis = new FileInputStream(webXml2);
        FileOutputStream fos = new FileOutputStream(webXml);

        byte buf[] = new byte[512];
View Full Code Here


  private static void getVersionInResource() {
    String implVersion = null;
    // Read version from joram.version file in bundle.
    try {
      InputStream in = MetaData.class.getResourceAsStream("/joram.version");
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      String v = reader.readLine();
      while (v != null) {
        if (v.contains("version"))
          implVersion = (v.substring(v.indexOf('=')+1, v.length())).trim();
        else if (v.contains("protocol"))
          protocol = Integer.parseInt(v.substring(v.indexOf('=')+1, v.length()).trim());
        v = reader.readLine();
      }

    } catch (Exception e) {
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, "MetaData.getVersionInResource:: EXCEPTION", e);
View Full Code Here

        String insertStartMarker =
            Localizer.getMessage("jspc.webinc.insertStart");
        String insertEndMarker =
            Localizer.getMessage("jspc.webinc.insertEnd");

        BufferedReader reader = new BufferedReader(openWebxmlReader(webXml));
        BufferedReader fragmentReader = new BufferedReader(
                openWebxmlReader(new File(webxmlFile)));
        PrintWriter writer = new PrintWriter(openWebxmlWriter(webXml2));

        // Insert the <servlet> and <servlet-mapping> declarations
        boolean inserted = false;
        int current = reader.read();
        while (current > -1) {
            if (current == '<') {
                String element = getElement(reader);
                boolean found = false;
                if (!inserted) {
                    for (String before : insertBefore) {
                        if (element.equals(before)) {
                            found = true;
                            break;
                        }
                    }
                }
                if (found) {
                    // Insert generated content here
                    writer.println(insertStartMarker);
                    while (true) {
                        String line = fragmentReader.readLine();
                        if (line == null) {
                            writer.println();
                            break;
                        }
                        writer.println(line);
                    }
                    writer.println(insertEndMarker);
                    writer.println();
                    writer.write(element);
                    inserted = true;
                } else if (element.equals(insertStartMarker)) {
                    // Skip the previous auto-generated content
                    while (true) {
                        current = reader.read();
                        if (current < 0) {
                            throw new EOFException();
                        }
                        if (current == '<') {
                            element = getElement(reader);
                            if (element.equals(insertEndMarker)) {
                                break;
                            }
                        }
                    }
                    current = reader.read();
                    while (current == '\n' || current == '\r') {
                        current = reader.read();
                    }
                    continue;
                } else {
                    writer.write(element);
                }
            } else {
                writer.write(current);
            }
            current = reader.read();
        }
        writer.close();

        reader.close();
        fragmentReader.close();

        FileInputStream fis = new FileInputStream(webXml2);
        FileOutputStream fos = new FileOutputStream(webXml);

        byte buf[] = new byte[512];
View Full Code Here

  private void updateJoramAdminCfg(String hostName,
                                   String port)
    throws Exception {
    File file = new File(confDir, JORAMADMIN_CFG);
    FileReader fileReader = new FileReader(file);
    BufferedReader reader = new BufferedReader(fileReader);
    boolean end = false;
    String line;
    StringTokenizer tokenizer;
    String firstToken;
    StringBuffer buff = new StringBuffer();

    while (! end) {
      line = reader.readLine();
      if (line == null)
        end = true;
      else {
        tokenizer = new StringTokenizer(line);
        if (tokenizer.hasMoreTokens()) {
View Full Code Here

  private void updateJoramAdminXml(String hostName,
                                   String port)
    throws Exception {
    File file = new File(confDir, JORAMADMIN_XML);
    FileReader fileReader = new FileReader(file);
    BufferedReader reader = new BufferedReader(fileReader);
    boolean end = false;
    String line;
    StringBuffer buff = new StringBuffer();
    int i = -1;

    while (! end) {
      line = reader.readLine();
      if (line == null)
        end = true;
      else {
        if (line.trim().startsWith("<connect")) {
          while (true) {
            i = line.indexOf("host");
            if (i > 0) {
              buff.append(line.substring(0,i+10));
              buff.append(hostName);
              int j = line.indexOf("\"",i+11);
              buff.append(line.substring(j,line.length()) + "\n");
              if (line.trim().endsWith("/>")) {
                line = reader.readLine();
                break;
              }
              line = reader.readLine();
              continue;
            }
            i = line.indexOf("port");
            if (i > 0) {
              buff.append(line.substring(0,i+6));
              buff.append(port);
              int j = line.indexOf("\"",i+7);
              buff.append(line.substring(j,line.length()) + "\n");
              if (line.trim().endsWith("/>")) {
                line = reader.readLine();
                break;
              }
              line = reader.readLine();
              continue;
            }
            buff.append(line + "\n");
            if (line.trim().endsWith("/>")) {
              line = reader.readLine();
              break;
            }
            line = reader.readLine();
          }
        } else if (line.trim().startsWith("<tcp")) {
          while (true) {
            i = line.indexOf("host");
            if (i > 0) {
              buff.append(line.substring(0,i+6));
              buff.append(hostName);
              int j = line.indexOf("\"",i+7);
              buff.append(line.substring(j,line.length()) + "\n");
              if (line.trim().endsWith("/>")) {
                line = reader.readLine();
                break;
              }
              line = reader.readLine();
              continue;
            }
            i = line.indexOf("port");
            if (i > 0) {
              buff.append(line.substring(0,i+6));
              buff.append(port);
              int j = line.indexOf("\"",i+7);
              buff.append(line.substring(j,line.length()) + "\n");
              if (line.trim().endsWith("/>")) {
                line = reader.readLine();
                break;
              }
              line = reader.readLine();
              continue;
            }
            buff.append(line + "\n");
            if (line.trim().endsWith("/>"))
              break;
            line = reader.readLine();
          }
        }
        buff.append(line + "\n");
      }
    }
View Full Code Here

              "Already returned as a stream.");
        ((ServeInputStream) in).setReturnedAsReader(true);
      }
      if (charEncoding != null)
        try {
          return new BufferedReader(new InputStreamReader(in,
              charEncoding));
        } catch (UnsupportedEncodingException uee) {
        }
      return new BufferedReader(new InputStreamReader(in));
    }
View Full Code Here

  public static Acme.WildcardDictionary parseThrottleFile(String filename) throws IOException {
    Acme.WildcardDictionary wcd = new Acme.WildcardDictionary();
    File thFile = new File(filename);
    if (thFile.isAbsolute() == false)
      thFile = new File(System.getProperty("user.dir", "."), thFile.getName());
    BufferedReader br = new BufferedReader(new FileReader(thFile));
    while (true) {
      String line = br.readLine();
      if (line == null)
        break;
      int i = line.indexOf('#');
      if (i != -1)
        line = line.substring(0, i);
      line = line.trim();
      if (line.length() == 0)
        continue;
      String[] words = Acme.Utils.splitStr(line);
      if (words.length != 2)
        throw new IOException("malformed throttle line: " + line);
      try {
        wcd.put(words[0], new ThrottleItem(Long.parseLong(words[1])));
      } catch (NumberFormatException e) {
        throw new IOException("malformed number in throttle line: " + line);
      }
    }
    br.close();
    return wcd;
  }
View Full Code Here

    try {
      URL deviceURL = configuration.getDeviceURL(page);
      URLConnection connection = deviceURL.openConnection();
      connection.setConnectTimeout(configuration.getConnectionTimeout());
      InputStream contentStream = (InputStream) connection.getContent();
      BufferedReader in = new BufferedReader(new InputStreamReader(contentStream));
      StringBuffer content = new StringBuffer();
      String line;
      while ((line = in.readLine()) != null) {
        content.append(line);
      }
      in.close();
      configuration.setDeviceUnreachable(false);
      return content;
    } catch (MalformedURLException e) {
      configuration.setDeviceUnreachable(true);
      throw new TopfieldConnectionException(e);
View Full Code Here

        connection.setDoOutput(true);
        OutputStreamWriter connectionWriter = new OutputStreamWriter(connection.getOutputStream());
        connectionWriter.write(request);
        connectionWriter.close();
        InputStream contentStream = connection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(contentStream));
        boolean insertOK = true;
        String line;
        while ((line = in.readLine()) != null) {
          if (line.contains(REPLY_ALERT)) {
            insertOK = false;
            break;
          }
        }
        in.close();
        getTimerList();
        configuration.setDeviceUnreachable(false);
        return insertOK;
      } catch (MalformedURLException e) {
        configuration.setDeviceUnreachable(true);
View Full Code Here

      connectionWriter.close();
      // No need to check the answer, it's always OK. Nevertheless we have to
      // read the result or the server on the device won't answer the next
      // request.
      InputStream contentStream = connection.getInputStream();
      BufferedReader in = new BufferedReader(new InputStreamReader(contentStream));
      while (in.readLine() != null) {
        ;
      }
      in.close();
      getTimerList();
      boolean deleteOK = true;
      // Check the list of timers after deletion to determine if the deletion
      // was successful.
      for (TopfieldTimerEntry currentEntry : configuration.getTimerEntries()) {
View Full Code Here

TOP

Related Classes of java.io.BufferedReader

Copyright © 2015 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.