private void copy(InputStream in, File tmpJar) { try { OutputStream out = new FileOutputStream(tmpJar); ByteStreams.copy(in, out); Streams.closeQuietly(in); Streams.closeQuietly(out); } catch (Exception e) { throw Exceptions.propagate(e); } }
public void logTailOfPostgresLog() { try { File file = Os.newTempFile("postgresql-" + getEntity().getId(), "log"); int result = getMachine().copyFrom(getLogFile(), file.getAbsolutePath()); if (result != 0) throw new IllegalStateException("Could not access log file " + getLogFile()); log.info("Saving {} contents as {}", getLogFile(), file); Streams.logStreamTail( log, "postgresql.log", Streams.byteArrayOfString(Files.toString(file, Charsets.UTF_8)), 1024); file.delete(); } catch (IOException ioe) { log.debug("Error reading copied log file: {}", ioe); } }
@Override public int copyResource( Map<Object, Object> sshFlags, String source, String target, boolean createParentDir) { if (createParentDir) { createDirectory(getDirectory(target), "Creating resource directory"); } InputStream stream = null; try { Tasks.setBlockingDetails("retrieving resource " + source + " for copying across"); stream = resource.getResourceFromUrl(source); Tasks.setBlockingDetails("copying resource " + source + " to server"); return copyTo(stream, target); } catch (Exception e) { throw Exceptions.propagate(e); } finally { Tasks.setBlockingDetails(null); if (stream != null) Streams.closeQuietly(stream); } }
public ProcessTaskWrapper<Integer> executeScriptAsync(String commands) { String filename = "postgresql-commands-" + Identifiers.makeRandomId(8); installFile(Streams.newInputStreamWithContents(commands), filename); return executeScriptFromInstalledFileAsync(filename); }