public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException { for (Object value : container) { write(value); } return this; }
public SequenceWriter writeAll(Object[] value) throws IOException { for (int i = 0, len = value.length; i < len; ++i) { write(value[i]); } return this; }
/** * @since 2.7 */ public SequenceWriter writeAll(Iterable<?> iterable) throws IOException { for (Object value : iterable) { write(value); } return this; }
predict, rmse, r.getTimestamp() - buildTime, rank, buildsCount); if (extWriter != null) { extWriter.write(json);
public SequenceWriter writeAll(Object[] value) throws IOException { for (int i = 0, len = value.length; i < len; ++i) { write(value[i]); } return this; }
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException { for (Object value : container) { write(value); } return this; }
public SequenceWriter writeAll(Object[] value) throws IOException { for (int i = 0, len = value.length; i < len; ++i) { write(value[i]); } return this; }
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException { for (Object value : container) { write(value); } return this; }
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException { for (Object value : container) { write(value); } return this; }
/** * @since 2.7 */ public SequenceWriter writeAll(Iterable<?> iterable) throws IOException { for (Object value : iterable) { write(value); } return this; }
public <C extends Collection<?>> SequenceWriter writeAll(C container) throws IOException { for (Object value : container) { write(value); } return this; }
public SequenceWriter writeAll(Object[] value) throws IOException { for (int i = 0, len = value.length; i < len; ++i) { write(value[i]); } return this; }
/** * @since 2.7 */ public SequenceWriter writeAll(Iterable<?> iterable) throws IOException { for (Object value : iterable) { write(value); } return this; }
YAMLFactory yf = new YAMLFactory(); ObjectMapper mapper = new ObjectMapper(yf); ObjectNode root = (ObjectNode) mapper.readTree(yamlFileIn); // modify root here FileOutputStream fos = new FileOutputStream(yamlFileOut); SequenceWriter sw = mapper.writerWithDefaultPrettyPrinter().writeValues(fos); sw.write(root);
@Override public boolean write(Variant variant) { try { jsonObjectWriter.write(variant.getImpl()); bw.write('\n'); } catch (IOException e) { throw Throwables.propagate(e); } return true; }
/** * 序列化为JSON */ public static <V> void toFile(String path, V v) { try (Writer writer = new FileWriter(new File(path), true)) { mapper.writer().writeValues(writer).write(v); writer.flush(); } catch (Exception e) { log.error("jackson to file error, path: {}, obj: {}", path, v, e); } }
/** * 序列化为Properties文件 */ public static <V> void toPropFile(String path, V v) { try (Writer writer = new FileWriter(new File(path), true)) { JavaPropsSchema schema = JavaPropsSchema.emptySchema(); propsMapper.writer(schema).writeValues(writer).write(v); writer.flush(); } catch (Exception e) { log.error("jackson to properties file error, path: {}, obj: {}", path, v, e); } }
private void persistLicenseMap() throws IOException { if (licenseMapOutputFile != null) { licenseMapOutputFile.getParentFile().mkdirs(); SequenceWriter sw = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValues(licenseMapOutputFile).init(true); for (LicensedProjects entry : licenseMap.values()) { sw.write(entry); } sw.close(); } }
/** * 序列化为CSV文件 */ public static <V> void toCsvFile(String path, String separator, V v) { try (Writer writer = new FileWriter(new File(path), true)) { CsvSchema schema = csvMapper.schemaFor(v.getClass()).withHeader().withColumnSeparator(separator.charAt(0)); csvMapper.writer(schema).writeValues(writer).write(v); writer.flush(); } catch (Exception e) { log.error("jackson to csv file error, path: {}, separator: {}, obj: {}", path, separator, v, e); } }
@Test public final void testWriteEmptySingle() throws Exception { List<String> headers = Arrays.asList("TestHeader1"); StringWriter writer = new StringWriter(); final Writer writer1 = writer; CSVStream.newCSVWriter(writer1, headers).write(Arrays.asList()); System.out.println(writer.toString()); assertEquals("TestHeader1\n", writer.toString()); }