Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.webbasics.ssh.generic.file;
 
 import java.io.File;
 import java.util.List;
 
 
 
 public class FileConnector implements IConnectorFileBased <FileFile>
 {
   private File m_aChannel;
 
   public FileConnector (@Nonnull final IFileConnectionDestination aDestination)
   {
     if (aDestination == null)
       throw new NullPointerException ("destination");
      = aDestination;
   }
 
   @Nonnull
   {
     return ;
   }
 
   @Nullable
   public File getHandle ()
   {
     return ;
   }
 
   @Nonnull
   public EChange openConnection (@Nonnull final IAuthCredentials aCredentials)
   {
     // already open?
     if (isConnectionOpen ())
       return .;
 
     // open connection
      = .openConnection (aCredentials);
     return EChange.valueOf (isConnectionOpen ());
   }
 
   @Nonnull
   public EChange closeConnection ()
   {
     {
        = null;
       return .;
     }
 
     return .;
   }
 
   public boolean isConnectionOpen ()
   {
     return  != null;
   }
 
   @Nonnull
   public ESuccess getData (@Nonnull final String sFilename, @Nonnull final OutputStream aOS)
   {
     try
     {
       if ( != null)
         return StreamUtils.copyInputStreamToOutputStream (FileUtils.getInputStream (new File (sFilename)),
                                                           aOS);
       return .;
     }
    finally
    {
      StreamUtils.close (aOS);
    }
  }
  public ESuccess putData (@Nonnull final String sFilename, @Nonnull final InputStream aIS)
  {
    try
    {
      if ( != null)
        return StreamUtils.copyInputStreamToOutputStream (aIS,
                                                          FileUtils.getOutputStream (new File (sFilename)));
      return .;
    }
    finally
    {
      StreamUtils.close (aIS);
    }
  }
  public ESuccess changeWorkingDirectory (@Nonnull final String sDirectory)
  {
    if ( != null)
    {
       = new File (sDirectory);
      return .;
    }
    return .;
  }
  {
    return changeWorkingDirectory ("..");
  }
  public ESuccess deleteFile (@Nonnull final String sFilename)
  {
    if ( != null)
      return ESuccess.valueOf (FileOperations.deleteFile (new File (sFilename)).isSuccess ());
    return .;
  }
  public ESuccess listFiles (@Nullable final IFilter <FileaFilter, @Nonnull final List <FileaTargetList)
  {
    if ( != null)
    {
      for (final File aFile : new FileSystemIterator ())
        if (aFilter == null || aFilter.matchesFilter (aFile))
          aTargetList.add (aFile);
      return .;
    }
    return .;
  }
New to GrepCode? Check out our FAQ X