/** * @see HttpMessage#getPayload() */ public T payload(File payload) { this.payload = Payloads.newFilePayload(checkNotNull(payload, "payload")); return self(); }
/** * @see HttpMessage#getPayload() */ public T payload(File payload) { this.payload = Payloads.newFilePayload(checkNotNull(payload, "payload")); return self(); }
/** * @see HttpMessage#getPayload() * @deprecated see payload(Files.asByteSource(File)) */ @Deprecated public T payload(File payload) { this.payload = Payloads.newFilePayload(checkNotNull(payload, "payload")); return self(); }
/** * @see HttpMessage#getPayload() */ public T payload(File payload) { this.payload = Payloads.newFilePayload(checkNotNull(payload, "payload")); return self(); }
/** * @see HttpMessage#getPayload() */ public T payload(File payload) { this.payload = Payloads.newFilePayload(checkNotNull(payload, "payload")); return self(); }
/** * @see HttpMessage#getPayload() */ public T payload(File payload) { this.payload = Payloads.newFilePayload(checkNotNull(payload, "payload")); return self(); }
public static Payload newPayload(Object data) { checkNotNull(data, "data"); if (data instanceof Payload) { return (Payload) data; } else if (data instanceof InputStream) { return newInputStreamPayload((InputStream) data); } else if (data instanceof byte[]) { return newByteArrayPayload((byte[]) data); } else if (data instanceof String) { return newStringPayload((String) data); } else if (data instanceof File) { return newFilePayload((File) data); } else { throw new UnsupportedOperationException("unsupported payload type: " + data.getClass()); } }
public static Payload newPayload(Object data) { checkNotNull(data, "data"); if (data instanceof Payload) { return (Payload) data; } else if (data instanceof InputStream) { return newInputStreamPayload((InputStream) data); } else if (data instanceof byte[]) { return newByteArrayPayload((byte[]) data); } else if (data instanceof String) { return newStringPayload((String) data); } else if (data instanceof File) { return newFilePayload((File) data); } else { throw new UnsupportedOperationException("unsupported payload type: " + data.getClass()); } }
public static Payload newPayload(Object data) { checkNotNull(data, "data"); if (data instanceof Payload) { return (Payload) data; } else if (data instanceof InputStream) { return newInputStreamPayload((InputStream) data); } else if (data instanceof byte[]) { return newByteArrayPayload((byte[]) data); } else if (data instanceof ByteSource) { return newByteSourcePayload((ByteSource) data); } else if (data instanceof String) { return newStringPayload((String) data); } else if (data instanceof File) { return newFilePayload((File) data); } else { throw new UnsupportedOperationException("unsupported payload type: " + data.getClass()); } }
/** * @deprecated see newPayload(ByteSource) or newPayload(InputStream) */ @Deprecated public static Payload newPayload(Object data) { checkNotNull(data, "data"); if (data instanceof Payload) { return (Payload) data; } else if (data instanceof InputStream) { return newInputStreamPayload((InputStream) data); } else if (data instanceof byte[]) { return newByteArrayPayload((byte[]) data); } else if (data instanceof ByteSource) { return newByteSourcePayload((ByteSource) data); } else if (data instanceof String) { return newStringPayload((String) data); } else if (data instanceof File) { return newFilePayload((File) data); } else { throw new UnsupportedOperationException("unsupported payload type: " + data.getClass()); } }
public static Payload newPayload(Object data) { checkNotNull(data, "data"); if (data instanceof Payload) { return (Payload) data; } else if (data instanceof InputStream) { return newInputStreamPayload((InputStream) data); } else if (data instanceof byte[]) { return newByteArrayPayload((byte[]) data); } else if (data instanceof ByteSource) { return newByteSourcePayload((ByteSource) data); } else if (data instanceof String) { return newStringPayload((String) data); } else if (data instanceof File) { return newFilePayload((File) data); } else { throw new UnsupportedOperationException("unsupported payload type: " + data.getClass()); } }
public static Payload newPayload(Object data) { checkNotNull(data, "data"); if (data instanceof Payload) { return (Payload) data; } else if (data instanceof InputStream) { return newInputStreamPayload((InputStream) data); } else if (data instanceof byte[]) { return newByteArrayPayload((byte[]) data); } else if (data instanceof ByteSource) { return newByteSourcePayload((ByteSource) data); } else if (data instanceof String) { return newStringPayload((String) data); } else if (data instanceof File) { return newFilePayload((File) data); } else { throw new UnsupportedOperationException("unsupported payload type: " + data.getClass()); } }
private void uploadToNode(ComputeServiceContext context, NodeMetadata node, LoginCredentials credentials, URL url, String path) { Utils utils = context.utils(); SshClient ssh = credentials != null ? utils .sshForNode() .apply(NodeMetadataBuilder.fromNodeMetadata(nodeMetadata) .credentials(credentials).build()) : utils.sshForNode().apply(node); try (InputStream is = url.openStream(); ) { ssh.connect(); File distro = Files.createTempFile("/tmp"); Files.copy(is, new FileOutputStream(distro)); ssh.put(path, Payloads.newFilePayload(distro)); distro.delete(); } catch (IOException e) { LOGGER.warn("Failed to upload. Will attempt downloading distribution via maven."); } finally { if (ssh != null) { ssh.disconnect(); } } } }
Payload payload = newFilePayload(f); byte[] digest = digester.digest(); payload.getContentMetadata().setContentMD5(digest);
payloadFile.deleteOnExit(); final Payload testPayload = Payloads.newFilePayload(payloadFile); final byte[] md5 = md5Supplier(testPayload); testPayload.getContentMetadata().setContentType("image/png");
private FilePayload uploadContent(String fileName) throws Exception { // Define the file you want in the cookbook File file = new File(System.getProperty("user.dir"), fileName); FilePayload content = Payloads.newFilePayload(file); content.getContentMetadata().setContentType("application/x-binary"); // Get an md5 so that you can see if the server already has it or not content.getContentMetadata().setContentMD5(Files.asByteSource(file).hash(Hashing.md5()).asBytes()); // Note that java collections cannot effectively do equals or hashcodes on // byte arrays, so let's convert to a list of bytes. List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5()); // Request an upload site for this file UploadSandbox site = api.createUploadSandboxForChecksums(ImmutableSet.of(md5)); assertTrue(site.getChecksums().containsKey(md5), md5 + " not in " + site.getChecksums()); try { // Upload the file contents, if still not uploaded ChecksumStatus status = site.getChecksums().get(md5); if (status.needsUpload()) { api.uploadContent(status.getUrl(), content); } Sandbox sandbox = api.commitSandbox(site.getSandboxId(), true); assertTrue(sandbox.isCompleted(), "Sandbox should be completed after uploading"); } catch (RuntimeException e) { api.commitSandbox(site.getSandboxId(), false); fail("Could not upload content", e); } return content; }
private FilePayload uploadAndGetFilePayload(File file) throws IOException { FilePayload content = Payloads.newFilePayload(file); content.getContentMetadata().setContentType("application/x-binary"); // Get an md5 so that you can see if the server already has it or not content.getContentMetadata().setContentMD5(Files.asByteSource(file).hash(Hashing.md5()).asBytes()); // Note that java collections cannot effectively do equals or hashcodes on // byte arrays, so let's convert to a list of bytes. List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5()); // Request an upload site for this file UploadSandbox site = api.createUploadSandboxForChecksums(ImmutableSet.of(md5)); assertTrue(site.getChecksums().containsKey(md5), md5 + " not in " + site.getChecksums()); try { // Upload the file contents, if still not uploaded ChecksumStatus status = site.getChecksums().get(md5); if (status.needsUpload()) { api.uploadContent(status.getUrl(), content); } Sandbox sandbox = api.commitSandbox(site.getSandboxId(), true); assertTrue(sandbox.isCompleted(), "Sandbox should be completed after uploading"); } catch (RuntimeException e) { api.commitSandbox(site.getSandboxId(), false); fail("Could not upload content"); } return content; }
public void testCreateNewCookbook() throws Exception { // define the file you want in the cookbook FilePayload content = Payloads.newFilePayload(new File(System.getProperty("user.dir"), "pom.xml")); content.getContentMetadata().setContentType("application/x-binary"); // get an md5 so that you can see if the server already has it or not Payloads.calculateMD5(content); // Note that java collections cannot effectively do equals or hashcodes on // byte arrays, // so let's convert to a list of bytes. List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5()); // request an upload site for this file UploadSandbox site = api.getUploadSandboxForChecksums(ImmutableSet.of(md5)); try { assert site.getChecksums().containsKey(md5) : md5 + " not in " + site.getChecksums(); ChecksumStatus status = site.getChecksums().get(md5); if (status.needsUpload()) { // context.utils().http().put(status.getUrl(), content); api.uploadContent(status.getUrl(), content); } api.commitSandbox(site.getSandboxId(), true); } catch (RuntimeException e) { api.commitSandbox(site.getSandboxId(), false); } // create a new cookbook CookbookVersion cookbook = new CookbookVersion(PREFIX, "0.0.0"); cookbook.getRootFiles().add(new Resource(content)); // upload the cookbook to the remote server api.updateCookbook(PREFIX, "0.0.0", cookbook); }