当前位置: 首页>>代码示例>>Java>>正文


Java LineProcessor类代码示例

本文整理汇总了Java中com.google.common.io.LineProcessor的典型用法代码示例。如果您正苦于以下问题:Java LineProcessor类的具体用法?Java LineProcessor怎么用?Java LineProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LineProcessor类属于com.google.common.io包,在下文中一共展示了LineProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: withLineNumbers

import com.google.common.io.LineProcessor; //导入依赖的package包/类
private String withLineNumbers(String code) {
	try {
		return CharStreams.readLines(new StringReader(code), new LineProcessor<String>() {

			private final StringBuilder lines = new StringBuilder();
			private int lineNo = 1;

			@Override
			public boolean processLine(String line) throws IOException {
				lines.append(Strings.padStart(String.valueOf(lineNo++), 3, ' ')).append(": ").append(line)
						.append("\n");
				return true;
			}

			@Override
			public String getResult() {
				return lines.toString();
			}
		});
	} catch (IOException e) {
		throw new IllegalStateException(e.getMessage());
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:24,代码来源:PositiveAnalyser.java

示例2: findFirst10Errors_guava

import com.google.common.io.LineProcessor; //导入依赖的package包/类
private List<String> findFirst10Errors_guava(File file) throws IOException {
	List<String> lines = Files.readLines(file, Charsets.UTF_8, new LineProcessor<List<String>>() {
		List<String> accumulator = new ArrayList<String>();
		
		@Override
		public boolean processLine(String line) throws IOException {
			if (line.startsWith(ERROR_PREFIX)) {
				accumulator.add(line);
			}
			return accumulator.size() < 10;
		}

		@Override
		public List<String> getResult() {
			return accumulator;
		}
	});
	return lines;
}
 
开发者ID:notsojug,项目名称:jug-material,代码行数:20,代码来源:FileProcessingTest.java

示例3: processLines

import com.google.common.io.LineProcessor; //导入依赖的package包/类
public void processLines( final Object stream, final Consumer<String> callback )
    throws Exception
{
    final CharSource source = toCharSource( stream );
    source.readLines( new LineProcessor<Object>()
    {
        @Override
        public boolean processLine( final String line )
            throws IOException
        {
            callback.accept( line );
            return true;
        }

        @Override
        public Object getResult()
        {
            return null;
        }
    } );
}
 
开发者ID:purplejs,项目名称:purplejs,代码行数:22,代码来源:CoreLibHelper.java

示例4: load

import com.google.common.io.LineProcessor; //导入依赖的package包/类
private static List<String> load(final String path) throws IOException {

        return Files.readLines(new File(path), Charsets.UTF_8, new LineProcessor<List<String>>() {

            private final List<String> result = Lists.newArrayList();
            private final StringBuilder stringBuilder = new StringBuilder();

            @Override
            public boolean processLine(final String line) throws IOException {
                if (line.isEmpty()) {
                    if (this.stringBuilder.length() > 0)
                        this.stringBuilder.deleteCharAt(this.stringBuilder.length() - 1);
                    this.result.add(this.stringBuilder.toString());
                    this.stringBuilder.setLength(0);
                }
                else this.stringBuilder.append(line).append("\n");
                return true;
            }

            @Override
            public List<String> getResult() {
                return this.result;
            }
        });
    }
 
开发者ID:arie-benichou,项目名称:blockplus,代码行数:26,代码来源:PolyominosTest.java

示例5: getTotalNumberOfLines

import com.google.common.io.LineProcessor; //导入依赖的package包/类
private BigDecimal getTotalNumberOfLines() {
    try {
        return new BigDecimal(Files.readLines(tempFile, Charset.defaultCharset(), new LineProcessor<Integer>() {
            private int count;

            @Override
            public Integer getResult() {
                return count;
            }

            @Override
            public boolean processLine(final String line) {
                count++;
                return true;
            }
        }));

    } catch (final IOException e) {
        LOG.error("Error while reading temp file for upload.", e);
    }

    return new BigDecimal(0);
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:24,代码来源:BulkUploadHandler.java

示例6: readRegularLines

import com.google.common.io.LineProcessor; //导入依赖的package包/类
/**
 * Read file that has not any multi-line text
 * 
 * @param file
 * @param charset
 * @return
 * @throws IOException
 */
public List<String> readRegularLines(@NonNull final File file, @NonNull final Charset charset) throws IOException
{
	final List<String> loadedDataLines = new ArrayList<>();

	Files.readLines(file, charset, new LineProcessor<Void>()
	{
		@Override
		public boolean processLine(final String line) throws IOException
		{
			loadedDataLines.add(line);
			return true;
		}

		@Override
		public Void getResult()
		{
			return null;
		}
	});

	return loadedDataLines;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:31,代码来源:FileImportReader.java

示例7: fromCharSource

import com.google.common.io.LineProcessor; //导入依赖的package包/类
public static List<Rewrite> fromCharSource(CharSource source) throws IOException {
  return source.readLines(new LineProcessor<List<Rewrite>>() {
    private List<Rewrite> refactorings = new ArrayList<>();
    private final Splitter SPLITTER = Splitter.on("->").trimResults().omitEmptyStrings();

    @Override
    public List<Rewrite> getResult() {
      return Collections.unmodifiableList(refactorings);
    }

    @Override
    public boolean processLine(String line) {
      List<String> parts = SPLITTER.splitToList(line);
      refactorings.add(Rewrite.of(parts.get(0), parts.get(1), Rewrite.Visit.Expressions));
      return true;
    }
  });
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:19,代码来源:Rewrites.java

示例8: numberOfLinesInFile

import com.google.common.io.LineProcessor; //导入依赖的package包/类
/**
 * Return the number of lines in this file.
 * 
 * @param f
 * @return
 * @throws IOException
 */
public static int numberOfLinesInFile(final File f) throws IOException {
	return Files.readLines(f, Charset.defaultCharset(),
			new LineProcessor<Integer>() {
				int count = 0;

				@Override
				public Integer getResult() {
					return count;
				}

				@Override
				public boolean processLine(final String line) {
					count++;
					return true;
				}
			});
}
 
开发者ID:mast-group,项目名称:tassal,代码行数:25,代码来源:TextFileUtils.java

示例9: stringSetFrom

import com.google.common.io.LineProcessor; //导入依赖的package包/类
public static Set<String> stringSetFrom(final CharSource supplier) throws IOException {
  final LineProcessor<Set<String>> callback = new LineProcessor<Set<String>>() {
    private final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    @Override
    public boolean processLine(final String s) {
      builder.add(s.trim());
      return true;
    }

    @Override
    public Set<String> getResult() {
      return builder.build();
    }
  };

  supplier.readLines(callback);
  return callback.getResult();
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:20,代码来源:StringUtils.java

示例10: parse

import com.google.common.io.LineProcessor; //导入依赖的package包/类
public void parse() throws Exception {
    Files.readLines(Paths.get(path).toFile(), Charset.defaultCharset(), new LineProcessor<String>() {
        @Override public boolean processLine(String line) throws IOException {
            HistogramResult result = JSON.parseObject(line, HistogramResult.class);
            String histogramString = result.getHistogram();
            System.out.println(histogramString);
            ByteBuffer buffer = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(histogramString));
            try {
                Histogram histogram = Histogram.decodeFromCompressedByteBuffer(buffer, 0);
                histogram.setStartTimeStamp(result.getStartTime());
                histogram.setEndTimeStamp(result.getEndTime());
                //TODO
            } catch (DataFormatException e) {
                e.printStackTrace();
            }
            return true;
        }

        @Override public String getResult() {
            return null;
        }
    });
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:24,代码来源:ParserReader.java

示例11: read

import com.google.common.io.LineProcessor; //导入依赖的package包/类
public List<InputRecord> read(CharSource source) throws IOException {
  return source.readLines(new LineProcessor<List<InputRecord>>() {
    private final List<InputRecord> recs = Lists.newArrayList();

    @Override
    public boolean processLine(String line) throws IOException {
      if (isBlank(line)) {
        return true;
      }
      if (isComment(line)) {
        return true;
      }

      InputRecord maybe = reader.parse(line);
      if (maybe != null) {
        recs.add(maybe);
      }
      return true;
    }

    @Override
    public List<InputRecord> getResult() {
      return recs;
    }
  });
}
 
开发者ID:steveash,项目名称:jg2p,代码行数:27,代码来源:InputReader.java

示例12: shouldGetResourceWithLineProcessorFromContext

import com.google.common.io.LineProcessor; //导入依赖的package包/类
@Test
public void shouldGetResourceWithLineProcessorFromContext() throws Exception {
    // given
    String classResource = "../base/Either.class";

    // when
    String classString = getResourceWith(Resources.class, classResource, new LineProcessor<String>() {
        StringBuilder builder = new StringBuilder();

        @Override
        public boolean processLine(String line) throws IOException {
            builder.append(line).append("\n");
            return true;
        }

        @Override
        public String getResult() {
            return builder.toString();
        }
    });

    // then
    assertThat(classString, isNotEmptyString());
    assertThat(classString, containsString("com/bluecatcode/common/base/Either"));
}
 
开发者ID:pawelprazak,项目名称:java-extended,代码行数:26,代码来源:ResourcesTest.java

示例13: shouldWrapExceptionInGetResourceWithLineProcessorFromContext

import com.google.common.io.LineProcessor; //导入依赖的package包/类
@Test
public void shouldWrapExceptionInGetResourceWithLineProcessorFromContext() throws Exception {
    // given
    String classResource = "../base/Either.class";

    // expect
    exception.expect(IllegalStateException.class);

    // when
    getResourceWith(Resources.class, classResource, new LineProcessor<String>() {

        @Override
        public boolean processLine(String line) throws IOException {
            throw new IOException("test");
        }

        @Override
        public String getResult() {
            return null;
        }
    });
}
 
开发者ID:pawelprazak,项目名称:java-extended,代码行数:23,代码来源:ResourcesTest.java

示例14: parseExportPackage

import com.google.common.io.LineProcessor; //导入依赖的package包/类
protected static Collection<String> parseExportPackage(InputStream is) throws IOException {
  LineProcessor<List<String>> processor = new LineProcessor<List<String>>() {
    final List<String> result = new ArrayList<String>();

    @Override
    public boolean processLine(String line) throws IOException {
      result.add(line.replace('.', '/'));
      return true; // keep reading
    }

    @Override
    public List<String> getResult() {
      return result;
    }
  };
  return CharStreams.readLines(new InputStreamReader(is, Charsets.UTF_8), processor);
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:18,代码来源:DependencyClasspathEntry.java

示例15: mapResource

import com.google.common.io.LineProcessor; //导入依赖的package包/类
private static Map<String, String> mapResource(String name) throws IOException {
    final Splitter onTab = Splitter.on("\t");

    return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<Map<String, String>>() {
        final Map<String, String> r = Maps.newHashMap();

        @Override
        public boolean processLine(String line) throws IOException {
            Iterator<String> pieces = onTab.split(line).iterator();
            String key = pieces.next();
            r.put(key, pieces.next());
            return true;
        }

        @Override
        public Map<String, String> getResult() {
            return r;
        }
    });
}
 
开发者ID:tdunning,项目名称:log-synth,代码行数:21,代码来源:VinSampler.java


注:本文中的com.google.common.io.LineProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。