FileDocCategorySizeDatePackage
ChecksumCollector.javaAPI DocGlassfish v2 API6963Fri May 04 22:34:44 BST 2007com.sun.enterprise.diagnostics.collect

ChecksumCollector

public class ChecksumCollector extends Object implements Collector
Collects check sum information for binaries
author
Manisha Umbarje

Fields Summary
private String
source
private String
destFolder
private String
destFile
private BufferedWriter
writer
private WritableData
dataObj
private static final String
BIN_FOLDER
private static final String
LIB_FOLDER
private static final String
JAR_EXT
private static final String
DLL_EXT
private static final String
SO_EXT
private static Logger
logger
Constructors Summary
public ChecksumCollector(String source, String destFolder)
Creates a new instance of ChecksumCollector

param
destFolder destination folder in which checksum information is copied.

                           
         
        this.destFolder = destFolder;
        this.source = source;
        dataObj = new WritableDataImpl(source, DataType.CHECKSUM);
    
Methods Summary
public com.sun.enterprise.diagnostics.Datacapture()
Captures check sum information

throw
DiagnosticException

        dataObj.addRow(Arrays.asList(new String[]{"Name", "Length", "Checksum"}));
        captureChecksum(source + LIB_FOLDER, getFilter());
        captureChecksum(source + BIN_FOLDER, null);
        return dataObj;
    
private voidcaptureChecksum(java.lang.String sourceName, java.io.FilenameFilter filter)
Captures checksum of files specified by the filter

param
sourceName source folder from where files are copied
param
filter file name filter
throw
DiagnosticException

        
        File fileObj = new File(sourceName);
        String[] fileNames = fileObj.list(filter);
        if(fileNames != null) {
            int length = fileNames.length;
            for (int i = 0 ; i < length; i++) {
                dataObj.addRow(generateCRC32Checksum(sourceName, fileNames[i]));
            }
        }

    
private java.util.ListgenerateCRC32Checksum(java.lang.String parent, java.lang.String fileName)
Generates check sum

param
file name of the file for which checkum is calculated
return
list containing file name, length and checksum

        try {
        // First item being name of file, second - length; third being checksum
        String file = parent + File.separator + fileName;
        List<String> checksumInfo = new ArrayList(3);
        CRC32 crc32 = new CRC32();
        int length = 0;
        BufferedInputStream fileinputstream = new BufferedInputStream(
                new FileInputStream(new File(file)));
        for( CheckedInputStream checkedinputstream = new CheckedInputStream(
        fileinputstream, crc32); checkedinputstream.read() != -1;)
                length++;
        long cksum = crc32.getValue();
        fileinputstream.close();
        fileinputstream = null;
        crc32 = null;
        checksumInfo.add(fileName);
        checksumInfo.add(Integer.toString(length));
        checksumInfo.add(Long.toString(cksum));
        return checksumInfo;
        } catch(Exception e) {
           //ignore
            logger.log(Level.FINE, "diagnostic-service.compute_checksum_failed"
                    ,new Object[]{fileName, e.getMessage()});
            return null;
        }
    
private java.io.FilenameFiltergetFilter()
Gets filter which recognizes .jar and .so/.dll files

return
FilenameFilter

        final String[] exts ;
        if(isSolaris())
            exts = new String[] {JAR_EXT, SO_EXT};
        else
            exts = new String[] {JAR_EXT, DLL_EXT};
        return new FilenameFilter(){
            public boolean accept(File dir, String name) {
                return name.endsWith(exts[0]) ||
                        name.endsWith(exts[1]);
            }
        };
    
private booleanisSolaris()

        return DiagnosticServiceHelper.isSolaris();
    
private voidwriteToFile(java.util.List checksumInfo)

        if (checksumInfo != null) {
            try {
                writer.write("\n");
                for(String entry : checksumInfo) {
                    writer.write(entry + "\t");
                } //for
             }catch(IOException ioe) {
               //ignore
            }
            
       }//if