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