com.google.common.io.Files#asCharSource ( )源码实例Demo

下面列出了com.google.common.io.Files#asCharSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: token-core-android   文件: WalletManager.java
public static void scanWallets() {
  File directory = getDefaultKeyDirectory();

  keystoreMap.clear();
  for (File file : directory.listFiles()) {
    if (!file.getName().startsWith("identity")) {
      try {
        IMTKeystore keystore = null;
        CharSource charSource = Files.asCharSource(file, Charset.forName("UTF-8"));
        String jsonContent = charSource.read();
        JSONObject jsonObject = new JSONObject(jsonContent);
        int version = jsonObject.getInt("version");
        if (version == 3) {
          if (jsonContent.contains("encMnemonic")) {
            keystore = unmarshalKeystore(jsonContent, V3MnemonicKeystore.class);
          } else if (jsonObject.has("imTokenMeta") && ChainType.EOS.equals(jsonObject.getJSONObject("imTokenMeta").getString("chainType"))) {
            keystore = unmarshalKeystore(jsonContent, LegacyEOSKeystore.class);
          } else {
            keystore = unmarshalKeystore(jsonContent, V3Keystore.class);
          }
        } else if (version == 1) {
          keystore = unmarshalKeystore(jsonContent, V3Keystore.class);
        } else if (version == 44) {
          keystore = unmarshalKeystore(jsonContent, HDMnemonicKeystore.class);
        } else if (version == 10001) {
          keystore = unmarshalKeystore(jsonContent, EOSKeystore.class);
        }

        if (keystore != null) {
          keystoreMap.put(keystore.getId(), keystore);
        }
      } catch (Exception ex) {
        Log.e(LOG_TAG, "Can't loaded " + file.getName() + " file", ex);
      }
    }
  }
}
 
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	if (IS_FLUTTER_PROJECT_PROPERTY.equalsIgnoreCase(property)) {
		IResource resource = Adapters.adapt(receiver, IResource.class);
		if (resource == null) {
			return false;
		}

		IProject project = resource.getProject();
		if (project == null) {
			return false;
		}
		IResource pubspec = project.findMember(GlobalConstants.PUBSPEC_YAML);
		if (pubspec == null) {
			return false;
		}
		File pubspecFile = pubspec.getRawLocation().toFile();
		CharSource pubspecContent = Files.asCharSource(pubspecFile, Charset.defaultCharset());
		try {
			for (String line : pubspecContent.readLines()) {
				if (FLUTTER_SDK.matcher(line).matches()) {
					return true;
				}
			}
		} catch (IOException e) {
			LOG.log(DartLog.createError("Could not open pubspec.yaml", e));
		}
	}
	return false;
}
 
源代码3 项目: jopenfst   文件: Convert.java
/**
 * Imports an openfst text format. You pass in the file pointing to the fst.txt file and
 * it assumes that the other files has the same prefix, but with input.syms and output.syms
 * as suffixes.  For exmaple if you pass in:
 * path/to/mymodel.fst.txt
 * It assumes that you also have:
 * path/to/mymodel.input.syms
 * path/to/mymodel.output.syms
 *
 * @param fileToFst the files' base name
 * @param semiring  the fst's semiring
 */
public static MutableFst importFst(File fileToFst, Semiring semiring) {
  Preconditions.checkArgument(fileToFst.exists(), "File to the fst.txt openfst output doesnt exist", fileToFst);
  Preconditions.checkArgument(fileToFst.getName().endsWith(FST_TXT), "fst.txt path must end in .fst.txt", fileToFst);
  String basepath = fileToFst.getAbsolutePath();
  basepath = StringUtils.removeEnd(basepath, FST_TXT);
  CharSource cs = Files.asCharSource(fileToFst, Charsets.UTF_8);

  Optional<MutableSymbolTable> maybeInputs = importSymbols(new File(basepath + INPUT_SYMS));
  Optional<MutableSymbolTable> maybeOutputs = importSymbols(new File(basepath + OUTPUT_SYMS));
  Optional<MutableSymbolTable> maybeStates = importSymbols(new File(basepath + STATES_SYMS));

  return convertFrom(cs, maybeInputs, maybeOutputs, maybeStates, semiring);
}
 
源代码4 项目: tutorials   文件: GuavaIOUnitTest.java
@Test
public void whenReadUsingCharSource_thenRead() throws IOException {
    final String expectedValue = "Hello world";
    final File file = new File("src/test/resources/test1.in");

    final CharSource source = Files.asCharSource(file, Charsets.UTF_8);

    final String result = source.read();
    assertEquals(expectedValue, result);
}
 
源代码5 项目: tutorials   文件: GuavaIOUnitTest.java
@Test
public void whenReadMultipleCharSources_thenRead() throws IOException {
    final String expectedValue = "Hello worldTest";
    final File file1 = new File("src/test/resources/test1.in");
    final File file2 = new File("src/test/resources/test1_1.in");

    final CharSource source1 = Files.asCharSource(file1, Charsets.UTF_8);
    final CharSource source2 = Files.asCharSource(file2, Charsets.UTF_8);
    final CharSource source = CharSource.concat(source1, source2);

    final String result = source.read();

    assertEquals(expectedValue, result);
}
 
源代码6 项目: tac-kbp-eal   文件: AssessmentSpecFormats.java
private synchronized AnswerKey uncachedRead(final Symbol docid) throws IOException {
  final ImmutableList.Builder<AssessedResponse> annotated = ImmutableList.builder();
  final ImmutableList.Builder<Response> unannotated = ImmutableList.builder();
  final CorefAnnotation.Builder corefBuilder = assessmentCreator.corefBuilder(docid);

  final File f = bareOrWithSuffix(directory, docid.asString(), ACCEPTABLE_SUFFIXES);

  final CharSource source = Files.asCharSource(f, UTF_8);
  for (final String line : source.readLines()) {
    try {
      if (line.isEmpty() || line.startsWith("#")) {
        continue;
      }
      final String[] parts = line.split("\t");
      final List<String> annotationParts = Arrays.asList(parts).subList(11, parts.length);

      if (annotationParts.isEmpty()) {
        throw new IOException(String.format(
            "The assessment store file for document ID %s appears to be a system " +
                "output file with no assessment columns.", docid));
      }

      final Response response = parseArgumentFields(format, ImmutableList.copyOf(parts));
      final AssessmentCreator.AssessmentParseResult annotation =
          parseAnnotation(annotationParts);

      if (annotation.assessment().isPresent()) {
        annotated.add(AssessedResponse.of(response, annotation.assessment().get()));
      } else {
        unannotated.add(response);
      }

      if (annotation.corefId().isPresent()) {
        corefBuilder.corefCAS(response.canonicalArgument(), annotation.corefId().get());
      } else {
        corefBuilder.addUnannotatedCAS(response.canonicalArgument());
      }
    } catch (Exception e) {
      throw new IOException(String.format(
          "While reading answer key for document %s, error on line %s", docid, line), e);
    }
  }

  return assessmentCreator.createAnswerKey(docid, annotated.build(), unannotated.build(),
      corefBuilder.build());
}
 
源代码7 项目: tcl-regex-java   文件: Grep.java
private void processFile(File input) throws IOException, RegexException {
    CharSource inputCharSource = Files.asCharSource(input, Charsets.UTF_8);
    processReader(inputCharSource.openBufferedStream());
}
 
源代码8 项目: Strata   文件: CharSources.java
/**
 * Obtains an instance of {@link CharSource} from a file name, specified as a String.
 *
 * @param fileName  the file name, as a String
 * @return  a new instance of {@link CharSource} with UTF-8 for charset.
 */
public static CharSource ofFileName(String fileName) {
  return Files.asCharSource(new File(fileName), Charsets.UTF_8);
}
 
源代码9 项目: Strata   文件: CharSources.java
/**
 * Obtains an instance of {@link CharSource} from a file name, specified as a String.
 * This also takes in a specific character set, as a {@link Charset}.
 *
 * @param fileName  the file name, as a String
 * @param charset  the charset to build the new CharSource based on
 * @return  a new instance of {@link CharSource}
 */
public static CharSource ofFileName(String fileName, Charset charset) {
  return Files.asCharSource(new File(fileName), charset);
}
 
源代码10 项目: Strata   文件: CharSources.java
/**
 * Obtains an instance of {@link CharSource} from a file object, specified as a {@link File}.
 *
 * @param file  the file object
 * @return  a new instance of {@link CharSource} with UTF-8 for charset.
 */
public static CharSource ofFile(File file) {
  return Files.asCharSource(file, Charsets.UTF_8);
}
 
源代码11 项目: Strata   文件: CharSources.java
/**
 * Obtains an instance of {@link CharSource} from a file object, specified as a {@link File}.
 * This also takes in a specific character set, as a {@link Charset}.
 *
 * @param file  the file object
 * @param charset  the charset to build the new CharSource based on
 * @return  a new instance of {@link CharSource}
 */
public static CharSource ofFile(File file, Charset charset) {
  return Files.asCharSource(file, charset);
}