private void putBlob(Blob blob, OutputStream stdout) throws IOException { byte[] buf = new byte[1024]; try (InputStream in = blob.open()) { while (true) { int read = in.read(buf); if (read < 0) { break; } stdout.write(buf, 0, read); } } }
/** * Returns the file suffix for the extension. * @param extension the extension name * @param blob the target BLOB * @return the target file name suffix */ public static String getSuffix(String extension, Blob blob) { return String.format(".%s.%s", extension, blob.getFileExtension()); } }
private void send( Session session, Blob blob, String remotePath, int localIndex, OutputStream output) throws IOException, JSchException { long size = blob.getSize(); String exec = String.format("scp -t \"%s\"", toLiteral(remotePath)); //$NON-NLS-1$ String header = String.format("C0644 %d BLOB-%d", size, localIndex); //$NON-NLS-1$ YSLOG.info("I01001", size, remotePath); long start = System.currentTimeMillis(); ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(exec); channel.setErrStream(output, true); try (InputStream stdin = channel.getInputStream(); OutputStream stdout = channel.getOutputStream()) { channel.connect(); stdout.write(header.getBytes(ENCODING)); stdout.write('\n'); stdout.flush(); checkAck(blob, stdin); putBlob(blob, stdout); stdout.write(0); stdout.flush(); checkAck(blob, stdin); } finally { channel.disconnect(); } long end = System.currentTimeMillis(); YSLOG.info("I01002", size, remotePath, end - start); }
private static String resolve(String extension, Blob blob, TemporaryFiles temporaries) throws IOException { if (blob instanceof FileBlob) { return ((FileBlob) blob).getFile().getAbsolutePath(); } String suffix = BlobUtil.getSuffix(extension, blob); try (InputStream in = blob.open()) { return temporaries.create(BLOB_FILE_PREFIX, suffix, in).getAbsolutePath(); } }