/** * Creates an instance, allowing the new line character to be controlled and using a comma separator. * <p> * See the standard quoting rules in the class-level documentation. * * @param underlying the destination to write to * @param newLine the new line string * @return the CSV outputter */ public static CsvOutput standard(Appendable underlying, String newLine) { return new CsvOutput(underlying, newLine, COMMA, false); }
/** * Returns a suitable hash code for the file. * * @return the hash code */ @Override public int hashCode() { return keyValueMap.hashCode(); }
/** * Returns a string describing the file. * * @return the descriptive string */ @Override public String toString() { return keyValueMap.toString(); }
private TradeReportTemplate parseIni(String resourceName) { ResourceLocator locator = ResourceLocator.of("classpath:" + resourceName); IniFile ini = IniFile.of(locator.getCharSource()); TradeReportTemplateIniLoader loader = new TradeReportTemplateIniLoader(); return loader.load(ini); }
public void test_ofChained_chainToNowhere() { IniFile test = ResourceConfig.combinedIniFile("TestChain3.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "x", "b", "y"); assertEquals(test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1))); }
/** * 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); }
/** * Parses the specified source as an XML file to an in-memory DOM-like structure. * <p> * This parses the specified byte source expecting an XML file format. * The resulting instance can be queried for the root element. * * @param source the XML source data * @return the parsed file * @throws UncheckedIOException if an IO exception occurs * @throws IllegalArgumentException if the file cannot be parsed */ public static XmlFile of(ByteSource source) { return of(source, ""); }
/** * Writes a single cell to the current line, only quoting if needed. * <p> * When using this method, either {@link #writeNewLine()} or one of the {@code writeLine} * methods must be called at the end of the line. * * @param cell the cell to write * @return this, for method chaining * @throws UncheckedIOException if an IO exception occurs */ public CsvOutput writeCell(String cell) { writeCell(cell, false); return this; }
/** * Reads the source, converting to UTF-8 using a Byte-Order Mark if available. * * @return the UTF-8 string */ public String readUtf8UsingBom() { return UnicodeBom.toString(array); }
/** * Returns a string describing the file. * * @return the descriptive string */ @Override public String toString() { return root.toString(); }
/** * Obtains an instance by copying part of an array. * <p> * The input array is copied and not mutated. * * @param array the array to copy * @param fromIndex the offset from the start of the array * @return an array containing the specified values * @throws IndexOutOfBoundsException if the index is invalid */ public static ArrayByteSource copyOf(byte[] array, int fromIndex) { return copyOf(array, fromIndex, array.length); }
@Override public String toString() { return "ArrayByteSource[" + size() + " bytes]"; }
private static Optional<String> findValue(CsvRow row, String leg, String field) { return row.findValue(leg + field); }
/** * Converts an {@code InputStream} to a {@code Reader}. * <p> * This ensures that any Unicode byte order marker is used correctly. * The default encoding is UTF-8 if no BOM is found. * * @param inputStream the input stream to wrap * @return the reader, that uses the BOM to determine the encoding * @throws IOException if an IO error occurs */ public static Reader toReader(InputStream inputStream) throws IOException { return new BomReader(inputStream); }
@Override public ByteArrayInputStream openBufferedStream() { return openStream(); }
/** * Creates an instance, not copying the array. * <p> * This method is inherently unsafe as it relies on good behavior by callers. * Callers must never make any changes to the passed in array after calling this method. * Doing so would violate the immutability of this class. * * @param array the array, not copied * @return the byte source */ public static ArrayByteSource ofUnsafe(byte[] array) { return new ArrayByteSource(array); }
public void test_ofChained_chainNextFileFalse() { IniFile test = ResourceConfig.combinedIniFile("TestChain2.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "z"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("m", "n"); assertEquals( test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1), "two", PropertySet.of(keyValues2))); }
/** * Creates an instance, using the system default line separator and using a comma separator. * <p> * See the standard quoting rules in the class-level documentation. * * @param underlying the destination to write to * @return the CSV outputter */ public static CsvOutput standard(Appendable underlying) { return new CsvOutput(underlying, NEW_LINE, COMMA, false); }
public void test_ofChained_chainRemoveSections() { IniFile test = ResourceConfig.combinedIniFile("TestChain5.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "a"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("m", "n", "o", "z"); assertEquals( test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1), "two", PropertySet.of(keyValues2))); }
/** * Creates an instance, allowing the new line character to be controlled, specifying the separator. * <p> * See the standard quoting rules in the class-level documentation. * * @param underlying the destination to write to * @param newLine the new line string * @param separator the separator used to separate each field, typically a comma, but a tab is sometimes used * @return the CSV outputter */ public static CsvOutput standard(Appendable underlying, String newLine, String separator) { return new CsvOutput(underlying, newLine, separator, false); }