|
From: <das...@us...> - 2008-10-29 20:14:16
|
Revision: 1183
http://vlab.svn.sourceforge.net/vlab/?rev=1183&view=rev
Author: dasil014
Date: 2008-10-29 20:14:14 +0000 (Wed, 29 Oct 2008)
Log Message:
-----------
This class has methods that executes manipulation of data in the external side of the Web service. It has methods to call scripts, create files based on data defined by the user through web portal, and creation of data based on workflow.
Added Paths:
-----------
trunk/vlab/services/project-executor/src/main/java/org/vlab/services/OutRunnings.java
Added: trunk/vlab/services/project-executor/src/main/java/org/vlab/services/OutRunnings.java
===================================================================
--- trunk/vlab/services/project-executor/src/main/java/org/vlab/services/OutRunnings.java (rev 0)
+++ trunk/vlab/services/project-executor/src/main/java/org/vlab/services/OutRunnings.java 2008-10-29 20:14:14 UTC (rev 1183)
@@ -0,0 +1,722 @@
+package org.vlab.services;
+
+import java.io.File.*;
+import java.io.*;
+
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+import java.util.*;
+
+import org.apache.axis.encoding.Base64;
+
+public class OutRunnings {
+
+ public static void createQPointFile(){
+
+ try {
+ BufferedWriter out = new BufferedWriter(new FileWriter(ProjectExecutor.ENV_PACKAGE_DIR+ProjectExecutor.dirEPName+"/__q-points_grid"));
+ out.write("4 4 4 0 0 0");
+ out.close();
+ } catch (IOException e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+ public static void CijGentab(){
+
+ ProjectExecutor.setDirEPName();
+
+ System.out.println("\n Here I start the CijGentab() \n");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+ File FileDir = null;
+
+ try{
+ FileDir = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+ String[] fullcommand = {ProjectExecutor.ENV_SCRIPT +"Cij_gentab.sh", ProjectExecutor.getCrystalType()};
+
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ //returnMessage = br_stdin.readLine();
+ }
+
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:CijGentab()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+
+
+ //This method will no longer be used
+ private String UnCompressTarBallFromWS(String ProjectType, Boolean phaseOption){
+
+ /* Starting the process to UnZip the file */
+ int count;
+ byte data[] = null;
+
+ try {
+ BufferedOutputStream dest = null;
+ BufferedInputStream is = null;
+ ZipEntry entry;
+ ZipFile zipfile = new ZipFile(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + "TarBallFromWS.zip");
+ Enumeration e = zipfile.entries();
+
+ while(e.hasMoreElements()) {
+ entry = (ZipEntry) e.nextElement();
+ System.out.println("Extracting TarBallFromWS.zip : " + entry);
+ is = new BufferedInputStream (zipfile.getInputStream(entry));
+
+ data = new byte[ProjectExecutor.BUFFER];
+ FileOutputStream fos = new FileOutputStream(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + entry.getName());
+ dest = new BufferedOutputStream(fos, ProjectExecutor.BUFFER);
+ while ((count = is.read(data, 0, ProjectExecutor.BUFFER)) != -1) {
+ dest.write(data, 0, count);
+ }
+ dest.flush();
+ dest.close();
+ is.close();
+ }
+ } catch(Exception e) {
+ System.err.println("[ProjectExecutor.java] In setUncompressZip() " + e.getMessage());
+ e.printStackTrace();
+ //System.exit(-1);
+ }
+ return "sucessfully Uncompress of TarBallFromWS.zip";
+ }
+
+
+ public static String UnCompressExecutionPackage(String ProjectType, Boolean phaseOption){
+ System.out.println(" Here I start the ProjectExecutor::UnCompressExecutionPackage() ");
+
+ /* Starting the process to UnZip the file */
+ int count;
+ byte data[] = null;
+ String[] Packages = DispatcherSetting.ListPackages(ProjectType, phaseOption);
+ String actuallyPackage = null;
+
+ for(int i=0; i < Packages.length; i++){
+
+ actuallyPackage = Packages[i];
+
+ try {
+ BufferedOutputStream dest = null;
+ BufferedInputStream is = null;
+ ZipEntry entry;
+ ZipFile zipfile = new ZipFile(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + actuallyPackage);
+ Enumeration e = zipfile.entries();
+
+ while(e.hasMoreElements()) {
+ entry = (ZipEntry) e.nextElement();
+ StringTokenizer st = new StringTokenizer(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + entry.getName(), "/" );
+ String accumulatedDir = "/";
+ String TokenName;
+ File tempDirectory = null;
+
+ while ( st.hasMoreTokens() ) {
+ TokenName = st.nextToken();
+ accumulatedDir += TokenName + "/";
+ System.out.println("Token: "+TokenName);
+ // System.out.println("SubStr: "+zipFileName.substring(0,zipFileName.length()-4));
+
+ if (TokenName.equals(actuallyPackage.substring(0,actuallyPackage.length()-4))){
+ System.out.println("accumalatedDir: "+accumulatedDir);
+ tempDirectory = new File( accumulatedDir );
+ /*If to create a temp directory*/
+ if ( !tempDirectory.exists() ) {
+ if ( !tempDirectory.mkdir() ) {
+ System.err.println("unable to create directory: " + accumulatedDir );
+ } else
+ System.out.println( tempDirectory.getAbsolutePath() + " created." );
+ tempDirectory = new File (accumulatedDir+"/tmp");
+ tempDirectory.mkdir();
+ System.out.println( tempDirectory.getAbsolutePath() + " created." );
+ }
+
+ if (entry.getSize()>0){
+ System.out.println("Extracting "+actuallyPackage+": "+entry);
+ is = new BufferedInputStream (zipfile.getInputStream(entry));
+
+ data = new byte[ProjectExecutor.BUFFER];
+ FileOutputStream fos = new FileOutputStream(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + entry.getName());
+ dest = new BufferedOutputStream(fos, ProjectExecutor.BUFFER);
+ while ((count = is.read(data, 0, ProjectExecutor.BUFFER)) != -1) {
+ dest.write(data, 0, count);
+ }
+ dest.flush();
+ dest.close();
+ is.close();
+ }
+ }
+ }
+ }
+ } catch(Exception e) {
+ System.err.println("[ProjectExecutor.java] In setUncompressZip() " + e.getMessage());
+ e.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+ return "Sucessfully";
+ }
+ /* Preciso de um metodo pra descobrir se o projeto eh Fast Refine ou Long Refine */
+
+
+
+ public static String UnCompressComplexCalc(){
+
+ System.out.println(" Here I start the ProjectExecutor::UnCompressComplexCalc() ");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+
+ try{
+ File FileDir = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+ String[] fullcommand = {ProjectExecutor.ENV_SCRIPT +"unzip.sh", ProjectExecutor.zipFileName };
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ //returnMessage = br_stdin.readLine();
+ }
+
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:UnCompressComplexCalc()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ return "Sucessfully";
+ }
+
+
+ public static void RunPackageESG(Boolean phaseOption){
+
+ System.out.println("\n Here I start the Script of ESG \n");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+ File FileDir = null;
+ String[] fullcommand1 = null;
+
+ try{
+ FileDir = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+
+ if (phaseOption.booleanValue()==true){
+ String[] fullcommand2 = { ProjectExecutor.ENV_SCRIPT +"FastRefine.sh" , "GenericInput" };
+ fullcommand1 = fullcommand2;
+ }
+ else{
+ String[] fullcommand2 = { ProjectExecutor.ENV_SCRIPT +"LongRefineCd.sh", "GenericInput" };
+ fullcommand1 = fullcommand2;
+ }
+
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand1, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }
+
+ /*for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }*/
+
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+ } catch (Exception ae){
+
+ System.err.println("[OutRunnings:RunPackageESG()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+ }
+
+
+ public static void setFastRefineFitting(){
+
+ System.out.println("\n Here I start the setFastRefineFitting() \n");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+ String fullcommand = null;
+
+ try{
+ File FileDir = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+ fullcommand = ProjectExecutor.ENV_SCRIPT +"FRef_fit.sh";
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }
+
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:setFastRefineFitting()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+ public static void setLongRefineFitting(){
+
+ System.out.println("\n Here I start the setLongRefineFitting() \n");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+ String fullcommand = null;
+
+
+ try{
+ File FileDir = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+ fullcommand = ProjectExecutor.ENV_SCRIPT +"LRef_fit.sh";
+
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ //returnMessage = br_stdin.readLine();
+ }
+
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:setLongRefineFitting()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+ /* This method is just to create Zip File*/
+ public static void setCreatePackage(String pesdataexecutionpackage){
+
+ //int len;
+ System.out.println("\n Here I start the setCreatePackage() \n");
+ byte[] DataToFile = null;
+ File zipFile = null;
+
+ //DimeAttachments streamfiledime = DimeAttachment();
+
+ try{
+ System.out.println("File size from Client: " + pesdataexecutionpackage.length());
+ DataToFile = Base64.decode(pesdataexecutionpackage);
+ } catch(Exception ae){
+ //ae.printStackTrace();
+ System.err.println("[ProjectExecutor::setCreatePackage] Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+
+
+ try{
+ /*Set Name for Zip File*/
+ ProjectExecutor.setDirEPName();
+
+ zipFile = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+
+ if (zipFile.exists())
+ System.out.println("ALL PREVIOUS FILE WAS DELETED: " + deleteDir(zipFile));
+
+ zipFile.mkdir();
+ zipFile = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + ProjectExecutor.zipFileName);
+ System.out.println("File name: "+zipFile.getName());
+ System.out.println("File Size: "+DataToFile.length);
+ System.out.println("The outputstream for the file: "+zipFile);
+ OutputStream srcDest = new FileOutputStream(zipFile);
+ System.out.println("The write data on the file");
+ srcDest.write(DataToFile, 0, DataToFile.length);
+ System.out.println("Close the file");
+ srcDest.close();
+ System.out.println("I created the file " + ProjectExecutor.zipFileName + " ");
+ /* Here I should set one variable with the right path to Zip File Created */
+ }catch (Exception ae){
+ System.err.println("[ProjectExecutor::setCreatePackage()] => Error creating the ZipFile: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+ /* Here I uncompress the package that I got from the Page */
+ public void setUncompressZip(){
+
+ /* Starting the process to UnZip the file */
+ int count;
+ byte data[] = null;
+
+ try {
+ BufferedOutputStream dest = null;
+ BufferedInputStream is = null;
+ ZipEntry entry;
+ ZipFile zipfile = new ZipFile(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + ProjectExecutor.zipFileName);
+ Enumeration e = zipfile.entries();
+
+ while(e.hasMoreElements()) {
+ entry = (ZipEntry) e.nextElement();
+ StringTokenizer st = new StringTokenizer(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + entry.getName(), "/" );
+ String accumulatedDir = "/";
+ String TokenName;
+ File tempDirectory = null;
+
+ while ( st.hasMoreTokens() ) {
+ TokenName = st.nextToken();
+ accumulatedDir += TokenName + "/";
+ System.out.println("Token: "+TokenName);
+ System.out.println("SubStr: " + ProjectExecutor.zipFileName.substring(0, ProjectExecutor.zipFileName.length()-4));
+
+ if (TokenName.matches(".*Input.*")){
+ System.out.println("InputName is: "+TokenName);
+ }
+
+ if (TokenName.equals(ProjectExecutor.zipFileName.substring(0, ProjectExecutor.zipFileName.length()-4))){
+ System.out.println("accumalatedDir: "+accumulatedDir);
+ tempDirectory = new File( accumulatedDir );
+ /*If to create a temp directory*/
+ if ( !tempDirectory.exists() ) {
+ if ( !tempDirectory.mkdir() ) {
+ System.err.println("unable to create directory: " + accumulatedDir );
+ } else
+ System.out.println( tempDirectory.getAbsolutePath() + " created." );
+ tempDirectory = new File (accumulatedDir+"/tmp");
+ tempDirectory.mkdir();
+ System.out.println( tempDirectory.getAbsolutePath() + " created." );
+ }
+
+ if (entry.getSize()>0){
+ System.out.println("Extracting " + ProjectExecutor.zipFileName+": "+entry);
+ is = new BufferedInputStream (zipfile.getInputStream(entry));
+
+ data = new byte[ProjectExecutor.BUFFER];
+ FileOutputStream fos = new FileOutputStream(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + entry.getName());
+ dest = new BufferedOutputStream(fos, ProjectExecutor.BUFFER);
+ while ((count = is.read(data, 0, ProjectExecutor.BUFFER)) != -1) {
+ dest.write(data, 0, count);
+ }
+ dest.flush();
+ dest.close();
+ is.close();
+ }
+ }
+ }
+ }
+ } catch(Exception e) {
+ System.err.println("[ProjectExecutor.java] In setUncompressZip() " + e.getMessage());
+ e.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+
+ public static void RunIntermediate34(){
+
+ System.out.println("\n Here I start the RunIntermediate34() \n");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+ String fullcommand = null;
+ File FileDir = null;
+ try{
+
+ FileDir = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+
+ fullcommand = ProjectExecutor.ENV_SCRIPT +"Intermediate34.sh";
+
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:RunIntermediate34()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+ public static void ScriptCreatePhononPackages(){
+
+ System.out.println("\n Here I start the ScriptCreatePhononPackages() \n");
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+ String fullcommand = null;
+ File FileDir = null;
+
+ try{
+ FileDir = new File( ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+ fullcommand = ProjectExecutor.ENV_SCRIPT +"x2.sh";
+
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }
+
+ /*for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }*/
+
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+ } catch (Exception ae){
+
+ System.err.println("[OutRunning:ScriptCreatePhononPackages()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+
+
+
+
+
+
+ public static void setTheNewPackage(){
+
+ File readExecutionPackage = null;
+ byte[] buff = null;
+ InputStream sourcefile = null;
+
+ try{
+ readExecutionPackage = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + "ComplexCalc.zip");
+ ProjectExecutor.zipFileName = "ComplexCalc.zip";
+
+ System.out.println("\n File name is: "+readExecutionPackage.getName());
+ System.out.println("\n File size is: "+readExecutionPackage.length());
+
+ int filesiuze = (int) readExecutionPackage.length();
+ buff = new byte[filesiuze];
+ sourcefile = new FileInputStream(readExecutionPackage);
+ sourcefile.read(buff);
+ //ProjectExecutor.pesdataexecutionpackage = new String(Base64.encode(buff));
+ }catch (Exception ae){
+ System.err.println("[ProjectExecutor::setTheNewPackage()] => Error "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+
+
+ public static void CreatePackage(){
+
+ //File listPseudoFile = new File(ENV_UPLOAD_DIR);
+ File RunDirTemplate = null;
+ //Create the ZIP file
+ String outFilename = null;
+
+ try{
+ RunDirTemplate = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName +"RunDirTemplate");
+ outFilename = ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName +"ComplexCalc.zip";
+
+ ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
+ System.out.println("[ElasInputManager.java] Creating : " + outFilename);
+ AddDirToZiP(RunDirTemplate, out, ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + ProjectExecutor.INPUT_GENERIC);
+ out.close();
+ System.out.println("[ElasInputManager.java] Zip File Created sucessfully");
+ }catch (IOException ae){
+ System.out.println("[ProjectExecutor::CreatePackage()] Error creating the basic package " + ae.getMessage());
+ ae.printStackTrace();
+ //return "fail";
+ }
+ }
+
+ public static void AddDirToZiP(File dirObj, ZipOutputStream out, String AbsolutePathGenericInput) throws IOException
+ {
+ File[] files = dirObj.listFiles();
+ File GenericInput = new File(AbsolutePathGenericInput);
+ byte[] tmpBuf = new byte[1024];
+ FileInputStream in=null;
+ int len;
+
+ for (int i=0; i<files.length; i++){
+ if(files[i].isDirectory()){
+ File[] files_temp = files[i].listFiles();
+ in = new FileInputStream(files_temp[0].getAbsoluteFile());
+ System.out.println("[ElasPwscfBean.java] Adding: " + files_temp[0].getAbsolutePath());
+ out.putNextEntry(new ZipEntry("/RunDirTemplate/"+"tmp/"+files_temp[0].getName()));
+ }else{
+ in = new FileInputStream(files[i].getAbsoluteFile());
+ System.out.println("[ElasPwscfBean.java] Adding: " + files[i].getAbsolutePath());
+ out.putNextEntry(new ZipEntry("/RunDirTemplate/"+files[i].getName()));
+ }
+
+ // Transfer from the file to the ZIP file
+ while((len = in.read(tmpBuf)) > 0){
+ out.write(tmpBuf, 0, len);
+ }
+ // Complete the entry
+ out.closeEntry();
+ in.close();
+ }
+
+ /* Insert the generic Input to ComplexCalc.zip*/
+ in = new FileInputStream(GenericInput);
+ System.out.println("[ElasPwscfBean.java] Adding: " + GenericInput.getAbsolutePath());
+ out.putNextEntry(new ZipEntry(GenericInput.getName()));
+ //Transfer from the file to the ZIP file
+ while((len = in.read(tmpBuf)) > 0){
+ out.write(tmpBuf, 0, len);
+ }
+ // Complete the entry
+ out.closeEntry();
+ in.close();
+ }
+
+
+
+
+
+ public static boolean deleteDir(File dir) {
+ try{
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i=0; i<children.length; i++) {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ } catch (Exception ae){
+ System.err.println("[deleteDir] => "+ae.getMessage());
+ ae.printStackTrace();
+ }
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
+
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|