List of usage examples for com.google.common.io OutputSupplier getOutput
T getOutput() throws IOException;
From source file:com.scottwoodward.rpitems.items.NbtFactory.java
/** * Save the content of a NBT compound to a stream. * <p>//from www. j a va 2s. co m * Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file. * @param source - the NBT compound to save. * @param stream - the stream. * @param option - whether or not to compress the output. * @throws IOException If anything went wrong. */ public static void saveStream(NbtCompound source, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException { OutputStream output = null; DataOutputStream data = null; try { output = stream.getOutput(); data = new DataOutputStream( option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output); invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data); } finally { if (data != null) Closeables.closeQuietly(data); if (output != null) Closeables.closeQuietly(output); } }
From source file:org.richfaces.cdk.resource.writer.impl.JavaScriptPackagingProcessor.java
@Override public void process(String resourceName, InputSupplier<? extends InputStream> in, OutputSupplier<? extends OutputStream> out, boolean closeAtFinish) throws IOException { process(resourceName, in.getInput(), out.getOutput(), closeAtFinish); }
From source file:com.minecave.pickaxes.util.nbt.EPNbtFactory.java
/** * Save the content of a NBT compound to a stream. * <p/>/* w w w . ja v a 2s .com*/ * Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file. * * @param source - the NBT compound to save. * @param stream - the stream. * @param option - whether or not to compress the output. * @throws IOException If anything went wrong. */ public static void saveStream(NbtCompound source, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException { OutputStream output = null; DataOutputStream data = null; boolean suppress = true; try { output = stream.getOutput(); data = new DataOutputStream( option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output); invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data); suppress = false; } finally { if (data != null) Closeables.close(data, suppress); else if (output != null) Closeables.close(output, suppress); } }
From source file:co.cask.tigon.internal.app.FlowSpecificationAdapter.java
public void toJson(FlowSpecification appSpec, OutputSupplier<? extends Writer> outputSupplier) throws IOException { Writer writer = outputSupplier.getOutput(); try {//from w w w . ja v a 2 s .c om toJson(appSpec, writer); } finally { Closeables.closeQuietly(writer); } }
From source file:co.cask.cdap.internal.app.ApplicationSpecificationAdapter.java
public void toJson(ApplicationSpecification appSpec, OutputSupplier<? extends Writer> outputSupplier) throws IOException { try (Writer writer = outputSupplier.getOutput()) { toJson(appSpec, writer);/* w w w . j av a2 s.c om*/ } }
From source file:io.druid.common.utils.SerializerUtils.java
public void writeString(OutputSupplier<? extends OutputStream> supplier, String name) throws IOException { try (OutputStream out = supplier.getOutput()) { writeString(out, name);//from ww w. ja va 2 s. co m } }
From source file:com.metamx.druid.utils.SerializerUtils.java
public void writeString(OutputSupplier<? extends OutputStream> supplier, String name) throws IOException { OutputStream out = null;/*from w ww .j a va 2 s . co m*/ try { out = supplier.getOutput(); writeString(out, name); } finally { Closeables.closeQuietly(out); } }
From source file:io.druid.segment.data.CompressedLongsSupplierSerializer.java
public void closeAndConsolidate(OutputSupplier<? extends OutputStream> consolidatedOut) throws IOException { endBuffer.limit(endBuffer.position()); endBuffer.rewind();// w ww . java 2 s .c om flattener.write(StupidResourceHolder.create(endBuffer)); endBuffer = null; flattener.close(); try (OutputStream out = consolidatedOut.getOutput()) { out.write(CompressedLongsIndexedSupplier.version); out.write(Ints.toByteArray(numInserted)); out.write(Ints.toByteArray(sizePer)); out.write(new byte[] { compression.getId() }); ByteStreams.copy(flattener.combineStreams(), out); } }
From source file:com.github.nethad.clustermeister.provisioning.cli.Provisioning.java
private void createDefaultConfiguration(String configFilePath) { final File configFile = new File(configFilePath); if (configFile.exists()) { return;//from w w w .j ava2s . c om } configFile.getParentFile().mkdirs(); OutputSupplier<OutputStreamWriter> writer = Files.newWriterSupplier(configFile, Charsets.UTF_8); OutputStreamWriter output = null; try { output = writer.getOutput(); output.append(YamlConfiguration.defaultConfiguration()); output.flush(); output.close(); } catch (IOException ex) { throw new RuntimeException(ex); } finally { if (output != null) { try { output.close(); } catch (IOException ex) { // ignore } } } }
From source file:io.druid.segment.data.CompressedFloatsSupplierSerializer.java
public void closeAndConsolidate(OutputSupplier<? extends OutputStream> consolidatedOut) throws IOException { endBuffer.limit(endBuffer.position()); endBuffer.rewind();/*from w ww. ja v a2 s . c o m*/ flattener.write(StupidResourceHolder.create(endBuffer)); endBuffer = null; flattener.close(); try (OutputStream out = consolidatedOut.getOutput()) { out.write(CompressedFloatsIndexedSupplier.version); out.write(Ints.toByteArray(numInserted)); out.write(Ints.toByteArray(sizePer)); out.write(new byte[] { compression.getId() }); ByteStreams.copy(flattener.combineStreams(), out); } }