Package de.fzj.unicore.uas.client

Examples of de.fzj.unicore.uas.client.FileTransferClient


    if(source==null || source.getIsDirectory()){
      throw new IllegalStateException("Source="+source);
    }
   
    OutputStream os=targetStream!=null?targetStream:null;
    FileTransferClient ftc=null;
    try{
      String path=source.getPath();
      if(targetStream==null){
        if(localFile.isDirectory()){
          localFile=new File(localFile,getName(source.getPath()));
        }
        if(mode.equals(Mode.nooverwrite) && localFile.exists()){
          System.out.println("File exists and creation mode was set to 'nooverwrite'.");
          return;
        }
        System.out.println("Downloading remote file '"+sms.getUrl()+"#/"+path+"' -> "+localFile.getAbsolutePath());
        os=new FileOutputStream(localFile.getAbsolutePath(), mode.equals(Mode.append));
      }
     
      chosenProtocol=sms.findSupportedProtocol(preferredProtocols.toArray(new ProtocolType.Enum[preferredProtocols.size()]));
      Map<String,String>extraParameters=makeExtraParameters(chosenProtocol);
      ftc=sms.getExport(path,extraParameters,chosenProtocol);
      configure(ftc, extraParameters);
      System.out.println("DEB:File transfer URL : "+ftc.getUrl());
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable  && showProgress){
        long size=ftc.getSourceFileSize();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      long startTime=System.currentTimeMillis();
      if(isRange()){
        if(!(ftc instanceof SupportsPartialRead)){
          throw new Exception("Byte range is defined but protocol does not allow " +
              "partial read! Please choose a different protocol!");
        }
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        SupportsPartialRead pReader=(SupportsPartialRead)ftc;
        pReader.readPartial(startByte, endByte-startByte+1, os);
      }
      else{
        ftc.readAllData(os);
      }
//      if(p!=null){
//        p.finish();
//      }
      if(timing){
        long duration=System.currentTimeMillis()-startTime;
        double rate=(double)localFile.length()/(double)duration;
        System.out.println("Rate: " +rate+ " kB/sec.");
      }
      if(targetStream==null)copyProperties(source, localFile);
    }
    finally{
      try{
        if(targetStream==null && os!=null){
          os.close();
        }
      }catch(Exception ignored){}
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          System.out.println("Could not destroy the filetransfer client",e1);
        }
      }
    }
View Full Code Here


   */
  private void uploadFile(File localFile, String remotePath, StorageClient sms, ProtocolType.Enum protocol,
      Map<String,String>extraParameters) throws Exception{
    long startTime=System.currentTimeMillis();
    FileInputStream is=null;
    FileTransferClient ftc=null;
    try{
      if(remotePath==null){
        remotePath="/"+localFile.getName();
      }
      else if(remotePath.endsWith("/")){
        remotePath+=localFile.getName();
      }
      System.out.println("Uploading local file '"+localFile.getAbsolutePath()+"' -> '"+sms.getUrl()+"#"+remotePath+"'");
      is=new FileInputStream(localFile.getAbsolutePath());
      boolean append=Mode.append.equals(mode);
      ftc=sms.getImport(remotePath, append, extraParameters, protocol);
      configure(ftc, extraParameters);
      if(append)ftc.setAppend(true);
      String url=ftc.getUrl();
      System.out.println("File transfer URL : "+url);
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable){
        long size=localFile.length();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      if(isRange()){
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        long skipped=0;
        while(skipped<startByte){
          skipped+=is.skip(startByte);
        }
        ftc.writeAllData(is, endByte-startByte+1);
       
      }else{
        ftc.writeAllData(is);
      }
      copyProperties(localFile, sms, remotePath);
     
//      if(ftc instanceof IMonitorable){
//        p.finish();
//      }
     
    }finally{
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          msg.error("Could not clean-up the filetransfer at <"+ftc.getUrl()+">",e1);
        }
      }
      try{ if(is!=null)is.close(); }catch(Exception ignored){}
View Full Code Here

    if(source==null || source.getIsDirectory()){
      throw new IllegalStateException("Source="+source);
    }
   
    OutputStream os=targetStream!=null?targetStream:null;
    FileTransferClient ftc=null;
    try{
      String path=source.getPath();
      if(targetStream==null){
        if(localFile.isDirectory()){
          localFile=new File(localFile,getName(source.getPath()));
        }
        if(mode.equals(Mode.nooverwrite) && localFile.exists()){
          System.out.println("File exists and creation mode was set to 'nooverwrite'.");
          return;
        }
        System.out.println("Downloading remote file '"+sms.getUrl()+"#/"+path+"' -> "+localFile.getAbsolutePath());
        os=new FileOutputStream(localFile.getAbsolutePath(), mode.equals(Mode.append));
      }
     
      chosenProtocol=sms.findSupportedProtocol(preferredProtocols.toArray(new ProtocolType.Enum[preferredProtocols.size()]));
      Map<String,String>extraParameters=makeExtraParameters(chosenProtocol);
      ftc=sms.getExport(path,extraParameters,chosenProtocol);
      configure(ftc, extraParameters);
      System.out.println("DEB:File transfer URL : "+ftc.getUrl());
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable  && showProgress){
        long size=ftc.getSourceFileSize();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      long startTime=System.currentTimeMillis();
      if(isRange()){
        if(!(ftc instanceof SupportsPartialRead)){
          throw new Exception("Byte range is defined but protocol does not allow " +
              "partial read! Please choose a different protocol!");
        }
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        SupportsPartialRead pReader=(SupportsPartialRead)ftc;
        pReader.readPartial(startByte, endByte-startByte+1, os);
      }
      else{
        ftc.readAllData(os);
      }
//      if(p!=null){
//        p.finish();
//      }
      if(timing){
        long duration=System.currentTimeMillis()-startTime;
        double rate=(double)localFile.length()/(double)duration;
        System.out.println("Rate: " +rate+ " kB/sec.");
      }
      if(targetStream==null)copyProperties(source, localFile);
    }
    finally{
      try{
        if(targetStream==null && os!=null){
          os.close();
        }
      }catch(Exception ignored){}
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          System.out.println("Could not destroy the filetransfer client",e1);
        }
      }
    }
View Full Code Here

   */
  private void uploadFile(File localFile, String remotePath, StorageClient sms, ProtocolType.Enum protocol,
      Map<String,String>extraParameters) throws Exception{
    long startTime=System.currentTimeMillis();
    FileInputStream is=null;
    FileTransferClient ftc=null;
    try{
      if(remotePath==null){
        remotePath="/"+localFile.getName();
      }
      else if(remotePath.endsWith("/")){
        remotePath+=localFile.getName();
      }
      System.out.println("Uploading local file '"+localFile.getAbsolutePath()+"' -> '"+sms.getUrl()+"#"+remotePath+"'");
      is=new FileInputStream(localFile.getAbsolutePath());
      boolean append=Mode.append.equals(mode);
      ftc=sms.getImport(remotePath, append, extraParameters, protocol);
      configure(ftc, extraParameters);
      if(append)ftc.setAppend(true);
      String url=ftc.getUrl();
      System.out.println("File transfer URL : "+url);
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable){
        long size=localFile.length();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      if(isRange()){
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        long skipped=0;
        while(skipped<startByte){
          skipped+=is.skip(startByte);
        }
        ftc.writeAllData(is, endByte-startByte+1);
       
      }else{
        ftc.writeAllData(is);
      }
      copyProperties(localFile, sms, remotePath);
     
//      if(ftc instanceof IMonitorable){
//        p.finish();
//      }
     
    }finally{
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          msg.error("Could not clean-up the filetransfer at <"+ftc.getUrl()+">",e1);
        }
      }
      try{ if(is!=null)is.close(); }catch(Exception ignored){}
View Full Code Here

TOP

Related Classes of de.fzj.unicore.uas.client.FileTransferClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.