Java 类com.google.common.io.LineProcessor 实例源码

项目:n4js    文件:PositiveAnalyser.java   
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());
    }
}
项目:jug-material    文件:FileProcessingTest.java   
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;
}
项目:purplejs    文件:CoreLibHelper.java   
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;
        }
    } );
}
项目:blockplus    文件:PolyominosTest.java   
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;
            }
        });
    }
项目:hawkbit    文件:BulkUploadHandler.java   
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);
}
项目:metasfresh    文件:FileImportReader.java   
/**
 * 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;
}
项目:mclab-core    文件:Rewrites.java   
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;
    }
  });
}
项目:tassal    文件:TextFileUtils.java   
/**
 * 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;
                }
            });
}
项目:bue-common-open    文件:StringUtils.java   
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();
}
项目:excalibur    文件:ParserReader.java   
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;
        }
    });
}
项目:jg2p    文件:InputReader.java   
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;
    }
  });
}
项目:java-extended    文件:ResourcesTest.java   
@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"));
}
项目:java-extended    文件:ResourcesTest.java   
@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;
        }
    });
}
项目:codemining-utils    文件:TextFileUtils.java   
/**
 * 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;
                }
            });
}
项目:takari-lifecycle    文件:DependencyClasspathEntry.java   
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);
}
项目:log-synth    文件:VinSampler.java   
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;
        }
    });
}
项目:log-synth    文件:VinSampler.java   
private static SetMultimap<String, String> multiMapResource(String name) throws IOException {
    final Splitter onTab = Splitter.on("\t");

    return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<SetMultimap<String, String>>() {
        final SetMultimap<String, String> r = HashMultimap.create();

        @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 SetMultimap<String, String> getResult() {
            return r;
        }
    });
}
项目:levelup-java-examples    文件:CountLinesTextFile.java   
@Test
public void count_lines_text_file_guava() throws IOException {

    long linesCounted = com.google.common.io.Files.readLines(
            Paths.get(fileLocation).toFile(), Charsets.UTF_8,
            new LineProcessor<Long>() {

                long numberOfLinesInTextFile = 0;

                @Override
                public boolean processLine(String line) throws IOException {

                    numberOfLinesInTextFile++;
                    return true;
                }

                @Override
                public Long getResult() {
                    return numberOfLinesInTextFile;
                }
            });

    assertEquals(10, linesCounted);
}
项目:BSPAT    文件:QueryRefGenome.java   
private StringBuilder loadRefGenome(String refGenomePath, String chr) throws IOException {
    return CharStreams.readLines(new FileReader(String.format("%s/%s.fa", refGenomePath, chr)),
            new LineProcessor<StringBuilder>() {
                StringBuilder refChrBuilder = new StringBuilder(100000000);

                @Override
                public boolean processLine(String s) throws IOException {
                    if (!s.startsWith(">")) {
                        refChrBuilder.append(s);
                    }
                    return true;
                }

                @Override
                public StringBuilder getResult() {
                    return refChrBuilder;
                }
            });
}
项目:basking    文件:WriteCacheFileTask.java   
/**
 * Returns a new line processor for the cache file. The processor generates map of song IDs to
 * file names.
 */
static LineProcessor<Map<Integer, String>> newCacheFileLineProcessor() {
    return new LineProcessor<Map<Integer, String>>() {

        @SuppressWarnings("CanBeFinal")
        Map<Integer, String> map = Maps.newHashMap();

        @Override
        public boolean processLine(String line) throws IOException {
            String[] split = line.split("\\|");
            map.put(Integer.valueOf(split[0]), split[1]);
            return true;
        }

        @Override
        public Map<Integer, String> getResult() {
            return map;
        }
    };
}
项目:mclab    文件:Refactorings.java   
public static <T extends Reader> List<Refactoring>
    fromInputSupplier(InputSupplier<T> supplier) throws IOException{
  return CharStreams.readLines(supplier,  new LineProcessor<List<Refactoring>>() {
    private List<Refactoring> refactorings = Lists.newArrayList();
    private final Splitter SPLITTER = Splitter.on("->").trimResults().omitEmptyStrings();

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

    @Override
    public boolean processLine(String line) {
      Iterator<String> parts = SPLITTER.split(line).iterator();
      String from = parts.next();
      String to = parts.next();
      refactorings.add(Refactoring.of(from, to, Refactoring.Visit.Expressions));
      return true;
    }
  });
}
项目:oma-riista-web    文件:CodeStyleTest.java   
@Test
public void verifySourceFilesDoNotContainTabCharacters() throws IOException {
    final Iterator<File> iter = FileUtils.iterateFiles(new File("src"), new CodeStyleFileFilter(), TrueFileFilter.INSTANCE);

    final List<String> filesContainingTabs = new ArrayList<>();

    while (iter.hasNext()) {
        final File file = iter.next();
        Files.readLines(file, StandardCharsets.US_ASCII, new LineProcessor<Void>() {
            @Override
            public boolean processLine(@Nonnull final String line) throws IOException {
                boolean result = true;
                if (line.contains("\t")) {
                    filesContainingTabs.add(file.getCanonicalPath());
                    result = false;
                }
                return result;
            }

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

    assertEmpty(filesContainingTabs, "The following files contain tab characters: ");
}
项目:Alchemy    文件:NonUpdate.java   
public static ImmutableList<String> getWhiteList() {
    File file = new File("nu-whitelist.txt");
    try {
        return Files.readLines(file, Charsets.UTF_8, new LineProcessor<ImmutableList<String>>() {

            List<String> result = Lists.newLinkedList();

            @Override
            public boolean processLine(String line) {
                if (!line.startsWith("#") && !line.isEmpty())
                    result.add(line);
                return true;
            }

            @Override
            public ImmutableList<String> getResult() {
                return ImmutableList.copyOf(result);
            }

        });
    } catch (IOException e) {
        if (!file.isFile())
            try {
                if (file.createNewFile()) {
                    String whitelist = Joiner.on('\n').join(DEFAULT_WHITE_LIST);
                    logger.info("Create file: nu-whitelist.txt\n" + whitelist);
                    Files.write(whitelist, file, Charsets.UTF_8);
                    return DEFAULT_WHITE_LIST;
                }
            } catch (IOException ex) { ex.printStackTrace(); }
        return ImmutableList.of();
    }
}
项目:react-java-goos    文件:GooGoo.java   
/**
 * 读取模版文件并做变量替换
 */
private static List<String> renderTemplate(String templateFileName, final Map<String, String> params) throws MalformedURLException, IOException {
    final Pattern p = Pattern.compile("\\{(.*?)\\}");
    // 定义每行的处理逻辑
    LineProcessor<List<String>> processor = new LineProcessor<List<String>>() {

        private List<String> result = Lists.newArrayList();

        @Override
        public boolean processLine(String line) throws IOException {
            String tmp = line;
            Matcher m = p.matcher(line);
            while (m.find()) {
                String key = m.group(1);
                if (params.containsKey(key)) {
                    tmp = tmp.replaceAll("\\{" + key + "\\}", params.get(key));
                }
            }

            result.add(tmp);
            return true;
        }

        @Override
        public List<String> getResult() {
            return result;
        }
    };

    return Resources.readLines(Resources.getResource(templateFileName), Charsets.UTF_8, processor);
}
项目:ch.vorburger.minecraft.osgi    文件:FileNewsRepository.java   
private List<News> load() throws IOException {
    if (!file.exists()) {
        return new ArrayList<>();
    }
    return Files.readLines(file, CHARSET, new LineProcessor<List<News>>() {

        List<News> loadedNews = new ArrayList<>();

        @Override
        public boolean processLine(String line) throws IOException {
            try {
                line = line.trim();
                if (!line.isEmpty()) {
                    int indexOfSpace1 = line.indexOf(' ');
                    String createdAsString = line.substring(0, indexOfSpace1);
                    int indexOfSpace2 = line.indexOf(' ', indexOfSpace1 + 1);
                    String uuidAsString = line.substring(indexOfSpace1 + 1, indexOfSpace2);
                    String textAsString = line.substring(indexOfSpace2 + 1);

                    Instant createdOn = dateTimeFormatter.parse(createdAsString, Instant::from);
                    UUID uuid = UUID.fromString(uuidAsString);
                    User byUser = getUser(uuid);
                    Text message = textSerializer.deserialize(textAsString);

                    loadedNews.add(ImmutableNews.builder().createdOn(createdOn).author(byUser).message(message).build());
                }
                return true;
            } catch (StringIndexOutOfBoundsException | DateTimeParseException | TextParseException | UserNotFoundException e) {
                throw new IOException("Failed to read line of file " + file + ": " + line, e);
            }
        }

        @Override
        public List<News> getResult() {
            return loadedNews;
        }
    });
}
项目:FastBuild    文件:ReobfExceptor.java   
private Map<String, String> readCSVs() throws IOException {
    final Map<String, String> csvData = Maps.newHashMap();
    File[] csvs = new File[]
            {
                    fieldCSV == null ? null : fieldCSV,
                    methodCSV == null ? null : methodCSV
            };

    for (File f : csvs) {
        if (f == null) continue;

        Files.readLines(f, Charset.defaultCharset(), new LineProcessor<Object>() {
            @Override
            public boolean processLine(String line) throws IOException {
                String[] s = line.split(",");
                csvData.put(s[0], s[1]);
                return true;
            }

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

    return csvData;
}
项目:FastBuild    文件:ReobfExceptor.java   
private Map<String, String> createClassMap(Map<String, String> markerMap, final List<String> interfaces) throws IOException {
    Map<String, String> excMap = Files.readLines(excConfig, Charset.defaultCharset(), new LineProcessor<Map<String, String>>() {
        Map<String, String> tmp = Maps.newHashMap();

        @Override
        public boolean processLine(String line) throws IOException {
            if (line.contains(".") ||
                    !line.contains("=") ||
                    line.startsWith("#")) return true;

            String[] s = line.split("=");
            if (!interfaces.contains(s[0])) tmp.put(s[0], s[1] + "_");

            return true;
        }

        @Override
        public Map<String, String> getResult() {
            return tmp;
        }
    });

    Map<String, String> map = Maps.newHashMap();
    for (Entry<String, String> e : excMap.entrySet()) {
        String renamed = markerMap.get(e.getValue());
        if (renamed != null) {
            map.put(e.getKey(), renamed);
        }
    }
    return map;
}
项目:benayn    文件:Sources.java   
/**
 * @see com.google.common.io.LineProcessor
 * @see com.google.common.io.Resources#getResource(String)
 * @see com.google.common.io.Resources#readLines(URL, Charset, LineProcessor)
 */
public static <T> T getResourceWith(String resourceName, LineProcessor<T> lineProcessor) {
    checkNotNull(lineProcessor);
    URL url = Resources.getResource(checkNotEmpty(resourceName));
    try {
        return Resources.readLines(url, Charsets.UTF_8, lineProcessor);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
项目:Review-It    文件:Indexer.java   
private CharArraySet getStopWordSet() {
    File stopWordsFile = new File(Configuration.getInstance().getStopWord());
    try {
        return Files.readLines(stopWordsFile,
                Charsets.UTF_8,

                new LineProcessor<CharArraySet>() {
                    CharArraySet result = new CharArraySet(Configuration
                                                .getInstance()
                                                .getStopWordSize(), true);

                    @Override
                    public CharArraySet getResult() {
                        return result;
                    }

                    @Override
                    public boolean processLine(String line) {
                        if (Strings.isNotBlank(line)) {
                            result.add(line.trim());
                        }
                        return true;
                    }
                });
    } catch (IOException e) {
        throw new RuntimeException("Unable to find  Stopwords file: ", e);
    }
}
项目:SrgLib    文件:MappingsFormat.java   
default Mappings parse(Readable readable) throws IOException {
    LineReader lineReader = new LineReader(readable);
    LineProcessor<Mappings> lineProcessor = createLineProcessor();
    String line;
    while ((line = lineReader.readLine()) != null) {
        if (!lineProcessor.processLine(line)) {
            break;
        }
    }
    return lineProcessor.getResult();
}
项目:bue-common-open    文件:MultitableLoader.java   
private void loadToMultitable(final CharSource source,
    final ImmutableMultitable.Builder<R, C, V> ret) throws IOException {
  source.readLines(new LineProcessor<Void>() {
    @Override
    public boolean processLine(final String line) throws IOException {
      final List<String> fields = fieldSplitter().splitToList(line);
      if (fields.size() == 3) {
        final R rowKey = interpret(fields.get(0), rowInterpreter(), "row key", line);
        final C columnKey = interpret(fields.get(1), columnInterpreter(), "column key", line);

        if (valueListSplitter().isPresent()) {
          for (final String value : valueListSplitter().get().split(fields.get(2))) {
            ret.put(rowKey, columnKey, interpret(value, valueInterpreter(), "value", line));
          }
        } else {
          ret.put(rowKey, columnKey, interpret(fields.get(2), valueInterpreter(), "value", line));
        }
      } else {
        throw new IOException("Cannot parse lines as multitable entries:\n" + line);
      }
      // we never stop procesisng lines early
      return true;
    }

    @Override
    public Void getResult() {
      return null;
    }
  });
}
项目:dohko    文件:IOUtils2.java   
/**
 * Reads all of the lines from an {@link InputStream} object. The lines include the line-termination characters, and also include other leading
 * and trailing whitespace.
 * <p>
 * Does not close the {@code InputStream}.
 * 
 * @param is The stream to read from.
 * @throws IOException if an I/O error occurs.
 */
public static String readLines(InputStream is) throws IOException
{
    InputStreamReader isr = new InputStreamReader(is);
    try
    {
        return CharStreams.readLines(isr, new LineProcessor<String>()
        {
            final StringBuilder lines = new StringBuilder();

            @Override
            public boolean processLine(String line) throws IOException
            {
                lines.append(line).append(Strings2.NEW_LINE);
                return true;
            }

            @Override
            public String getResult()
            {
                return lines.toString();
            }
        });
    }
    finally
    {
        closeQuietly(isr);
    }
}
项目:excalibur    文件:AppTest.java   
public static void main(String[] args) throws IOException {

        AvscSchemaBuilder asb = new AvscSchemaBuilder(Metric.class);
        final DataFileWriter<Metric2> dataFileWriter = new DataFileWriter<Metric2>(new SpecificDatumWriter<Metric2>(asb.createSchema()));
        dataFileWriter.create(asb.createSchema(), new File("v1.avro"));
        Path p = Paths.get("v1.log");
        Files.readLines(p.toFile(), Charset.defaultCharset(), new LineProcessor<String>() {
            @Override
            public boolean processLine(String line) throws IOException {
                String[] vals = line.split(" ");
                Metric2 mc =
                        Metric2.builder().dataVersion(Integer.valueOf(vals[0])).salt(Integer.valueOf(vals[1])).applicationId(Long.valueOf(vals[2]))
                                .timeScope(Integer.valueOf(vals[3])).metricTypeId(Long.valueOf(vals[4])).metricId(Long.valueOf(vals[5])).time(Integer.valueOf(vals[6]))
                                .agentRunId(Long.valueOf(vals[7])).uuid(vals[8]).num1(Double.valueOf(vals[9])).num2(Double.valueOf(vals[10])).num3(Double.valueOf(vals[11]))
                                .num4(Double.valueOf(vals[12])).num5(Double.valueOf(vals[13])).num6(Double.valueOf(vals[14])).timestamp(Long.valueOf(vals[15])).build();
                dataFileWriter.append(mc);
                return true;
            }

            @Override
            public String getResult() {
                return null;
            }
        });
        dataFileWriter.flush();
        dataFileWriter.close();
    }
项目:excalibur    文件:BaseReader.java   
public void handle() throws IOException {
    Files.readLines(Paths.get(sourceDataFilePath).toFile(), Charset.defaultCharset(), new LineProcessor<String>() {
        @Override public boolean processLine(String line) throws IOException {
            service.addRecord("A", "a", System.currentTimeMillis(), Long.valueOf(line));
            return true;
        }

        @Override public String getResult() {
            return null;
        }
    });
    service.shuffle(service.acquireAllData(), resultDataFilePath);
}
项目:excalibur    文件:WindowHistogramReader.java   
public void handle() throws IOException {
    Files.readLines(Paths.get(sourceDataFilePath).toFile(), Charset.defaultCharset(), new LineProcessor<String>() {
        @Override public boolean processLine(String line) throws IOException {
            String[] splits = line.split(" ");
            service.addRecord("A", "a", Long.valueOf(splits[0]), Long.valueOf(splits[1]));
            return true;
        }

        @Override public String getResult() {
            return null;
        }
    });
    service.shuffle(service.acquireAllData(), resultDataFilePath);
}
项目:jg2p    文件:SeqInputReader.java   
public List<AlignGroup> readInput(CharSource source) throws IOException {
  return source.readLines(new LineProcessor<List<AlignGroup>>() {

    final List<AlignGroup> groups = Lists.newArrayList();
    String lastGroup = "";
    List<Alignment> aligns = Lists.newArrayList();

    @Override
    public boolean processLine(String line) throws IOException {
      List<String> fields = caretSplit.splitToList(line);
      if (!lastGroup.equals(fields.get(0))) {
        lastGroup = fields.get(0);
        if (!aligns.isEmpty()) {
          groups.add(new AlignGroup(aligns));
        }
        aligns.clear();
      }
      Double score = Double.parseDouble(fields.get(1));
      Word input = Word.fromSpaceSeparated(fields.get(2));
      Iterable<String> graphs = pipeSplit.split(fields.get(3));
      Iterable<String> phones = pipeSplit.split(fields.get(4));

      aligns.add(new Alignment(input, Zipper.up(graphs, phones), score));
      return true;
    }

    @Override
    public List<AlignGroup> getResult() {
      if (!aligns.isEmpty()) {
        groups.add(new AlignGroup(aligns));
      }
      return groups;
    }
  });
}
项目:TopK    文件:TopKTest.java   
@Test
public void testText() throws IOException {

    final int k = 200;

    final ReferenceTopK<String> ref = new ReferenceTopK<>(k);
    final DeterministicTopK<String> det = new DeterministicTopK<>(k);
    final Pattern pattern = Pattern.compile("[\\p{Punct}\\p{Space}]");

    Resources.readLines(Resources.getResource("alice.txt"), Charsets.UTF_8, new LineProcessor<Void>() {

        @Override
        public boolean processLine(String line) throws IOException {
            Scanner scanner = new Scanner(line).useDelimiter(pattern);
            while (scanner.hasNext()) {
                String item = scanner.next().toLowerCase();
                ref.add(item);
                det.add(item);
            }
            return true;
        }

        @Override
        public Void getResult() {
            return null;
        }
    });
    Iterable<String> a = det.get();
    Iterable<String> b = ref.get();

    System.out.format("Ref: %s%n", ref);
    System.out.format("Det: %s%n", det);

    List<String> detSet = ImmutableList.copyOf(Iterables.limit(det.get(), 20));
    List<String> refSet = ImmutableList.copyOf(Iterables.limit(ref.get(), 20));
    assertThat(detSet, equalTo(refSet));
}
项目:java-extended    文件:Resources.java   
/**
 * @param contextClass  the class the resource is relative to
 * @param resourceName  the resource name
 * @param lineProcessor the line processor to use
 * @param <T>           the type of object to load into
 * @return the loaded object of type <tt>T</tt>
 * @see com.google.common.io.LineProcessor
 * @see com.google.common.io.Resources#getResource(String)
 * @see com.google.common.io.Resources#readLines(java.net.URL, java.nio.charset.Charset, LineProcessor)
 */
public static <T> T getResourceWith(Class<?> contextClass, String resourceName, LineProcessor<T> lineProcessor) {
    checkArgument(contextClass != null, "Expected non-null contextClass");
    checkNotEmpty(resourceName);
    checkArgument(lineProcessor != null, "Expected non-null lineProcessor");

    URL url = getResource(contextClass, resourceName);
    try {
        return readLines(url, UTF_8, lineProcessor);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
项目:nicta-ner    文件:IO.java   
private static <T> T readResource(final Class<?> origin, final String resource,
                                  final LineProcessor<T> processor) throws IOException {
    try { return readLines(getResource(origin, resource), UTF_8, processor); }
    catch (final IOException ioe) {
        throw new IOException("Error reading resource: '" + resource + "'", ioe);
    }
}
项目:swmutsel    文件:ArgumentsProcessor.java   
private static String[] mergeFileArguments(final String[] rawArguments) {

        List<String> arguments = Lists.newArrayList();

        for (String arg : rawArguments) {
            // If we've been given an input file
            if (arg.startsWith("@")) {
                String filename = arg.substring(1);
                try {
                    List<String> nonCommentLines = Files.readLines(new File(filename), Charset.defaultCharset(), new LineProcessor<List<String>>() {
                        List<String> lines = Lists.newArrayList();

                        @Override
                        public boolean processLine(String line) throws IOException {
                            // This is the end of the file
                            if (line.startsWith("//")) return false;
                            // Ignore comments and empty lines, ignore everything after a comment
                            if (!line.startsWith("#") && line.length() > 0) lines.add(line.split("#")[0]);
                            return true;
                        }

                        @Override
                        public List<String> getResult() {
                            return lines;
                        }
                    });

                    arguments.addAll(nonCommentLines);

                } catch (IOException e) {
                    CoreUtils.msg("ERROR: Could not read file '%s'\n", arg.substring(1));
                }

            } else {
                arguments.add(arg);
            }
        }

        return arguments.toArray(new String[arguments.size()]);
    }