List of usage examples for com.google.common.io ByteSource openStream
public abstract InputStream openStream() throws IOException;
From source file:eu.lp0.cursus.xml.common.AbstractXMLFile.java
public final void from(ByteSource in) throws ImportException { try {//from w ww .ja v a 2s. c o m from(in.openStream()); } catch (IOException e) { throw new ImportException(e); } }
From source file:at.ac.univie.isc.asio.d2rq.LoadD2rqModel.java
private Model readFrom(final ByteSource source, final String base) throws IOException { try (final InputStream stream = source.openStream()) { final Model model = ModelFactory.createDefaultModel(); parser.read(model, stream, base); return model; }/*from www . j a va 2s .co m*/ }
From source file:com.comphenix.attributes.NbtFactory.java
/** * Load the content of a file from a stream. * <p>/*from ww w. j a v a 2 s .co m*/ * Use {@link Files#asByteSource(File)} to provide a stream from a file. * * @param stream - the stream supplier. * @param option - whether or not to decompress the input stream. * @return The decoded NBT compound. * @throws IOException If anything went wrong. */ public static NbtCompound fromStream(ByteSource stream, StreamOptions option) throws IOException { InputStream input = null; DataInputStream data = null; boolean suppress = true; try { input = stream.openStream(); data = new DataInputStream(new BufferedInputStream( option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input)); NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data)); suppress = false; return result; } finally { if (data != null) Closeables.close(data, suppress); else if (input != null) Closeables.close(input, suppress); } }
From source file:net.derquinse.common.io.BytesTransformer.java
/** Transforms a byte source. */ public void transform(ByteSource input, ByteSink output) throws IOException { checkInput(input);/*from w ww . j ava 2 s . c o m*/ checkOutput(output); final Closer closer = Closer.create(); try { transform(closer.register(input.openStream()), closer.register(output.openStream())); } finally { closer.close(); } }
From source file:net.derquinse.common.io.BytesTransformer.java
/** Transforms a byte source. */ public void transform(ByteSource input, OutputStream output) throws IOException { checkInput(input);//from w w w .ja va2 s. c o m checkOutput(output); final Closer closer = Closer.create(); try { transform(closer.register(input.openStream()), output); } finally { closer.close(); } }
From source file:net.derquinse.common.util.zip.ZipFileLoader.java
/** * Loads a zip file into memory.//from w w w . j av a 2 s . c om * @param input Input data. * @return The loaded zip file. * @throws IOException if an I/O error occurs * @throws MaximumSizeExceededException if any of the entries exceeds the maximum size. */ public LoadedZipFile load(ByteSource input) throws IOException { checkInput(input); Closer closer = Closer.create(); try { return load(closer.register(input.openStream())); } finally { closer.close(); } }
From source file:net.derquinse.bocas.gcs.GCSBucket.java
@Override protected void put(final ByteString key, final ByteSource value) { boolean ok = false; try {/*from ww w. j av a 2 s . c o m*/ final InputStream is = value.openStream(); try { InputStreamContent content = new InputStreamContent("application/octet-stream", is); if (value instanceof MemoryByteSource) { content.setLength(value.size()); } Storage.Objects.Insert request = storage.objects().insert(bucket, null, content); request.setName(key.toHexString()); // TODO: check direct upload request.execute(); ok = true; } catch (IOException e) { throw new BocasException(e); } finally { is.close(); } } catch (IOException e) { // ok is true if the exception is thrown during clean up. if (!ok) { throw new BocasException(e); } } }
From source file:com.google.template.soy.types.proto.DescriptorTreeWalker.java
/** Read a file descriptor set and walk any proto types found within. */ final void walkFileDescriptorSetFromByteSource(ByteSource source) throws FileNotFoundException, IOException, DescriptorValidationException { visitFileDescriptorSetFromByteSource(source); try (InputStream inputStream = source.openStream()) { walkFileDescriptorSet(FileDescriptorSet.parseFrom(inputStream, extensionRegistry)); }/*ww w .ja v a 2 s .c om*/ }
From source file:org.opendaylight.controller.cluster.raft.behaviors.LeaderInstallSnapshotState.java
void setSnapshotBytes(final ByteSource snapshotBytes) throws IOException { if (this.snapshotBytes != null) { return;/* w w w . j a va 2 s .c o m*/ } snapshotSize = snapshotBytes.size(); snapshotInputStream = snapshotBytes.openStream(); this.snapshotBytes = snapshotBytes; totalChunks = (int) (snapshotSize / snapshotChunkSize + (snapshotSize % snapshotChunkSize > 0 ? 1 : 0)); LOG.debug("{}: Snapshot {} bytes, total chunks to send: {}", logName, snapshotSize, totalChunks); replyReceivedForOffset = -1; chunkIndex = FIRST_CHUNK_INDEX; }
From source file:ratpack.server.internal.DefaultServerConfigBuilder.java
@Override public ServerConfig.Builder props(ByteSource byteSource) { Properties properties = new Properties(); try (InputStream is = byteSource.openStream()) { properties.load(is);/*from w ww.j a v a 2 s .co m*/ } catch (IOException e) { throw uncheck(e); } return props(properties); }