Package com.sos.VirtualFileSystem.local

Source Code of com.sos.VirtualFileSystem.local.SOSVfsLocal

/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
**   GNU General Public License version 2.0 (GPL)
**
**   as published by the Free Software Foundation
**   http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
**   LICENSE.GPL included in the packaging of this file.
**
** or the
** 
**   Agreement for Purchase and Licensing
**
**   as offered by Software- und Organisations-Service GmbH
**   in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
package com.sos.VirtualFileSystem.local;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;

import org.apache.log4j.Logger;

import sos.util.SOSFile;

import com.sos.JSHelper.Basics.JSJobUtilities;
import com.sos.JSHelper.Exceptions.JobSchedulerException;
import com.sos.JSHelper.Options.SOSOptionTransferMode;
import com.sos.JSHelper.io.Files.JSFile;
import com.sos.VirtualFileSystem.DataElements.SOSFileList;
import com.sos.VirtualFileSystem.DataElements.SOSFolderName;
import com.sos.VirtualFileSystem.Interfaces.ISOSAuthenticationOptions;
import com.sos.VirtualFileSystem.Interfaces.ISOSConnection;
import com.sos.VirtualFileSystem.Interfaces.ISOSConnectionOptions;
import com.sos.VirtualFileSystem.Interfaces.ISOSSession;
import com.sos.VirtualFileSystem.Interfaces.ISOSShellOptions;
import com.sos.VirtualFileSystem.Interfaces.ISOSVFSHandler;
import com.sos.VirtualFileSystem.Interfaces.ISOSVfsFileTransfer;
import com.sos.VirtualFileSystem.Interfaces.ISOSVirtualFile;
import com.sos.VirtualFileSystem.Interfaces.ISOSVirtualFileSystem;
import com.sos.VirtualFileSystem.Interfaces.ISOSVirtualFolder;
import com.sos.VirtualFileSystem.Options.SOSConnection2OptionsAlternate;
import com.sos.VirtualFileSystem.common.SOSVfsBaseClass;
import com.sos.i18n.annotation.I18NResourceBundle;

/**
* \class SOSVfsLocal
*
* \brief SOSVfsLocal -    
*
* \details
*
* \section SOSVfsLocal.java_intro_sec Introduction 
*
* \section SOSVfsLocal.java_samples Some Samples
*
* \code
*   .... code goes here ...
* \endcode
*
* <p style="text-align:center">
* <br />---------------------------------------------------------------------------
* <br /> APL/Software GmbH - Berlin
* <br />##### generated by ClaviusXPress (http://www.sos-berlin.com) #########
* <br />---------------------------------------------------------------------------
* </p>
* \author KB
* @version $Id: SOSVfsLocal.java 14791 2011-07-08 15:58:13Z kb $
* \see reference
*
* Created on 23.08.2010 17:53:03
*/

/**
* @author KB
*
*/
@I18NResourceBundle(baseName = "SOSVirtualFileSystem", defaultLocale = "en")
public class SOSVfsLocal extends SOSVfsBaseClass implements ISOSVfsFileTransfer, ISOSVFSHandler, ISOSVirtualFileSystem, ISOSConnection {

  @SuppressWarnings("unused")
  private final String  conClassName    = "SOSVfsLocal";

  private Logger      logger        = Logger.getLogger(SOSVfsLocal.class);
  private InputStream      objInputStream  = null;
  private OutputStream    objOutputStream  = null;


  private String      strReplyString    = "";
  @SuppressWarnings("unused")
  private File      objWorkingDirectory  = null;

  public SOSVfsLocal() {
    //
  }

  /**
   * \brief TransferMode
   *
   * \details
   *
   * \return
   *
   * @param pobjFileTransferMode
   * @return
   */
  @Override
  public ISOSVirtualFile TransferMode(SOSOptionTransferMode pobjFileTransferMode) {
    return null;
  }

  /**
   * \brief appendFile
   *
   * \details
   * Appends a File, which pathname is given as a String-Parameter, to another
   * file, with name is given as string-parameter.
   * 
   * \return the size of the file after append-operation
   *
   * @param localFile
   * @param remoteFile
   * @return
   */
  // TODO appendFile with ISOSVirtualFile
  @Override
  public long appendFile(String strSourceFileName, String strTargetFileName) {
    JSFile objTargetFile = new JSFile(strTargetFileName);
    long lngFileSize = 0;
    try {
      lngFileSize = objTargetFile.AppendFile(strSourceFileName);
    }
    catch (Exception e) {
      e.printStackTrace(System.err);
      String strM = "appendFile failed";
      logger.error(strM, e);
      throw new JobSchedulerException(strM, e);
    }
    return lngFileSize;
  }

  /**
   * \brief ascii
   *
   * \details
   *
   * \return
   *
   */
  @Override
  public void ascii() {
    // nothing to do

  }

  /**
   * \brief binary
   *
   * \details
   *
   * \return
   *
   */
  @Override
  public void binary() {
    // nothing to do

  }

  /**
   * \brief changeWorkingDirectory
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @return
   * @throws IOException
   */
  @Override
  public boolean changeWorkingDirectory(String pstrPathName) {
    boolean flgResult = true;
    // TODO use this directory on any file-operation
    objWorkingDirectory = new File(pstrPathName);
    return flgResult;
  }

  /**
   * \brief delete
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @throws IOException
   */
  @Override
  public void delete(String pathname) throws IOException {
    File objF = new File(getRealFileName(pathname));
    objF.delete();
  }

  private String getRealFileName(final String pstrPathname) {
    // TODO use objWorkingDirectory if it is not null to determine the Directory
    return pstrPathname;
  }

  /**
   * \brief disconnect
   *
   * \details
   *
   * \return
   *
   * @throws IOException
   */
  @Override
  public void disconnect() throws IOException {
    // nothing to do at all
  }

  /**
   * \brief getFile
   *
   * \details
   *
   * \return
   *
   * @param remoteFile
   * @param localFile
   * @param append
   * @return
   * @throws Exception
   */
  @Override
  public long getFile(String pstrSourceFileName, String pstrTargetFileName, boolean append) throws Exception {

    long lngFileSize = 0;

    if (append == false) {
      JSFile objF = new JSFile(pstrSourceFileName);
      lngFileSize = objF.length();
      objF.copy(pstrTargetFileName);
    }
    else {
      lngFileSize = this.appendFile(pstrSourceFileName, pstrTargetFileName);
    }
    return lngFileSize;
  }

  /**
   * \brief getFile
   *
   * \details
   *
   * \return
   *
   * @param remoteFile
   * @param localFile
   * @return
   * @throws Exception
   */
  @Override
  public long getFile(String remoteFile, String localFile) throws Exception {
    return 0;
  }

  /**
   * \brief getHandler
   *
   * \details
   *
   * \return
   *
   * @return
   */
  @Override
  public ISOSVFSHandler getHandler() {
    return this;
  }

  /**
   * \brief getReplyString
   *
   * \details
   *
   * \return
   *
   * @return
   */
  @Override
  public String getReplyString() {
    return strReplyString;
  }

  /**
   * \brief isConnected
   *
   * \details
   *
   * \return
   *
   * @return
   */
  @Override
  public boolean isConnected() {
    return true;
  }

  /**
   * \brief listNames
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @return
   * @throws IOException
   */
  @Override
  public String[] listNames(String pathname) throws IOException {
    return this.listNames(pathname);
  }

  /**
   * \brief login
   *
   * \details
   *
   * \return
   *
   * @param strUserName
   * @param strPassword
   */
  @Override
  public void login(String strUserName, String strPassword) {
  }

  /**
   * \brief logout
   *
   * \details
   *
   * \return
   *
   * @throws IOException
   */
  @Override
  public void logout() throws IOException {
  }

  /**
   * \brief mkdir
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @throws IOException
   */
  @Override
  public void mkdir(String pathname) throws IOException {
    new File(pathname).mkdir();
  }

  /**
   * \brief nList
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @return
   */
  @Override
  public Vector<String> nList(String pathname) {
    notImplemented();
    return null;
  }

  /**
   * \brief nList
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @param flgRecurseSubFolder
   * @return
   */
  @Override
  public Vector<String> nList(String pathname, boolean flgRecurseSubFolder) {
    notImplemented();
    return null;
  }

  /**
   * \brief nList
   *
   * \details
   *
   * \return
   *
   * @param recursive
   * @return
   * @throws Exception
   */
  @Override
  public Vector<String> nList(boolean recursive) throws Exception {
    notImplemented();
    return null;
  }

  /**
   * \brief nList
   *
   * \details
   *
   * \return
   *
   * @return
   * @throws Exception
   */
  @Override
  public Vector<String> nList() throws Exception {
    notImplemented();
    return null;
  }

  /**
   * \brief passive
   *
   * \details
   *
   * \return
   *
   * @return
   */
  @Override
  public int passive() {
    return 0;
  }

  /**
   * \brief put
   *
   * \details
   *
   * \return
   *
   * @param localFile
   * @param remoteFile
   */
  @Override
  public void put(String localFile, String remoteFile) {
  }

  /**
   * \brief putFile
   *
   * \details
   *
   * \return
   *
   * @param localFile
   * @param out
   * @return
   */
  @Override
  public long putFile(String localFile, OutputStream out) {
    return 0;
  }

  /**
   * \brief putFile
   *
   * \details
   *
   * \return
   *
   * @param localFile
   * @param remoteFile
   * @return
   * @throws Exception
   */
  @Override
  public long putFile(String localFile, String remoteFile) throws Exception {
    return 0;
  }

  /**
   * \brief getConnection
   *
   * \details
   *
   * \return
   *
   * @return
   */
  @Override
  public ISOSConnection getConnection() {
    return null;
  }

  /**
   * \brief getSession
   *
   * \details
   *
   * \return
   *
   * @return
   */
  @Override
  public ISOSSession getSession() {
    return null;
  }

  /**
   * \brief mkdir
   *
   * \details
   *
   * \return
   *
   * @param pobjFolderName
   * @return
   * @throws IOException
   */
  @Override
  public ISOSVirtualFolder mkdir(SOSFolderName pobjFolderName) throws IOException {
    new File(pobjFolderName.Value()).mkdir();
    return null;
  }

  /**
   * \brief rmdir
   *
   * \details
   *
   * \return
   *
   * @param pobjFolderName
   * @return
   * @throws IOException
   */
  @Override
  public boolean rmdir(SOSFolderName pobjFolderName) throws IOException {
    new File(pobjFolderName.Value()).delete();
    return true;
  }

  /**
   * \brief dir
   *
   * \details
   *
   * \return
   *
   * @param pobjFolderName
   * @return
   */
  @Override
  public SOSFileList dir(SOSFolderName pobjFolderName) {
    // TODO Auto-generated method stub
    return null;
  }

  /**
   * \brief dir
   *
   * \details
   *
   * \return
   *
   * @param pathname
   * @param flag
   * @return
   */
  @Override
  public SOSFileList dir(String pathname, int flag) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public void setJSJobUtilites(JSJobUtilities pobjJSJobUtilities) {
  }

  @Override
  public void ExecuteCommand(String strCmd) throws Exception {
    // TODO shell-execute einbauen wg. pre- und pos-commands
//    notImplemented();
  }

  @Override
  public String createScriptFile(String pstrContent) throws Exception {
    return EMPTY_STRING;
  }

  @Override
  public Integer getExitCode() {
    return 0;
  }

  @Override
  public String getExitSignal() {
    return EMPTY_STRING;
  }

  @Override
  public StringBuffer getStdErr() throws Exception {
    return new StringBuffer("");
  }

  @Override
  public StringBuffer getStdOut() throws Exception {
    return new StringBuffer("");
  }

  @Override
  public boolean remoteIsWindowsShell() {
    return false;
  }

  @Override
  public ISOSConnection Authenticate(ISOSAuthenticationOptions pobjAO) throws Exception {
    strReplyString = "230 Login successful.";
    return this;
  }

  @Override
  public void CloseConnection() throws Exception {
    strReplyString = "ok";
  }

  @Override
  public ISOSConnection Connect() throws Exception {
    strReplyString = "ok";
    return this;
  }

  @Override
  public ISOSConnection Connect(ISOSConnectionOptions pobjConnectionOptions) throws Exception {
    this.Connect();
    return this;
  }

  @Override
  public ISOSConnection Connect(String pstrHostName, int pintPortNumber) throws Exception {
    return null;
  }

  @Override
  public void CloseSession() throws Exception {
    strReplyString = "221 Goodbye.";
  }

  @Override
  public ISOSSession OpenSession(ISOSShellOptions pobjShellOptions) throws Exception {
    return null;
  }

  @Override
  public ISOSVirtualFile getFileHandle(String pstrFileName) {
    SOSVfsLocalFile objF = new SOSVfsLocalFile(pstrFileName);
    objF.setHandler(this);
    return objF;
  }

  @Override
  public boolean isNegativeCommandCompletion() {
    return false;
  }

  @Override
  public String[] getFilelist(String folder, String regexp, int flag, boolean withSubFolder) {
    String[] strS = null;
    try {
//      Vector<File> objA = SOSFile.getFilelist(folder, regexp, flag, withSubFolder);
      Vector<File> objA = SOSFile.getFolderlist(folder, regexp, flag, withSubFolder);
      Vector <String> objV = new Vector <String> ();
      for (File objF : objA) {
        objV.add(objF.getAbsolutePath());
      }
      strS = (String[]) objV.toArray(new String[objV.size()]);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    return strS;
  }

  @Override
  public void CompletePendingCommand() {
    // nothing to do
   
  }

  @Override
  public ISOSConnection Connect(SOSConnection2OptionsAlternate pobjConnectionOptions) throws Exception {
    // nothing to do
    return null;
  }

  @Override
  public String DoPWD() {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public OutputStream getAppendFileStream(String strFileName) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public long getFileSize(String strFileName) {
    // TODO Auto-generated method stub
    return 0;
  }

  @Override
  public InputStream getInputStream(String strFileName) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public String getModificationTime(String strFileName) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public OutputStream getOutputStream(String strFileName) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public boolean isDirectory(String strFileName) {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  public void rename(String strFileName, String pstrNewFileName) {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void close() {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void closeInput() {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void closeOutput() {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void flush() {
    // TODO Auto-generated method stub
   
  }

  @Override
  public int read(byte[] bteBuffer) {
    // TODO Auto-generated method stub
    return 0;
  }

  @Override
  public int read(byte[] bteBuffer, int intOffset, int intLength) {
    // TODO Auto-generated method stub
    return 0;
  }

  @Override
  public void write(byte[] bteBuffer, int intOffset, int intLength) {
    // TODO Auto-generated method stub
    notImplemented();
   
  }

  @Override
  public void write(byte[] bteBuffer) {
    // TODO Auto-generated method stub
    notImplemented();
   
  }

  @Override
  public void openInputFile(String pstrFileName) {
    // TODO Auto-generated method stub
    notImplemented();

  }

  @Override
  public void openOutputFile(String pstrFileName) {
    // TODO Auto-generated method stub
    notImplemented();   
  }

  @Override
  public Vector<ISOSVirtualFile> getFiles(String string) {
    // TODO Auto-generated method stub
    notImplemented();
    return null;
  }

  @Override
  public Vector<ISOSVirtualFile> getFiles() {
    // TODO Auto-generated method stub
    notImplemented();
    return null;
  }

  @Override
  public void putFile(ISOSVirtualFile objVirtualFile) {
   
    String strName = objVirtualFile.getName();
    strName = new File(strName).getAbsolutePath();
    if (strName.startsWith("c:") == true) {
      strName = strName.substring(3);
    }
    @SuppressWarnings("unused")
    ISOSVirtualFile objVF = (ISOSVirtualFile) this.getFileHandle(strName);
    OutputStream objOS = objVF.getFileOutputStream();
   
    InputStream objFI = objVirtualFile.getFileInputStream();

    int lngBufferSize = 1024;
    byte[] buffer = new byte[lngBufferSize];
    int intBytesTransferred;
    long totalBytes = 0;
    try {
      synchronized (this) {
        while ((intBytesTransferred = objFI.read(buffer)) != -1) {
          objOS.write(buffer, 0, intBytesTransferred);
          totalBytes += intBytesTransferred;
        }
        objFI.close();
        objOS.flush();
        objOS.close();
      }
    }
    catch (Exception e) {
      throw new JobSchedulerException("putfile reports exception", e);
    }
    finally {
    }
   
  }

  @Override
  public void ControlEncoding(String pstrControlEncoding) {
    // TODO Auto-generated method stub
   
  }
 
 
}
TOP

Related Classes of com.sos.VirtualFileSystem.local.SOSVfsLocal

TOP
Copyright © 2018 www.massapi.com. 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.