List of usage examples for com.google.common.io ByteSink openBufferedStream
public OutputStream openBufferedStream() throws IOException
From source file:com.github.steveash.jg2p.util.ReadWrite.java
public static <T> void writeTo(T model, File outputFile) throws IOException { ByteSink sink = Files.asByteSink(outputFile); try (ObjectOutputStream oos = new ObjectOutputStream(sink.openBufferedStream())) { oos.writeObject(model);/* ww w .ja v a 2s . c om*/ } }
From source file:com.blackducksoftware.bdio.io.BdioWriter.java
/** * Returns a subscriber from a byte sink. *//*from w w w .j ava 2s. com*/ public static Subscriber<Node> store(final LinkedDataContext context, final ByteSink sink, final Action1<Throwable> onError) { checkNotNull(context); checkNotNull(sink); checkNotNull(onError); return new Subscriber<Node>() { private BdioWriter writer; @Override public void onStart() { try { writer = new BdioWriter(context, sink.openBufferedStream()); } catch (IOException e) { onError(e); } } @Override public void onNext(Node node) { try { writer.write(node); } catch (IOException e) { onError(e); } } @Override public void onCompleted() { try { writer.close(); } catch (IOException e) { onError(e); } } @Override public void onError(Throwable e) { onError.call(e); } }; }
From source file:com.skcraft.launcher.persistence.Persistence.java
/** * Save an object to file.//from w ww. j a va 2s.c om * * @param object the object * @throws java.io.IOException on save error */ public static void commit(@NonNull Object object) throws IOException { ByteSink sink; synchronized (bound) { sink = bound.get(object); if (sink == null) { throw new IOException("Cannot persist unbound object: " + object); } } Closer closer = Closer.create(); try { OutputStream os = closer.register(sink.openBufferedStream()); mapper.writeValue(os, object); } finally { closer.close(); } }
From source file:org.asoem.greyfish.utils.persistence.JavaPersister.java
private void serialize(final Object object, final ByteSink byteSink) throws IOException { final OutputStream output = byteSink.openBufferedStream(); boolean threw = true; try {/* w ww. j a va 2s. co m*/ serialize(object, output); threw = false; } finally { Closeables.close(output, threw); } }
From source file:com.fasterxml.jackson.tools.Jackson.java
private void run() { ByteSource inputSource = Files.asByteSource(inputFile); ByteSink outputSink = Files.asByteSink(outputFile); InputStream input;/*www .ja v a 2 s .c o m*/ OutputStream output; try { input = inputSource.openBufferedStream(); output = outputSink.openBufferedStream(); convert(input, output); } catch (IOException e) { System.err.format("Exception in conversion %s%n", e.getMessage()); System.exit(1); } }
From source file:microsoft.exchange.webservices.data.core.EwsXmlReader.java
public void readBase64ElementValue(ByteSink sink) throws Exception { try (OutputStream os = sink.openBufferedStream()) { readBase64ElementValue(os);//from w ww . j a v a 2 s. c om } }