Esempio n. 1
0
  /*
   * (non-Javadoc)
   *
   * @see org.apache.ivy.repository.Repository#get(java.lang.String, java.io.File)
   */
  public void get(String source, File destination) throws IOException {
    Message.debug("SShRepository:get called: " + source + " to " + destination.getCanonicalPath());
    if (destination.getParentFile() != null) {
      destination.getParentFile().mkdirs();
    }
    Session session = getSession(source);

    URI sourceUri = null;
    try {
      sourceUri = new URI(source);
    } catch (URISyntaxException e) {
      IOException ioe = new IOException("The uri '" + source + "' is not valid!");
      ioe.initCause(e);
      throw ioe;
    }

    try {
      Scp myCopy = new Scp(session);
      myCopy.get(sourceUri.getPath(), destination.getCanonicalPath());
    } catch (IOException e) {
      if (session != null) {
        releaseSession(session, source);
      }
      throw e;
    } catch (RemoteScpException e) {
      throw new IOException(e.getMessage());
    }
  }
Esempio n. 2
0
 /**
  * Not really streaming...need to implement a proper streaming approach?
  *
  * @param resource to stream
  * @return InputStream of the resource data
  */
 public InputStream openStream(SshResource resource) throws IOException {
   Session session = getSession(resource.getName());
   Scp scp = new Scp(session);
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   try {
     scp.get(resource.getName(), os);
   } catch (IOException e) {
     if (session != null) {
       releaseSession(session, resource.getName());
     }
     throw e;
   } catch (RemoteScpException e) {
     throw new IOException(e.getMessage());
   }
   return new ByteArrayInputStream(os.toByteArray());
 }