Tabnine Logo
ByteStreams2.toByteArrayAndClose
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: apache/jclouds

public String sign(String toSign) {
 try {
   byte[] encrypted = ByteStreams2.toByteArrayAndClose(new RSAEncryptingPayload(crypto, Payloads.newStringPayload(toSign), supplyKey.get()).openStream());
   return base64().encode(encrypted);
 } catch (IOException e) {
   throw new HttpException("error signing request", e);
 }
}
origin: org.apache.jclouds.api/chef

public String sign(String toSign) {
 try {
   byte[] encrypted = ByteStreams2.toByteArrayAndClose(new RSAEncryptingPayload(crypto, Payloads.newStringPayload(toSign), supplyKey.get()).openStream());
   return base64().encode(encrypted);
 } catch (IOException e) {
   throw new HttpException("error signing request", e);
 }
}
origin: org.apache.jclouds.api/chef

@Override
public byte[] decrypt(InputStream input) throws IOException {
 @SuppressWarnings("resource")
 Payload payload = new RSADecryptingPayload(crypto, Payloads.newPayload(input), privateKey.get());
 return ByteStreams2.toByteArrayAndClose(payload.openStream());
}
origin: org.apache.jclouds.api/chef

@Override
public byte[] encrypt(InputStream input) throws IOException {
 @SuppressWarnings("resource")
 Payload payload = new RSAEncryptingPayload(crypto, Payloads.newPayload(input), privateKey.get());
 return ByteStreams2.toByteArrayAndClose(payload.openStream());
}
origin: apache/jclouds

@Override
public byte[] encrypt(InputStream input) throws IOException {
 @SuppressWarnings("resource")
 Payload payload = new RSAEncryptingPayload(crypto, Payloads.newPayload(input), privateKey.get());
 return ByteStreams2.toByteArrayAndClose(payload.openStream());
}
origin: apache/jclouds

@Override
public byte[] decrypt(InputStream input) throws IOException {
 @SuppressWarnings("resource")
 Payload payload = new RSADecryptingPayload(crypto, Payloads.newPayload(input), privateKey.get());
 return ByteStreams2.toByteArrayAndClose(payload.openStream());
}
origin: apache/jclouds

@Test(groups = "live", dependsOnMethods = "testGetObject")
public void testCopyObject() throws IOException {
 GoogleCloudStorageObject gcsObject = api().copyObject(BUCKET_NAME2, COPIED_OBJECT_NAME, BUCKET_NAME, UPLOAD_OBJECT_NAME);
 assertNotNull(gcsObject);
 assertEquals(gcsObject.bucket(), BUCKET_NAME2);
 assertEquals(gcsObject.name(), COPIED_OBJECT_NAME);
 assertEquals(gcsObject.contentType(), "text/plain");
 // Test for data
 PayloadEnclosing impl = api().download(BUCKET_NAME2, COPIED_OBJECT_NAME);
 assertNotNull(impl);
 assertEquals(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream()),
      ByteStreams2.toByteArrayAndClose(testPayload.getPayload().openStream()));
}
origin: apache/jclouds

@Test(groups = "live", dependsOnMethods = "testRewrite")
public void testDownload() throws IOException {
 PayloadEnclosing impl = api().download(BUCKET_NAME, UPLOAD_OBJECT_NAME);
 ContentMetadata meta = impl.getPayload().getContentMetadata();
 assertNotNull(impl);
 assertNotNull(impl.getPayload());
 assertNotNull(meta);
 assertEquals(meta.getContentType(), "text/plain");
 testPayload.getPayload().getContentMetadata().setContentDisposition("attachment");
 assertEquals(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream()),
      ByteStreams2.toByteArrayAndClose(testPayload.getPayload().openStream()));
}
origin: apache/jclouds

@Test(groups = "live", dependsOnMethods = "testGetObject")
public void testCopyObjectWithUpdatedMetadata() throws IOException {
 String METADATA_KEY = "key1";
 String METADATA_VALUE = "value1";
 ObjectTemplate template = new ObjectTemplate().contentLanguage("fr").contentType("text/plain")
      .contentDisposition("attachment").customMetadata(METADATA_KEY, METADATA_VALUE);
 GoogleCloudStorageObject gcsObject = api().copyObject(BUCKET_NAME2, COPIED_OBJECT_NAME2, BUCKET_NAME, UPLOAD_OBJECT_NAME, template);
 assertNotNull(gcsObject);
 assertEquals(gcsObject.bucket(), BUCKET_NAME2);
 assertEquals(gcsObject.name(), COPIED_OBJECT_NAME2);
 assertNotNull(gcsObject.acl());
 assertEquals(gcsObject.contentType(), "text/plain");
 assertEquals(gcsObject.metadata().get(METADATA_KEY), METADATA_VALUE);
 assertEquals(gcsObject.contentLanguage(), "fr");
 // Test for data
 PayloadEnclosing impl = api().download(BUCKET_NAME2, COPIED_OBJECT_NAME2);
 assertNotNull(impl);
 assertEquals(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream()),
      ByteStreams2.toByteArrayAndClose(testPayload.getPayload().openStream()));
}
origin: apache/jclouds

@Override
@BeforeClass(groups = "live")
public void setup() {
 super.setup();
 for (String regionId : regions) {
   boolean created = getApi().getContainerApi(regionId).create(containerName);
   if (!created) {
    deleteAllObjectsInContainer(regionId, containerName);
   }
 }
 GenericArchive files = ShrinkWrap.create(GenericArchive.class, "files.tar.gz");
 StringAsset content = new StringAsset("foo");
 for (int i = 0; i < OBJECT_COUNT; i++) {
   paths.add(containerName + "/file" + i);
   files.add(content, "/file" + i);
 }
 try {
   tarGz = ByteStreams2.toByteArrayAndClose(files.as(TarGzExporter.class).exportAsInputStream());
 } catch (IOException e) {
   throw Throwables.propagate(e);
 }
}
origin: apache/jclouds

public void testGetBlob() throws IOException {
  String blobKey = TestUtils.createRandomBlobKey();
  GetOptions options = null;
  Blob resultBlob;
  blobStore.createContainerInLocation(null, CONTAINER_NAME);
  resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
  assertNull(resultBlob, "Blob exists");
  // create blob
  TestUtils.createBlobsInContainer(CONTAINER_NAME, blobKey);
  resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
  assertNotNull(resultBlob, "Blob exists");
  // checks file content
  ByteSource expectedFile = Files.asByteSource(new File(TARGET_CONTAINER_NAME, blobKey));
  assertEquals(expectedFile.read(), ByteStreams2.toByteArrayAndClose(resultBlob.getPayload().openStream()),
      "Blob payload differs from file content");
  // metadata are verified in the test for blobMetadata, so no need to
  // perform a complete test here
  assertNotNull(resultBlob.getMetadata(), "Metadata null");
  MutableBlobMetadata metadata = resultBlob.getMetadata();
  assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
}
origin: apache/jclouds

@SuppressWarnings("resource")
public void testEncryptionWithClientPriv() throws IOException, CertificateException, NoSuchAlgorithmException {
 Client user = Client.builder().certificate(certificate).orgname("jclouds").clientname("adriancole-jcloudstest")
     .name("adriancole-jcloudstest").isValidator(false).privateKey(privateKey).publicKey(publicKey).build();
 byte[] encrypted = ByteStreams2.toByteArrayAndClose(new RSAEncryptingPayload(new JCECrypto(), Payloads.newPayload("fooya"), user
     .getCertificate().getPublicKey()).openStream());
 assertEquals(
     ByteStreams2.toByteArrayAndClose(new RSADecryptingPayload(new JCECrypto(), Payloads.newPayload(encrypted), user.getPrivateKey()).openStream()),
     "fooya".getBytes());
 assertEquals(
     handler.apply(HttpResponse.builder().statusCode(200).message("ok")
         .payload(ParseClientFromJsonTest.class.getResourceAsStream("/client.json")).build()), user);
}
origin: apache/jclouds

@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" })
public void testCopyBlob() throws Exception {
 ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024);
 // create blob
 AzureBlob object = getApi().newBlob();
 object.getProperties().setName("from");
 object.setPayload(byteSource.read());
 getApi().putBlob(privateContainer, object);
 // copy blob
 URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint();
 getApi().copyBlob(copySource, privateContainer, "to", CopyBlobOptions.NONE);
 // ensure copied blob matches original
 AzureBlob getBlob = getApi().getBlob(privateContainer, "to");
 assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read());
 assertThat(getBlob.getProperties().getMetadata().isEmpty());
}
origin: apache/jclouds

@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" })
public void testCopyBlobIfUnmodifiedSince() throws Exception {
 ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024);
 // create blob
 AzureBlob object = getApi().newBlob();
 object.getProperties().setName("from");
 object.setPayload(byteSource.read());
 String eTag = getApi().putBlob(privateContainer, object);
 long now = System.currentTimeMillis();
 Date before = new Date(now - 1000 * 1000);
 Date after = new Date(now + 1000 * 1000);
 URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint();
 // failure case
 try {
   getApi().copyBlob(copySource, privateContainer, "to-if-unmodifed-since", CopyBlobOptions.builder().ifUnmodifiedSince(before).build());
   failBecauseExceptionWasNotThrown(AzureStorageResponseException.class);
 } catch (AzureStorageResponseException asre) {
   assertThat(asre.getResponse().getStatusCode()).as("status code").isEqualTo(412);
 }
 // success case
 getApi().copyBlob(copySource, privateContainer, "to-if-unmodifed-since", CopyBlobOptions.builder().ifUnmodifiedSince(after).build());
 AzureBlob getBlob = getApi().getBlob(privateContainer, "to-if-unmodifed-since");
 assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read());
}
origin: apache/jclouds

@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" })
public void testCopyBlobIfModifiedSince() throws Exception {
 ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024);
 // create blob
 AzureBlob object = getApi().newBlob();
 object.getProperties().setName("from");
 object.setPayload(byteSource.read());
 String eTag = getApi().putBlob(privateContainer, object);
 long now = System.currentTimeMillis();
 Date before = new Date(now - 1000 * 1000);
 Date after = new Date(now + 1000 * 1000);
 URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint();
 // failure case
 try {
   getApi().copyBlob(copySource, privateContainer, "to-if-modified-since", CopyBlobOptions.builder().ifModifiedSince(after).build());
   failBecauseExceptionWasNotThrown(AzureStorageResponseException.class);
 } catch (AzureStorageResponseException asre) {
   assertThat(asre.getResponse().getStatusCode()).as("status code").isEqualTo(412);
 }
 // success case
 getApi().copyBlob(copySource, privateContainer, "to-if-modified-since", CopyBlobOptions.builder().ifModifiedSince(before).build());
 AzureBlob getBlob = getApi().getBlob(privateContainer, "to-if-modified-since");
 assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read());
}
origin: apache/jclouds

@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" })
public void testCopyBlobReplaceMetadata() throws Exception {
 ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024);
 // create blob
 AzureBlob object = getApi().newBlob();
 object.getProperties().setName("from");
 object.setPayload(byteSource.read());
 getApi().putBlob(privateContainer, object);
 // copy blob
 URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint();
 Map<String, String> newMetadata = ImmutableMap.of("foo", "bar");
 getApi().copyBlob(copySource, privateContainer, "to", CopyBlobOptions.builder().overrideUserMetadata(newMetadata).build());
 // ensure copied blob matches original
 AzureBlob getBlob = getApi().getBlob(privateContainer, "to");
 assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read());
 assertThat(getBlob.getProperties().getMetadata()).isEqualTo(newMetadata);
}
origin: apache/jclouds

@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" })
public void testCopyBlobIfMatch() throws Exception {
 ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024);
 // create blob
 AzureBlob object = getApi().newBlob();
 object.getProperties().setName("from");
 object.setPayload(byteSource.read());
 String eTag = getApi().putBlob(privateContainer, object);
 String fakeETag = "0x8CEB669D794AFE2";
 URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint();
 // failure case
 try {
   getApi().copyBlob(copySource, privateContainer, "to-if-match", CopyBlobOptions.builder().ifMatch(fakeETag).build());
   failBecauseExceptionWasNotThrown(AzureStorageResponseException.class);
 } catch (AzureStorageResponseException asre) {
   assertThat(asre.getResponse().getStatusCode()).as("status code").isEqualTo(412);
 }
 // success case
 getApi().copyBlob(copySource, privateContainer, "to-if-match", CopyBlobOptions.builder().ifMatch(eTag).build());
 AzureBlob getBlob = getApi().getBlob(privateContainer, "to-if-match");
 assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read());
}
origin: apache/jclouds

@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateContainer" })
public void testCopyBlobIfNoneMatch() throws Exception {
 ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024);
 // create blob
 AzureBlob object = getApi().newBlob();
 object.getProperties().setName("from");
 object.setPayload(byteSource.read());
 String eTag = getApi().putBlob(privateContainer, object);
 String fakeETag = "0x8CEB669D794AFE2";
 URI copySource = view.getSigner().signGetBlob(privateContainer, "from").getEndpoint();
 // failure case
 try {
   getApi().copyBlob(copySource, privateContainer, "to-if-none-match", CopyBlobOptions.builder().ifNoneMatch(eTag).build());
   failBecauseExceptionWasNotThrown(AzureStorageResponseException.class);
 } catch (AzureStorageResponseException asre) {
   assertThat(asre.getResponse().getStatusCode()).as("status code").isEqualTo(412);
 }
 // success case
 getApi().copyBlob(copySource, privateContainer, "to-if-none-match", CopyBlobOptions.builder().ifNoneMatch(fakeETag).build());
 AzureBlob getBlob = getApi().getBlob(privateContainer, "to-if-none-match");
 assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read());
}
origin: apache/jclouds

@Override
public Void call() throws Exception {
 Payload payload = Payloads.newByteSourcePayload(expected);
 payload.getContentMetadata().setContentType("image/png");
 Blob blob = view.getBlobStore().blobBuilder(name).payload(payload).contentLength(expected.size()).build();
 view.getBlobStore().putBlob(container, blob);
 assertConsistencyAwareBlobExists(container, name);
 blob = view.getBlobStore().getBlob(container, name);
 byte[] actual = ByteStreams2.toByteArrayAndClose(blob.getPayload().openStream());
 assertThat(actual).isEqualTo(expected.read());
 view.getBlobStore().removeBlob(container, name);
 assertConsistencyAwareBlobDoesntExist(container, name);
 return null;
}
origin: apache/jclouds

public void testMultipartCopy() throws Exception {
 String containerName = getContainerName();
 try {
   String fromObject = "fromObject";
   S3Object object = getApi().newS3Object();
   object.getMetadata().setKey(fromObject);
   object.setPayload(oneHundredOneConstitutions);
   object.getMetadata().getContentMetadata().setContentLength(oneHundredOneConstitutions.size());
   getApi().putObject(containerName, object);
   String toObject = "toObject";
   String uploadId = getApi().initiateMultipartUpload(containerName, ObjectMetadataBuilder.create().key(toObject).build());
   String eTagOf1 = getApi().uploadPartCopy(containerName, toObject, 1, uploadId, containerName, fromObject, 1, oneHundredOneConstitutions.size() - 1);
   getApi().completeMultipartUpload(containerName, toObject, uploadId, ImmutableMap.of(1, eTagOf1));
   object = getApi().getObject(containerName, toObject);
   assertEquals(ByteStreams2.toByteArrayAndClose(object.getPayload().openStream()), oneHundredOneConstitutions.slice(1, oneHundredOneConstitutions.size() - 1).read());
 } finally {
   returnContainer(containerName);
 }
}
org.jclouds.ioByteStreams2toByteArrayAndClose

Popular methods of ByteStreams2

  • hashAndClose

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Menu (java.awt)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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