/** * Gets the char source to access the resource using UTF-8. * <p> * A char source is a supplier of data. * The source itself is neither opened nor closed. * <p> * This method handles Unicode Byte Order Marks. * * @return the char source */ public CharSource getCharSource() { return UnicodeBom.toCharSource(source); }
/** * Loads one or more CSV format position files. * <p> * CSV files sometimes contain a Unicode Byte Order Mark. * This method uses {@link UnicodeBom} to interpret it. * * @param resources the CSV resources * @return the loaded positions, all errors are captured in the result */ public ValueWithFailures<List<Position>> load(Collection<ResourceLocator> resources) { Collection<CharSource> charSources = resources.stream() .map(r -> UnicodeBom.toCharSource(r.getByteSource())) .collect(toList()); return parse(charSources); }
/** * Loads one or more CSV format trade files. * <p> * CSV files sometimes contain a Unicode Byte Order Mark. * This method uses {@link UnicodeBom} to interpret it. * * @param resources the CSV resources * @return the loaded trades, all errors are captured in the result */ public ValueWithFailures<List<Trade>> load(Collection<ResourceLocator> resources) { Collection<CharSource> charSources = resources.stream() .map(r -> UnicodeBom.toCharSource(r.getByteSource())) .collect(toList()); return parse(charSources); }
/** * Loads one or more CSV format sensitivities files. * <p> * In most cases each file contains one sensitivity instance, however the file format is capable * of representing any number. * <p> * Within a single file and identifier, the same combination of type, reference and tenor must not be repeated. * No checks are performed between different input files. * It may be useful to merge the sensitivities in the resulting list in a separate step after parsing. * <p> * CSV files sometimes contain a Unicode Byte Order Mark. * This method uses {@link UnicodeBom} to interpret it. * * @param resources the CSV resources * @return the sensitivities keyed by identifier, parsing errors are captured in the result */ public ValueWithFailures<ListMultimap<String, CurveSensitivities>> load(Collection<ResourceLocator> resources) { Collection<CharSource> charSources = resources.stream() .map(r -> UnicodeBom.toCharSource(r.getByteSource())) .collect(toList()); return parse(charSources); }
public void test_toCharSource_noBomUtf8() throws IOException { byte[] bytes = {'H', 'e', 'l', 'l', 'o'}; ByteSource byteSource = ByteSource.wrap(bytes); CharSource charSource = UnicodeBom.toCharSource(byteSource); String str = charSource.read(); assertEquals(str, "Hello"); assertTrue(charSource.asByteSource(StandardCharsets.UTF_8).contentEquals(byteSource)); assertEquals(charSource.toString().startsWith("UnicodeBom"), true); }