Package com.sos.JSHelper.io.Files

Examples of com.sos.JSHelper.io.Files.JSFile


    this.operation.CheckMandatory();
    String localDir = this.local_dir.Value();
    if (isEmpty(localDir) == true) {
      String strPathName = this.file_path.Value();
      if (isNotEmpty(strPathName) == true) {
        JSFile fleT = new JSFile(strPathName);
        // fn.substring(0, fn.lastIndexOf(java.io.File.pathSeparatorChar));
        String strParent = fleT.getParent();
        if (strParent != null && strParent.equalsIgnoreCase(strPathName) == false) {
          this.local_dir.Value(fleT.getParent());
        }
      }
    }
    localDir = this.local_dir.Value();
    if (isEmpty(localDir) == true) {
View Full Code Here


    final String conMethodName = conClassName + "::Value";

    try {
      super.Value(pstrInFileName);
      if (isNotEmpty(pstrInFileName)) {
        objFile = new JSFile(pstrInFileName);
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

    @SuppressWarnings("unused")
    final String conMethodName = conClassName + "::JSFile";

    if (objFile == null) {
      objFile = new JSFile(this.strValue);
    }

    return objFile;
  } // private JSFile JSFile
View Full Code Here

   *
   * @param pstrFileName
   */
  public void putObject(String pstrFileName) {
    try {
      JSFile objFile = new JSFile(pstrFileName);
      String encoded = getObjectAsString();
      objFile.Write(encoded);
      objFile.close();
    }
    catch (Exception e) {
      throw new JobSchedulerException("Error occured writing object to file: " + e);
    }
  }
View Full Code Here

   * @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);
View Full Code Here

  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;
View Full Code Here

  public void Archive() throws Exception {

    final String conMethodName = conClassName + "::Archive";

    String nameOfArchiveFile = null;
    JSFile fleArchiveFile = null;
    String strFName = null;
    String strFileName = null;

    SignalInfo(String.format("%1$s: starting, file to archive: '%2$s', archive-folder: '%3$s'.", conMethodName, objOptions.FileName(), objOptions
        .ArchiveFolderName()));

    if (objOptions == null) {
      SignalAbort(String.format("%1$s: no Options specified. Archive aborted.", conMethodName));
    }

    objOptions.CheckMandatory();

    strFileName = objOptions.FileName();
    JSFile fileToArchive = new JSFile(strFileName);
    fileToArchive.registerMessageListener(this);
    fileToArchive.MustExist();
//    String strOriginalFileName = fileToArchive.getName();

    if (objOptions.CreateTimeStamp()) {
      /*
       * kein Rename-TimeStamp verwenden, zur Sicherheit, damit die
       * Original-Datei erhalten bleibt (jedenfalls erstmal).
       */
      fileToArchive = new JSFile(fileToArchive.CopyTimeStamp());
//    geht nicht auf be0027  fileToArchive.deleteOnExit();
      strFName = fileToArchive.getName();
    }
    else {
      strFName = fileToArchive.getName();
    }

    if (objOptions.CompressArchivedFile()) {
      // TODO: eigene Klasse mit eigenen Optionen implementieren
      // TODO: entweder als "eigenen" File ablegen oder in ein bestehendes ZIP-File integrieren.
      nameOfArchiveFile = objOptions.ArchiveFolderName() + strFName + ".gz";
      fleArchiveFile = new JSFile(nameOfArchiveFile);
      if (fleArchiveFile.exists()) {
        SignalAbort(String.format("%1$s: file '%2$s' already exist.", conMethodName, nameOfArchiveFile));
      }
      SignalInfo(String.format("%3$s: Zip '%1$s' into Zip-File '%2$s'", fileToArchive.getAbsoluteFile(), fleArchiveFile.getAbsoluteFile(), conMethodName));

      final BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileToArchive));
      final GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(fleArchiveFile));

      try {

        final byte buffer[] = new byte[1024];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) != -1) {
          out.write(buffer, 0, bytesRead);
        }

      } catch (final Exception e) {
        throw e;
      } finally {
        try {
          in.close();
        } catch (final Exception e) {
          throw e;
        }
        try {
          out.close();
        } catch (final Exception e) {
          throw e;
        }
      }

    }
    else {
      nameOfArchiveFile = objOptions.ArchiveFolderName() + strFName;
      fileToArchive.copy(nameOfArchiveFile);
    }

    message(String.format("%1$s: Archive file created '%2$s'.", conMethodName, nameOfArchiveFile));
    if (objOptions.DeleteFileAfterArchiving() || objOptions.CreateTimeStamp()) {
      final JSFile fileToDelete = new JSFile(strFileName);
      fileToDelete.delete();
      SignalInfo(String.format("%1$s: archived file deleted '%2$s'.", conMethodName, strFileName));
    }
    if (objOptions.CreateTimeStamp()) {
/*
* hier mu� gel�scht werden, da der die Datei mit dem Time-Stamp-Namen
View Full Code Here

   * @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);
View Full Code Here

    try {
      if (objWorkingDirectory != null) {
        objWorkingDirectory.close();
      }
      strZipArchiveName = pstrPathName;
      JSFile objFile = new JSFile(pstrPathName);
      if (this.isTarget() == true) {
        if (objFile.exists()) {
          objFile.delete();
        }
        objZipOutputStream = new ZipOutputStream(new FileOutputStream(pstrPathName));
        flgResult = true;
        logger.debug(String.format("Zip-File '%1$s' created", pstrPathName));
      }
      else {
        if (objFile.exists()) {
          objWorkingDirectory = new ZipFile(objFile, ZipFile.OPEN_READ);
          flgResult = true;
          logger.debug(String.format("Zip-File '%1$s' opened", pstrPathName));
        }
      }
View Full Code Here

TOP

Related Classes of com.sos.JSHelper.io.Files.JSFile

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.