cannot build directory from ANT custom Task
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Arun_KS
Posted On:   Wednesday, March 1, 2006 08:24 AM

I am not able to create any directory when i write code for creating directories for ANT custom TAsk The code listed below runs properly when i execute as standalone application but it fails when i use this code as ANT's Custom TAsk I am Using 1.6.2 version ANT package com.patni.ant.common; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.GUnzip; import java.io.*; import java.util.zip.*; import org.apache.tools.ant.taskdefs.*; import org.apache.commons.io.*; public class GunZipper extends Task {    More>>

I am not able to create any directory when i write code for creating directories for ANT custom TAsk

The code listed below runs properly when i execute as standalone application but it fails when i use this code as ANT's Custom TAsk I am Using 1.6.2 version ANT



package com.patni.ant.common;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.GUnzip;
import java.io.*;
import java.util.zip.*;
import org.apache.tools.ant.taskdefs.*;
import org.apache.commons.io.*;



public class GunZipper extends Task
{



private String srcDir="C:\download\FTP\";
private String destDir="E:\unzipdir\";


public static void main(String arg[]) throws BuildException
{


GunZipper zipper = new GunZipper();
zipper.execute();
}



public void execute() throws BuildException
{

System.out.println("The src is :"+srcDir);
System.out.println("The dest is :"+destDir);
File file = new File(srcDir);
String[] fileList = file.list();
int len= fileList.length;
String temp= null;
File uzipFile = null;
FileOutputStream out = null;
GZIPInputStream zIn = null;
FileInputStream fis = null;
File output = null;

try{

System.out.println("GunZipper.execute()");
System.err.println("GunZipper.execute()");
FileUtils.forceMkdir(new File("C:\Jakarta\apache\sun"));
createDir(destDir);

for(int i = 0 ; i < len ; i++)
{
temp = fileList[i];
if(temp.endsWith(".gz"))
{

out = new FileOutputStream(destDir+"temp.tar");
fis = new FileInputStream(srcDir+temp); //src name should be eg: C:\downloadFTP
zIn = new GZIPInputStream(fis);
byte[] buffer = new byte[8*1024];
int count = 0;
/* do{
out.write(buffer,0,count);
count = zIn.read(buffer,0,buffer.length);
}while(count!= -1);*/

}
}
}catch(IOException e)
{

System.out.println("The error u r encountering is : "+e.getMessage());
throw new BuildException(e.getMessage());
}


finally
{
if(fis!= null)
try{fis.close();
}catch(Exception e){}
if(out!= null)
try{out.close();
}catch(Exception e){}
if(zIn != null)
try { zIn.close();
} catch (Exception e) {}
}



}




public void createDir(String name)
{
System.out.println("Inside createDir");
File f1 = new File(name);
if(!f1.isDirectory())
f1.mkdirs();
}


/**
* @param string
*/
public void setDestDir(String string) {
destDir = string;
}



/**
* @param string
*/
public void setSrcDir(String string) {
srcDir = string;
}


}




   <<Less

Re: cannot build directory from ANT custom Task

Posted By:   Anonymous  
Posted On:   Thursday, March 2, 2006 04:55 AM

cant read the code ... too bold ... too less formatted ... Global hint: you could reuse the existing task implementation. See the oata/taskdefs/default.properties for taskname-implementationclass-mapping.
About | Sitemap | Contact