public static KnownSizeInputStream of(byte[] contents) { return new KnownSizeInputStream(new ByteArrayInputStream(contents), contents.length); }
public static KnownSizeInputStream of(String contents) { return of(contents.getBytes()); }
@Override public int copyToServer(Map<String,?> props, InputStream contents, String pathAndFileOnRemoteServer) { /* sshj needs to: * 1) to know the length of the InputStream to copy the file to perform copy; and * 2) re-read the input stream on retry if the first attempt fails. * For now, write it to a file, unless caller supplies a KnownSizeInputStream * * (We could have a switch where we hold it in memory if less than some max size, * but most the routines should supply a string or byte array or similar, * so we probably don't come here too often.) */ if (contents instanceof KnownSizeInputStream) { return copyToServer(props, Suppliers.ofInstance(contents), ((KnownSizeInputStream)contents).length(), pathAndFileOnRemoteServer); } else { File tempFile = writeTempFile(contents); try { return copyToServer(props, tempFile, pathAndFileOnRemoteServer); } finally { tempFile.delete(); } } }
public static InputStream newInputStreamWithContents(String contents) { byte[] bytes = checkNotNull(contents, "contents").getBytes(Charsets.UTF_8); return KnownSizeInputStream.of(bytes); }
@Override public Integer apply(ShellTool ssh) { return ((SshTool) ssh).copyToServer(props, new KnownSizeInputStream(src, filesize), destination); }}); }
public SshPutTaskFactory contents(String contents) { markDirty(); this.contents = Suppliers.ofInstance(KnownSizeInputStream.of(contents)); return self(); }
entity.getDriver().copyResource(new KnownSizeInputStream(Streams.newInputStreamWithContents(tempLocalContent), tempLocalContent.length()), tempDest.getAbsolutePath()); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); tempDest.delete();
public SshPutTaskFactory contents(byte[] contents) { markDirty(); this.contents = Suppliers.ofInstance(KnownSizeInputStream.of(contents)); return self(); }
/** returns the creation script contents, if it exists, or null if none is defined (error if it cannot be loaded) */ @Nullable public static InputStream getDatabaseCreationScript(Entity entity) { String url = entity.getConfig(DatastoreMixins.CREATION_SCRIPT_URL); if (!Strings.isBlank(url)) return new ResourceUtils(entity).getResourceFromUrl(url); String templateUrl = entity.getConfig(DatastoreMixins.CREATION_SCRIPT_TEMPLATE); if (!Strings.isBlank(templateUrl)) { String template = TemplateProcessor.processTemplateContents(new ResourceUtils(entity).getResourceAsString(templateUrl), (EntityInternal) entity, ImmutableMap.<String, Object>of()); try { return new ByteArrayInputStream(template.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw Exceptions.propagate(e); } } String contents = entity.getConfig(DatastoreMixins.CREATION_SCRIPT_CONTENTS); if (!Strings.isBlank(contents)) return KnownSizeInputStream.of(contents); return null; }