congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
ByteStreams2.hashAndClose
Code IndexAdd Tabnine to your IDE (free)

How to use
hashAndClose
method
in
org.jclouds.io.ByteStreams2

Best Java code snippets using org.jclouds.io.ByteStreams2.hashAndClose (Showing top 8 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew ArrayList()
  • Codota Iconnew LinkedList()
  • Smart code suggestions by Tabnine
}
origin: org.apache.jclouds.api/chef

@VisibleForTesting
String hashBody(Payload payload) {
 if (payload == null)
   return emptyStringHash;
 payload = useTheFilePartIfForm(payload);
 checkArgument(payload != null, "payload was null");
 checkArgument(payload.isRepeatable(), "payload must be repeatable: " + payload);
 try {
   return base64().encode(ByteStreams2.hashAndClose(payload.getInput(), sha1()).asBytes());
 } catch (Exception e) {
   Throwables.propagateIfPossible(e);
   throw new HttpException("error creating sigature for payload: " + payload, e);
 }
}
origin: apache/jclouds

@VisibleForTesting
String hashBody(Payload payload) {
 if (payload == null)
   return emptyStringHash;
 payload = useTheFilePartIfForm(payload);
 checkArgument(payload != null, "payload was null");
 checkArgument(payload.isRepeatable(), "payload must be repeatable: " + payload);
 try {
   return base64().encode(ByteStreams2.hashAndClose(payload.getInput(), sha1()).asBytes());
 } catch (Exception e) {
   Throwables.propagateIfPossible(e);
   throw new HttpException("error creating sigature for payload: " + payload, e);
 }
}
origin: apache/jclouds

private void assertValidMd5(final InputStream input, String md5) throws IOException {
 assertEquals(base64().encode(ByteStreams2.hashAndClose(input, md5()).asBytes()), md5);
}
origin: apache/jclouds

@Test(groups = "live")
public void testRemoteInputStreamSynch() throws Exception {
 try {
   URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl"));
   URLConnection connection = url.openConnection();
   HttpWire wire = setUpSynch();
   InputStream in = wire.input(connection.getInputStream());
   byte[] compare = ByteStreams2.hashAndClose(in, md5()).asBytes();
   Thread.sleep(100);
   assertEquals(base16().lowerCase().encode(compare), checkNotNull(sysHttpStreamMd5, sysHttpStreamMd5));
   assertEquals(((BufferLogger) wire.getWireLog()).buff.toString().getBytes().length, 3331484);
 } catch (UnknownHostException e) {
   // probably in offline mode
 }
}
origin: apache/jclouds

@Test(groups = "live")
public void testRemoteInputStream() throws Exception {
 try {
   URL url = new URL(checkNotNull(sysHttpStreamUrl, "sysHttpStreamUrl"));
   URLConnection connection = url.openConnection();
   HttpWire wire = setUp();
   InputStream in = wire.input(connection.getInputStream());
   byte[] compare = ByteStreams2.hashAndClose(in, md5()).asBytes();
   Thread.sleep(100);
   assertEquals(base16().lowerCase().encode(compare), checkNotNull(sysHttpStreamMd5, sysHttpStreamMd5));
   assertEquals(((BufferLogger) wire.getWireLog()).buff.toString().getBytes().length, 3331484);
 } catch (UnknownHostException e) {
   // probably in offline mode
 }
}
origin: apache/jclouds

private static void handlePost(HttpServletRequest request, HttpServletResponse response) throws IOException {
 InputStream body = request.getInputStream();
 try {
   if (request.getHeader("Content-MD5") != null) {
    String expectedMd5 = request.getHeader("Content-MD5");
    String realMd5FromRequest;
    realMd5FromRequest = base64().encode(ByteStreams2.hashAndClose(body, md5()).asBytes());
    boolean matched = expectedMd5.equals(realMd5FromRequest);
    if (matched) {
      response.setStatus(SC_OK);
      response.addHeader("x-Content-MD5", realMd5FromRequest);
    } else {
      response.sendError(500, "didn't match");
    }
   } else {
    String responseString = (request.getContentLength() < 10240) ? toStringAndClose(body) + "POST" : "POST";
    body = null;
    for (String header : new String[] { CONTENT_DISPOSITION, CONTENT_LANGUAGE, CONTENT_ENCODING })
      if (request.getHeader(header) != null) {
       response.addHeader("x-" + header, request.getHeader(header));
      }
    response.setStatus(SC_OK);
    response.getWriter().println(responseString);
   }
   Request.class.cast(request).setHandled(true);
 } catch (IOException e) {
   closeQuietly(body);
   response.sendError(500, getStackTraceAsString(e));
 }
}
origin: apache/jclouds

@Test(dependsOnMethods = "testListCookbookVersionsWithChefService")
public void testDownloadCookbooks() throws Exception {
 Iterable<? extends CookbookVersion> cookbooks = chefService.listCookbookVersions();
 for (CookbookVersion cookbook : cookbooks) {
   for (Resource resource : ImmutableList.<Resource> builder().addAll(cookbook.getDefinitions())
       .addAll(cookbook.getFiles()).addAll(cookbook.getLibraries()).addAll(cookbook.getSuppliers())
       .addAll(cookbook.getRecipes()).addAll(cookbook.getResources()).addAll(cookbook.getRootFiles())
       .addAll(cookbook.getTemplates()).addAll(cookbook.getAttributes()).build()) {
    InputStream stream = api.getResourceContents(resource);
    assertNotNull(stream, "Resource contents are null for resource: " + resource.getName());
    byte[] md5 = ByteStreams2.hashAndClose(stream, md5()).asBytes();
    assertEquals(md5, resource.getChecksum());
   }
 }
}
origin: apache/jclouds

  @Override public Void call() throws Exception {
   try {
     Blob blob = view.getBlobStore().getBlob(container, name);
     validateMetadata(blob.getMetadata(), container, name);
     assertEquals(hashAndClose(blob.getPayload().openStream(), md5()), supplier.hash(md5()));
   } catch (IOException e) {
     Throwables.propagate(e);
   }
   return null;
  }
}));
org.jclouds.ioByteStreams2hashAndClose

Popular methods of ByteStreams2

  • toByteArrayAndClose

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getExternalFilesDir (Context)
  • setRequestProperty (URLConnection)
  • startActivity (Activity)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JList (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • 21 Best IntelliJ Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now