Ejemplo 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());
    }
  }
Ejemplo 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());
 }
Ejemplo n.º 3
0
  /*
   * (non-Javadoc)
   *
   * @see org.apache.ivy.repository.Repository#put(java.io.File, java.lang.String, boolean)
   */
  public void put(File source, String destination, boolean overwrite) throws IOException {
    Message.debug("SShRepository:put called: " + destination);
    Session session = getSession(destination);

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

    try {
      String filePath = destinationUri.getPath();
      int lastSep = filePath.lastIndexOf(fileSeparator);
      String path;
      String name;
      if (lastSep == -1) {
        name = filePath;
        path = null;
      } else {
        name = filePath.substring(lastSep + 1);
        path = filePath.substring(0, lastSep);
      }
      if (!overwrite) {
        if (checkExistence(filePath, session)) {
          throw new IOException("destination file exists and overwrite == false");
        }
      }
      if (path != null) {
        makePath(path, session);
      }
      Scp myCopy = new Scp(session);
      myCopy.put(source.getCanonicalPath(), path, name, publishPermissions);
    } catch (IOException e) {
      if (session != null) {
        releaseSession(session, destination);
      }
      throw e;
    } catch (RemoteScpException e) {
      throw new IOException(e.getMessage());
    }
  }