Here you can find the source of write(final Object o, final String filename)
Parameter | Description |
---|---|
o | a parameter |
filename | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void write(final Object o, final String filename) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.file.Files; import java.util.zip.GZIPOutputStream; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { private static final ObjectMapper MAPPER = new ObjectMapper(); /**//from w w w. j av a 2 s . com * write to gzip file. * @param o * @param filename * @throws IOException */ public static void write(final Object o, final String filename) throws IOException { try (final BufferedWriter bw = setUpWriter(filename)) { bw.write(MAPPER.writeValueAsString(o)); bw.close(); } } /** * set up gzip file writer. * @param filename * @return * @throws IOException */ private static BufferedWriter setUpWriter(final String filename) throws IOException { return new BufferedWriter( new OutputStreamWriter(new GZIPOutputStream(Files.newOutputStream(new File(filename).toPath())))); } }