コード例 #1
0
 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);
   }
 }
  @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);
    }
  }