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


Java CharSource类代码示例

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


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

示例1: processLines

import com.google.common.io.CharSource; //导入依赖的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

示例2: identicalFileIsAlreadyGenerated

import com.google.common.io.CharSource; //导入依赖的package包/类
private boolean identicalFileIsAlreadyGenerated(CharSequence sourceCode) {
  try {
    String existingContent = new CharSource() {
      final String packagePath = !key.packageName.isEmpty() ? (key.packageName.replace('.', '/') + '/') : "";
      final String filename = key.relativeName + ".java";

      @Override
      public Reader openStream() throws IOException {
        return getFiler()
            .getResource(StandardLocation.SOURCE_OUTPUT,
                "", packagePath + filename)
            .openReader(true);
      }
    }.read();

    if (existingContent.contentEquals(sourceCode)) {
      // We are ok, for some reason the same file is already generated,
      // happens in Eclipse for example.
      return true;
    }
  } catch (Exception ignoredAttemptToGetExistingFile) {
    // we have some other problem, not an existing file
  }
  return false;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Output.java

示例3: main

import com.google.common.io.CharSource; //导入依赖的package包/类
public static void main(String[] argv) throws IOException {
  if (argv.length != 1) {
    usage();
  }

  final Parameters params = Parameters.loadSerifStyle(new File(argv[0]));

  final File docIdToFileMapFile = params.getExistingFile("docIdToFileMap");
  final File filterFile = params.getCreatableFile("quoteFilter");

  final Map<Symbol, CharSource> docIdToFileMap = FileUtils.loadSymbolToFileCharSourceMap(
      Files.asCharSource(docIdToFileMapFile, Charsets.UTF_8));

  log.info("Building quote filter from {} documents in {}", docIdToFileMap.size(),
      docIdToFileMapFile);

  final QuoteFilter quoteFilter = QuoteFilter.createFromOriginalText(docIdToFileMap);
  log.info("Writing quote filter to {}", filterFile);
  quoteFilter.saveTo(Files.asByteSink(filterFile));
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:21,代码来源:BuildQuoteFilter.java

示例4: loadCorpusEventFrames

import com.google.common.io.CharSource; //导入依赖的package包/类
@Override
public CorpusEventLinking loadCorpusEventFrames(final CharSource source)
    throws IOException {
  int lineNo = 1;
  try (final BufferedReader in = source.openBufferedStream()) {
    final ImmutableSet.Builder<CorpusEventFrame> ret = ImmutableSet.builder();
    String line;
    while ((line = in.readLine()) != null) {
      if (!line.isEmpty() && !line.startsWith("#")) {
        // check for blank or comment lines
        ret.add(parseLine(line));
      }
    }
    return CorpusEventLinking.of(ret.build());
  } catch (Exception e) {
    throw new IOException("Error on line " + lineNo + " of " + source, e);
  }
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:19,代码来源:CorpusEventLinkingIO2016.java

示例5: testQuotedRegionComputation

import com.google.common.io.CharSource; //导入依赖的package包/类
@Test
public void testQuotedRegionComputation() throws IOException {
  final Map<String, ImmutableRangeSet<Integer>> testCases = ImmutableMap.of(
      "Foo <quote>bar <quote>baz</quote> <quote>meep</quote></quote> blah <quote>another</quote>",
      ImmutableRangeSet.<Integer>builder().add(Range.closed(4, 60)).add(Range.closed(67, 88))
          .build(),
      "<quote>lalala</quote>", ImmutableRangeSet.of(Range.closed(0, 20)),
      "No quotes!", ImmutableRangeSet.<Integer>of());

  for (final Map.Entry<String, ImmutableRangeSet<Integer>> entry : testCases.entrySet()) {
    final Symbol docid = Symbol.from("dummy");

    final QuoteFilter reference =
        QuoteFilter.createFromBannedRegions(ImmutableMap.of(docid, entry.getValue()));
    final QuoteFilter computed = QuoteFilter.createFromOriginalText(ImmutableMap.of(docid,
        CharSource.wrap(entry.getKey())));

    assertEquals(reference, computed);
  }
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:21,代码来源:TestQuoteFilter.java

示例6: loadDictionary

import com.google.common.io.CharSource; //导入依赖的package包/类
/**
 * Load the word frequency list, skipping words that are not in the given white list.
 *
 * @param  whitelist The white list.
 * @return A Dictomation dictionary with the word probabilities.
 * @throws IOException
 * @throws DictionaryBuilderException
 */
public static DictomatonDictionary loadDictionary(Set<String> whitelist) throws IOException, DictionaryBuilderException {
    CharSource source = getResource(WORD_FREQUENCIES_FILE);

    DictomatonDictionary dictomatonDictionary;
    BufferedReader reader = source.openBufferedStream();
    try {
        if (whitelist == null) {
            dictomatonDictionary = DictomatonDictionary.read(reader);
        } else {
            dictomatonDictionary = DictomatonDictionary.read(reader, whitelist);
        }
    } finally {
        reader.close();
    }
    return dictomatonDictionary;
}
 
开发者ID:calcmen,项目名称:spellcheck,代码行数:25,代码来源:DictionaryUtil.java

示例7: testGet_io

import com.google.common.io.CharSource; //导入依赖的package包/类
public void testGet_io() throws IOException {
  assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
  assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
  assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
  assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
  ArbitraryInstances.get(PrintStream.class).println("test");
  ArbitraryInstances.get(PrintWriter.class).println("test");
  assertNotNull(ArbitraryInstances.get(File.class));
  assertFreshInstanceReturned(
      ByteArrayOutputStream.class, OutputStream.class,
      Writer.class, StringWriter.class,
      PrintStream.class, PrintWriter.class);
  assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
  assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
  assertNotNull(ArbitraryInstances.get(ByteSink.class));
  assertNotNull(ArbitraryInstances.get(CharSink.class));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:ArbitraryInstancesTest.java

示例8: call

import com.google.common.io.CharSource; //导入依赖的package包/类
@Override
public String call() throws Exception
{
	try
	{
		final URL resource = Resources.getResource("configurable.txt");
		final File f = new File(resource.toURI());
		if( !f.exists() )
		{
			return NO_CONTENT;
		}
		if( lastMod == 0 || lastMod < f.lastModified() )
		{
			final CharSource charSource = Resources.asCharSource(resource, Charset.forName("utf-8"));
			final StringWriter sw = new StringWriter();
			charSource.copyTo(sw);
			lastContent = sw.toString();
			lastMod = f.lastModified();
		}
		return lastContent;
	}
	catch( Exception e )
	{
		return NO_CONTENT;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:27,代码来源:UserConfigurableServlet.java

示例9: ModAccessTransformer

import com.google.common.io.CharSource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ModAccessTransformer() throws Exception
   {
       super(ModAccessTransformer.class);
       //We are in the new ClassLoader here, so we need to get the static field from the other ClassLoader.
       ClassLoader classLoader = this.getClass().getClassLoader().getClass().getClassLoader(); //Bit odd but it gets the class loader that loaded our current class loader yay java!
       Class<?> otherClazz = Class.forName(this.getClass().getName(), true, classLoader);
       Field otherField = otherClazz.getDeclaredField("embedded");
       otherField.setAccessible(true);
       embedded = (Map<String, String>)otherField.get(null);

       for (Map.Entry<String, String> e : embedded.entrySet())
       {
           int old_count = getModifiers().size();
           processATFile(CharSource.wrap(e.getValue()));
           int added = getModifiers().size() - old_count;
           if (added > 0)
           {
               FMLRelaunchLog.fine("Loaded %d rules from AccessTransformer mod jar file %s\n", added, e.getKey());
           }
       }
   }
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:23,代码来源:ModAccessTransformer.java

示例10: StableCssSubstitutionMapProvider

import com.google.common.io.CharSource; //导入依赖的package包/类
/**
 * @param backingFile a file that need not exist, but if it does, contains
 *     the content of the renaming map as formatted by
 *     {@link OutputRenamingMapFormat#JSON}..
 */
public StableCssSubstitutionMapProvider(File backingFile)
throws IOException {
  CharSource renameMapJson = Files.asCharSource(backingFile, Charsets.UTF_8);
  RecordingSubstitutionMap.Builder substitutionMapBuilder =
      new RecordingSubstitutionMap.Builder()
      .withSubstitutionMap(
          new MinimalSubstitutionMap());
  ImmutableMap<String, String> mappings = ImmutableMap.of();
  try {
    try (Reader reader = renameMapJson.openBufferedStream()) {
      mappings = OutputRenamingMapFormat.JSON.readRenamingMap(reader);
    }
  } catch (@SuppressWarnings("unused") FileNotFoundException ex) {
    // Ok.  Start with an empty map.
  }

  substitutionMapBuilder.withMappings(mappings);

  this.substitutionMap = substitutionMapBuilder.build();
  this.backingFile = backingFile;
  this.originalMappings = mappings;
}
 
开发者ID:mikesamuel,项目名称:closure-maven-plugin,代码行数:28,代码来源:StableCssSubstitutionMapProvider.java

示例11: provideCssRenamingMap

import com.google.common.io.CharSource; //导入依赖的package包/类
/** Reads the CSS rename map  */
@Provides
@Singleton
public SoyCssRenamingMap provideCssRenamingMap()
throws IOException {
  ImmutableMap.Builder<String, String> cssMapBuilder = ImmutableMap.builder();

  URL crUrl = getClass().getResource(CSS_RENAMING_MAP_RESOURCE_PATH);
  if (crUrl != null) {
    CharSource cssRenamingMapJson = Resources.asCharSource(
        crUrl, Charsets.UTF_8);
    JsonElement json;
    try (Reader jsonIn = cssRenamingMapJson.openStream()) {
      json = new JsonParser().parse(jsonIn);
    }
    for (Map.Entry<String, JsonElement> e
         : json.getAsJsonObject().entrySet()) {
      cssMapBuilder.put(e.getKey(), e.getValue().getAsString());
    }
  }
  return new SoyCssRenamingMapImpl(cssMapBuilder.build());
}
 
开发者ID:mikesamuel,项目名称:closure-maven-plugin,代码行数:23,代码来源:ClosureModule.java

示例12: injectAccessTransformer

import com.google.common.io.CharSource; //导入依赖的package包/类
public static void injectAccessTransformer(File file, String atName, LaunchClassLoader loader) throws IOException {
if (!AlchemyEngine.isRuntimeDeobfuscationEnabled() || file == null)
	return;
String at = null;
try (JarFile jar = new JarFile(file)) {
	ZipEntry entry = jar.getEntry("META-INF/" + atName);
       if (entry != null)
       	at = Tool.read(jar.getInputStream(entry));
}
if (at != null) {
	List<IClassTransformer> transformers = $(loader, "transformers");
	for (IClassTransformer t : transformers)
		if (t instanceof AccessTransformer) {
			AccessTransformer transformer = (AccessTransformer) t;
			$(transformer, "processATFile", CharSource.wrap(at));
			break;
		}
}
  }
 
开发者ID:NekoCaffeine,项目名称:Alchemy,代码行数:20,代码来源:AlchemySetup.java

示例13: ModAccessTransformer

import com.google.common.io.CharSource; //导入依赖的package包/类
public ModAccessTransformer() throws Exception
{
    super(ModAccessTransformer.class);
    //We are in the new ClassLoader here, so we need to get the static field from the other ClassLoader.
    ClassLoader classLoader = this.getClass().getClassLoader().getClass().getClassLoader(); //Bit odd but it gets the class loader that loaded our current class loader yay java!
    Class<?> otherClazz = Class.forName(this.getClass().getName(), true, classLoader);
    Field otherField = otherClazz.getDeclaredField("embedded");
    otherField.setAccessible(true);
    embedded = (Map<String, String>)otherField.get(null);

    for (Map.Entry<String, String> e : embedded.entrySet())
    {
        int old_count = getModifiers().size();
        processATFile(CharSource.wrap(e.getValue()));
        int added = getModifiers().size() - old_count;
        if (added > 0)
        {
            FMLRelaunchLog.fine("Loaded %d rules from AccessTransformer mod jar file %s\n", added, e.getKey());
        }
    }
}
 
开发者ID:alexandrage,项目名称:CauldronGit,代码行数:22,代码来源:ModAccessTransformer.java

示例14: scanProperties

import com.google.common.io.CharSource; //导入依赖的package包/类
public static Properties scanProperties(String... patterns) {
	Properties p = new Properties();
	Arrays.asList(patterns).forEach(pattern -> {

		Resources.scan(pattern).forEach(url -> {
			CharSource src = Resources.asCharSource(url);
			try (Reader r = src.openBufferedStream()) {
				p.load(r);
				log.info("load property source: <{}>", url.toExternalForm());
			} catch (IOException e) {
				log.error("fail to load property source: <{}> [{}]", url.toExternalForm(), e.getMessage());
			}
		});
	});

	return encryptedProperties(p);
}
 
开发者ID:dohbot,项目名称:knives,代码行数:18,代码来源:Configs.java

示例15: fromCharSource

import com.google.common.io.CharSource; //导入依赖的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


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