Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /antelope/src/ise/antelope/tasks/typedefs/file/

antelope
Discussion topic

Back to topic list

CVS update: /antelope/src/ise/antelope/tasks/typedefs/file/

Author danson
Full name Dale Anson
Date 2005-10-30 16:29:43 PST
Message User: danson
Date: 2005/10/30 16:29:43

Added:
   antelope/src/ise/ant​elope/tasks/typedefs​/file/CanRead.java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/CanWrite.java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/FileCount.java​
   antelope/src/ise/ant​elope/tasks/typedefs​/file/FileLength.jav​a
   antelope/src/ise/ant​elope/tasks/typedefs​/file/FileLineCount.​java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/FileList.java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/FileOp.java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/IsDirectory.ja​va
   antelope/src/ise/ant​elope/tasks/typedefs​/file/IsFile.java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/IsHidden.java
   antelope/src/ise/ant​elope/tasks/typedefs​/file/LastModified.j​ava

Log:
 typedefs for fileutil task
 

File Changes:

Directory: /antelope/src/ise/an​telope/tasks/typedef​s/file/
====================​====================​==================

File [added]: CanRead.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/CanRead.java?​rev=1.1&content-​type=text/vnd.viewcv​s-markup
Added lines: 25
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class CanRead implements FileOp {
    
    /**
     * Checks if the given file is readable
     *
     * @param f a file
     * @return true if the file is a readable.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        return f.canRead() ? "true" : "false";
    }
}



File [added]: CanWrite.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/CanWrite.java​?rev=1.1&content​-type=text/vnd.viewc​vs-markup
Added lines: 25
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class CanWrite implements FileOp {
    
    /**
     * Checks if the given file is writable
     *
     * @param f a file
     * @return true if the file is a writable.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        return f.canWrite() ? "true" : "false";
    }
}



File [added]: FileCount.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/FileCount.jav​a?rev=1.1&conten​t-type=text/vnd.view​cvs-markup
Added lines: 34
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class FileCount implements FileOp {
    
    /**
     * Counts the number of files in a directory. Does not recurse. Does not
     * count subdirectores. Only counts files in the directory.
     *
     * @param f a directory
     * @return the number of files contained in the directory.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        if (!f.isDirectory())
            return "1";
        File[] files = f.listFiles();
        int file_count = 0;
        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile())
                ++file_count;
        }
        return String.valueOf(file_count);
    }
}



File [added]: FileLength.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/FileLength.ja​va?rev=1.1&conte​nt-type=text/vnd.vie​wcvs-markup
Added lines: 26
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class FileLength implements FileOp {
    
    /**
     * Description of the Method
     *
     * @param f a file
     * @return the length of the file.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        return String.valueOf(f.length());
        
    }
}



File [added]: FileLineCount.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/FileLineCount​.java?rev=1.1&co​ntent-type=text/vnd.​viewcvs-markup
Added lines: 48
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;
import org.apache.tools.ant​.BuildException;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class FileLineCount implements FileOp {
    
    /**
     * Description of the Method
     *
     * @param f a file
     * @return the number of lines in the file
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        System.out.println(f);
        LineNumberReader lnr = null;
        try {
            lnr = new LineNumberReader(new FileReader(f));
            String line = lnr.readLine();
            while(line != null) {
                line = lnr.readLine();
            }
            return String.valueOf(lnr.g​etLineNumber());
        }
        catch(Exception e) {
            throw new BuildException(e.getMessage());
        }
        finally {
            try {
                if (lnr != null)
                    lnr.close();
            }
            catch(Exception e) {
                // ignored
            }
        }
        
    }
}



File [added]: FileList.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/FileList.java​?rev=1.1&content​-type=text/vnd.viewc​vs-markup
Added lines: 52
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.File;
import java.util.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class FileList implements FileOp {
    
    private String separator = ",";
    private boolean includepath = true;
    
    public void setSeparator(String s) {
        if (s != null)
            separator = s;
    }
    
    public void setIncludepath(boolean b) {
        includepath = b;
    }
    
    /**
     * Lists the files in a directory. Does not recurse. Does not
     * list subdirectores. Only lists files in the directory.
     *
     * @param f a directory
     * @return a list of files contained in the directory.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        if (!f.isDirectory())
            return f.toString();
        List files = Arrays.asList(f.listFiles());
        StringBuffer value = new StringBuffer();
        for (Iterator it = files.iterator(); it.hasNext(); ) {
            File file = (File)it.next();
            if (file.isFile()){
                String filename = includepath ? file.getAbsolutePath() : file.getName();
                value.append(filename);
                if (it.hasNext())
                    value.append(separator);
            }
        }
        return value.toString();
    }
}



File [added]: FileOp.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/FileOp.java?r​ev=1.1&content-t​ype=text/vnd.viewcvs​-markup
Added lines: 7
--------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.File;

public interface FileOp {
    public String execute(File f);
}

File [added]: IsDirectory.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/IsDirectory.j​ava?rev=1.1&cont​ent-type=text/vnd.vi​ewcvs-markup
Added lines: 25
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class IsDirectory implements FileOp {
    
    /**
     * Checks if the given file is a directory
     *
     * @param f a file
     * @return true if the file is a directory
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        return f.isDirectory() ? "true" : "false";
    }
}



File [added]: IsFile.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/IsFile.java?r​ev=1.1&content-t​ype=text/vnd.viewcvs​-markup
Added lines: 25
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class IsFile implements FileOp {
    
    /**
     * Checks if the given file is a file
     *
     * @param f a file
     * @return true if the file is a file, not a directory.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        return f.isFile() ? "true" : "false";
    }
}



File [added]: IsHidden.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/IsHidden.java​?rev=1.1&content​-type=text/vnd.viewc​vs-markup
Added lines: 25
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class IsHidden implements FileOp {
    
    /**
     * Checks if the given file is a hidden file
     *
     * @param f a file
     * @return true if the file is a hidden file.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        return f.isHidden() ? "true" : "false";
    }
}



File [added]: LastModified.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/tasks/typedef​s/file/LastModified.​java?rev=1.1&con​tent-type=text/vnd.v​iewcvs-markup
Added lines: 39
---------------
package ise.antelope.tasks.t​ypedefs.file;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Copyright 2003
 *
 * @version $Revision: 1.1 $
 */
public class LastModified implements FileOp {
    
    private String format = null;
    
    public void setFormat(String f) {
        format = f;
    }
    
    /**
     * Checks if the given file is writable
     *
     * @param f a file
     * @return true if the file is a writable.
     */
    public String execute(File f) {
        if (f == null)
            throw new IllegalArgumentException("file cannot be null");
        Date date = new Date(f.lastModified());
        String lm;
        if (format != null)
            lm = new SimpleDateFormat(for​mat).format(date);
        else
            lm = date.toString();
        return lm;
    }
}

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /antelope/src/ise/antelope/tasks/typedefs/file/ danson Dale Anson 2005-10-30 16:29:43 PST
Messages per page: