/** * Reads the contents of this byte source using the given {@code processor} to process bytes as * they are read. Stops when all bytes have been read or the consumer returns {@code false}. * Returns the result produced by the processor. * * @throws IOException if an I/O error occurs while reading from this source or if {@code * processor} throws an {@code IOException} * @since 16.0 */ @Beta @CanIgnoreReturnValue // some processors won't return a useful result public <T> T read(ByteProcessor<T> processor) throws IOException { checkNotNull(processor); Closer closer = Closer.create(); try { InputStream in = closer.register(openStream()); return ByteStreams.readBytes(in, processor); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
/** * Reads the contents of this byte source using the given {@code processor} to process bytes as * they are read. Stops when all bytes have been read or the consumer returns {@code false}. * Returns the result produced by the processor. * * @throws IOException if an I/O error occurs while reading from this source or if {@code * processor} throws an {@code IOException} * @since 16.0 */ @Beta @CanIgnoreReturnValue // some processors won't return a useful result public <T> T read(ByteProcessor<T> processor) throws IOException { checkNotNull(processor); Closer closer = Closer.create(); try { InputStream in = closer.register(openStream()); return ByteStreams.readBytes(in, processor); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
/** * Reads the contents of this byte source using the given {@code processor} to process bytes as * they are read. Stops when all bytes have been read or the consumer returns {@code false}. * Returns the result produced by the processor. * * @throws IOException if an I/O error occurs while reading from this source or if {@code * processor} throws an {@code IOException} * @since 16.0 */ @Beta @CanIgnoreReturnValue // some processors won't return a useful result public <T> T read(ByteProcessor<T> processor) throws IOException { checkNotNull(processor); Closer closer = Closer.create(); try { InputStream in = closer.register(openStream()); return ByteStreams.readBytes(in, processor); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
public void testByteProcessorStopEarly() throws IOException { byte[] array = newPreFilledByteArray(10000); assertEquals( (Integer) 42, ByteStreams.readBytes( new ByteArrayInputStream(array), new ByteProcessor<Integer>() { @Override public boolean processBytes(byte[] buf, int off, int len) { assertEquals(copyOfRange(buf, off, off + len), newPreFilledByteArray(8192)); return false; } @Override public Integer getResult() { return 42; } })); }
public void testReadBytes() throws IOException { final byte[] array = newPreFilledByteArray(1000); assertEquals( array, ByteStreams.readBytes(new ByteArrayInputStream(array), new TestByteProcessor())); }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (InvalidKeyException e) { throw propagate(e); } catch (IOException e) { throw propagate(e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (InvalidKeyException e) { throw propagate(e); } catch (IOException e) { throw propagate(e); } }
@Override public String sign(String toSign) { try { ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(creds.get().credential.getBytes(UTF_8))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA256)); } catch (InvalidKeyException e) { throw propagate(e); } catch (IOException e) { throw propagate(e); } }
private String createSignature(String key, String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(key.getBytes(UTF_8))); return base16().lowerCase().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (InvalidKeyException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA256)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
private String createSignature(String key, String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(key.getBytes(UTF_8))); return base16().lowerCase().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (InvalidKeyException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } } }
private String createSignature(String key, String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(key.getBytes(UTF_8))); return base16().lowerCase().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (InvalidKeyException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA256)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String signString(String toSign) { try { ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(base64().decode(creds.get().credential))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA256)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
private String createSignature(String key, String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(key.getBytes(UTF_8))); return base16().lowerCase().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (InvalidKeyException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } } }
public String sign(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor(crypto.hmacSHA1(creds.get().credential.getBytes(UTF_8))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }
public String sign(String toSign) { try { ByteProcessor<byte[]> hmacSHA1 = asByteProcessor( crypto.hmacSHA1(creds.get().credential.getBytes(UTF_8))); return base64().encode(readBytes(toInputStream(toSign), hmacSHA1)); } catch (Exception e) { throw new HttpException("error signing request", e); } }