當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。