Package org.apache.commons.io

Examples of org.apache.commons.io.LineIterator


    }
   
    private List<String> getExampleBenchmarkPaths(HttpServletRequest request) throws IOException {
        // TODO how to enumerate bundle resources?
        final String list = getBenchmarkText("/LIST.txt");
        final LineIterator it = new LineIterator(new StringReader(list));
        final List<String> result = new LinkedList<String>();
        while(it.hasNext()) {
            result.add(getExampleBenchmarkPath(request, it.nextLine()));
        }
        return result;
    }
View Full Code Here


    public RequestExecutor assertContentRegexp(boolean expected, String... regexp) {
        assertNotNull(this.toString(), response);
        nextPattern:
        for (String expr : regexp) {
            final Pattern p = Pattern.compile(".*" + expr + ".*");
            final LineIterator it = new LineIterator(new StringReader(contentString));
            while (it.hasNext()) {
                final String line = it.nextLine();
                if (expected & p.matcher(line).matches()) {
                    continue nextPattern;
                }
                if(!expected & p.matcher(line).matches()) {
                    fail(this + ": match found for regexp '" + expr + "', content=\n" + contentString);
View Full Code Here

     * @param in
     * @param validate if mappings should be validated before adding
     * @throws IOException
     */
    private void readPrefixMappings(InputStream in,boolean validate) throws IOException {
        LineIterator it = IOUtils.lineIterator(in, "UTF-8");
        while(it.hasNext()){
            String mapping = it.nextLine();
            if(mapping.charAt(0) != '#'){
                int sep = mapping.indexOf('\t');
                if(sep < 0 || mapping.length() <= sep+1){
                    log.warn("Illegal prefix mapping '{}'",mapping);
                } else {
View Full Code Here

     * Expected to be called only during activation
     * @param in
     * @throws IOException
     */
    private void readPrefixMappings(InputStream in) throws IOException {
        LineIterator it = IOUtils.lineIterator(in, "UTF-8");
        while(it.hasNext()){
            String mapping = it.nextLine();
            if(mapping.charAt(0) != '#'){
                int sep = mapping.indexOf('\t');
                if(sep < 0 || mapping.length() <= sep+1){
                    log.warn("Illegal prefix mapping '{}'",mapping);
                } else {
View Full Code Here

            if(reader != null){
                closeQuietly(reader);
            }
            final Pattern p = Pattern.compile(".*" + expr + ".*");
            reader = new InputStreamReader(blob.getStream(), charset);
            final LineIterator it = new LineIterator(reader);
            while (it.hasNext()) {
                final String line = it.nextLine();
                if (p.matcher(line).matches()) {
                    continue nextPattern;
                }
            }
            fail(this + ": no match for regexp '" + expr + "', content=\n" +
View Full Code Here

        return dfp.getInputStream(null, resource, null);
    }

    public List<String> getLines(String resource) throws IOException {
        List<String> lines = new ArrayList<String>();
        LineIterator it = IOUtils.lineIterator(openResource(resource), "UTF-8");
        while(it.hasNext()){
            String line = it.nextLine();
            if(line != null && !line.isEmpty() && line.charAt(0) != '#'){
                lines.add(line);
            }
        }
        return lines;
View Full Code Here

        return in;
    }

    public List<String> getLines(String resource) throws IOException {
        List<String> lines = new ArrayList<String>();
        LineIterator it = IOUtils.lineIterator(openResource(resource), "UTF-8");
        while(it.hasNext()){
            String line = it.nextLine();
            if(line != null && !line.isEmpty() && line.charAt(0) != '#'){
                lines.add(line);
            }
        }
        return lines;
View Full Code Here

        //UTF-8, but some configurations might want to use URLs as keys!
        Map<String,Object> configMap = new HashMap<String,Object>();
        try {
            InputStream in = openConfig(configFile);
            if(in != null){
                LineIterator lines = IOUtils.lineIterator(in, "UTF-8");
                while(lines.hasNext()){
                    String line = (String)lines.next();
                    if(!line.isEmpty()){
                        int indexOfEquals = line.indexOf('=');
                        String key = indexOfEquals > 0 ?
                                line.substring(0,indexOfEquals).trim():
                                    line.trim();
View Full Code Here

      IHasTimeZone tz = (IHasTimeZone) log.getAdapter(IHasTimeZone.class);
      if (tz != null) {
        // Apply the timezone
        getPatternTranslator().applyTimeZone(tz.getTimeZone(), rules);
      }
      LineIterator iter = IOUtils.lineIterator(input, enc.getEncoding());
      int minLinesPerEntry = getPatternTranslator().getMinLinesPerEntry();
      int lineNo = 0;
      int moreLinesToCome = 0;
      try {
        String line = null;
        while (iter.hasNext()) {
          lineNo++;
         
          if (minLinesPerEntry == 1) {
            // Simple case
            line = iter.nextLine();
          } else {
            String s = iter.nextLine();
            if (moreLinesToCome == 0) {
              Matcher m = getInternalPatternFirstLine().matcher(s);
              if (m.find()) {
                // First line
                line = s;
                moreLinesToCome = minLinesPerEntry - 1;
                continue;
              } else {
                // Some crazy stuff
                line = s;
              }
            } else if (iter.hasNext() && (moreLinesToCome > 1)) {
              // Some middle line
              line += IOUtils.LINE_SEPARATOR + s;
              moreLinesToCome--;
              continue;
            } else {
              // Last line
              line += IOUtils.LINE_SEPARATOR + s;
              if (!iter.hasNext()) {
                line += IOUtils.LINE_SEPARATOR;
              }
              moreLinesToCome = 0;
            }
          }
View Full Code Here

      LogEntry currentEntry = null;
      IHasEncoding enc = (IHasEncoding) log.getAdapter(IHasEncoding.class);
      IHasLocale loc = (IHasLocale) log.getAdapter(IHasLocale.class);
      // WebSphere Dialect doesn't need to care about the timezone, because it is encoded in the log messages
      DateFormat df = getDateFormat(loc.getLocale());
      LineIterator iter = IOUtils.lineIterator(input, enc.getEncoding());
      int lineNo = 0;
      try {
        while (iter.hasNext()) {
          // Error handling
          lineNo++;
          List<IStatus> statuses = null;
          boolean fatal = false; // determines whether to interrupt parsing
         
          String line = iter.nextLine();
          Matcher m = getInternalPattern().matcher(line);
          if (m.find()) {
            // The next line matches, so flush the previous entry and continue
            if (currentEntry != null) {
              collector.collect(currentEntry);
View Full Code Here

TOP

Related Classes of org.apache.commons.io.LineIterator

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.