Guava ByteSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava ByteSource class.

This code example shows how to use the following methods:copyTo, hash
   /** 
    * Essentially copied from the AWS multipart chucked stream test 
    */ 
   public void testMultipartChunkedFileStream() throws IOException, InterruptedException {
      oneHundredOneConstitutions = getTestDataSupplier();
      oneHundredOneConstitutionsMD5 = oneHundredOneConstitutions.hash(md5()).asBytes();
      File file = new File("target/const.txt");
      oneHundredOneConstitutions.copyTo(Files.asByteSink(file));
      String containerName = getContainerName();
 
      try { 
         BlobStore blobStore = view.getBlobStore();
         blobStore.createContainerInLocation(null, containerName);
         Blob blob = blobStore.blobBuilder("const.txt").payload(file).build();
         String expected = blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
         String etag = blobStore.blobMetadata(containerName, "const.txt").getETag();
         assertEquals(etag, expected);
      } finally { 
         returnContainer(containerName);
      } 
6
CodeRank
This code example shows how to use the following methods:hash
 
  private HashCode getHashCode(Path path) throws IOException {
    // TODO(simons): Should be this.projectFilesystem.computeSha1(path); 
    File file = this.projectFilesystem.resolve(path).toFile();
    ByteSource source = Files.asByteSource(file);
    return source.hash(Hashing.sha1());
  } 
 
  @Override 
  public boolean contains(Path path) {
    return loadingCache.getIfPresent(path) != null;
  } 
 
  /** 
   * @return The {@link com.google.common.hash.HashCode} of the contents of path. 
   */ 
  @Override 
  public HashCode get(Path path) {
    HashCode sha1;
    try { 
5
CodeRank
This code example shows how to use the following methods:copyTo
This code example shows how to use the following methods:openStream
    } 
 
    @Override 
    public void process(String outputName, ByteSource byteSource,
                        ByteSink byteSink, boolean closeAtFinish) throws IOException {
        process(outputName, byteSource.openStream(), byteSink.openStream(), closeAtFinish);
    } 
 
    @Override 
    public void process(String outputName, InputStream in, OutputStream out, boolean closeAtFinish) throws IOException {
 
        Reader reader = null;
        Writer writer = null;
 
        try { 
            reader = new InputStreamReader(in, charset);
            writer = new OutputStreamWriter(out, charset);
 
            MavenLogErrorReporter reporter = new MavenLogErrorReporter(outputName);
            new JavaScriptCompressor(reader, reporter).compress(writer, 0, true, true, false, false);
4
CodeRank
This code example shows how to use the following methods:openStream
    } 
 
    @Override 
    public void process(String outputName, ByteSource byteSource,
                        ByteSink byteSink, boolean closeAtFinish) throws IOException {
        process(outputName, byteSource.openStream(), byteSink.openStream(), closeAtFinish);
    } 
 
    @Override 
    public void process(String outputName, InputStream in, OutputStream out, boolean closeAtFinish) throws IOException {
 
        Reader reader = null;
        Writer writer = null;
 
        try { 
            reader = new InputStreamReader(in, charset);
            writer = new OutputStreamWriter(out, charset);
 
            CurrentResourceContext crc = (CurrentResourceContext) CurrentResourceContext.getInstance(FacesContext.getCurrentInstance());
 
4
CodeRank
This code example shows how to use the following methods:openStream
    } 
 
    @Override 
    public void process(String outputName, ByteSource byteSource,
                        ByteSink byteSink, boolean closeAtFinish) throws IOException {
        process(outputName, byteSource.openStream(), byteSink.openStream(), closeAtFinish);
    } 
 
    @Override 
    public void process(String outputName, InputStream in, OutputStream out, boolean closeAtFinish) throws IOException {
        Reader reader = null;
        Writer writer = null;
 
        try { 
            reader = new InputStreamReader(in, charset);
            writer = new OutputStreamWriter(out, charset);
 
            new CssCompressor(reader).compress(writer, 0);
        } finally { 
            try { 
4
CodeRank
This code example shows how to use the following methods:openStream
        return mimeType;
    } 
 
    public InputStream getInputStream() {
        try { 
            return byteSource.openStream();
        } catch (IOException e) {
            throw new HTTPException(e);
        } 
    } 
 
    public long length() { 
        return length;
    } 
 
    public boolean isAvailable() { 
        return true; 
    } 
     
    public static MD5CaculcatingPayload payloadFor(Payload p) {
4
CodeRank
This code example shows how to use the following methods:openStream
    // return openStream(); 
    // } 
 
    @Override 
    public InputStream openStream() throws IOException {
        return data.openStream();
    } 
 
    public Object asEntity() { 
        return data;
    } 
 
    public ByteString getHash() { 
        return hash;
    } 
 
    public void close() { 
 
    } 
 
4
CodeRank
This code example shows how to use the following methods:openStream
    } 
 
    @Override 
    public void process(String outputName, ByteSource byteSource,
                        ByteSink byteSink, boolean closeAtFinish) throws IOException {
        process(outputName, byteSource.openStream(), byteSink.openStream(), closeAtFinish);
    } 
 
    @Override 
    public void process(String outputName, InputStream in, OutputStream out, boolean closeAtFinish) throws IOException {
        try { 
            StreamUtils.copy(in, out);
        } finally { 
            try { 
                in.close();
            } catch (IOException e) {
                // Swallow 
            } 
            if (closeAtFinish) {
                try { 
5
CodeRank
This code example shows how to use the following methods:openStream
        try { 
            cipher = ScramblingSinkFilter.getCipher(Cipher.DECRYPT_MODE, key);
        } catch (Throwable e) {
            throw new IOException("Failed to create cipher", e);
        } 
        return new CipherInputStream(delegate.openStream(), cipher);
    } 
 
} 
4
CodeRank
See Code Examples for Guava ByteSource Methods: