1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.enterprise.diagnostics.Data; 26 import com.sun.enterprise.diagnostics.util.FileUtils; 27 import com.sun.enterprise.diagnostics.DiagnosticException; 28 import com.sun.logging.LogDomains; 29 import java.io.File ; 30 import java.io.IOException ; 31 import java.util.List ; 32 import java.util.logging.Level ; 33 import java.util.logging.Logger ; 34 35 39 public class FilesCollector implements Collector { 40 41 private String repositoryDir ; 42 private String reportDir; 43 private List <String > files; 44 private String dataType; 45 private static Logger logger = 46 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 47 48 public FilesCollector(String repositoryDir, String reportDir, 49 List <String > files, String dataType) { 50 this.repositoryDir = repositoryDir; 51 this.reportDir = reportDir; 52 this.files = files; 53 this.dataType = dataType; 54 } 55 56 public Data capture() throws DiagnosticException { 57 WritableDataImpl writableData = null; 58 if (files != null && repositoryDir != null && reportDir != null) { 59 writableData = new WritableDataImpl(dataType); 60 for(String fileName : files) { 61 String srcFile = repositoryDir + File.separator + fileName; 62 if(new File (srcFile).exists()) { 63 String destFile = reportDir + File.separator + fileName; 64 try { 65 FileUtils.copyFile(srcFile, destFile); 66 writableData.addChild(new FileData(fileName, dataType)); 67 } catch(IOException io) { 68 log(Level.WARNING, "Error occurred during copy of file" + srcFile); 69 } 70 71 } 72 } 73 } 74 return writableData; 75 } 76 77 private void log(Level level, String message) { 78 logger.log(level, message); 79 } 80 } 81 | Popular Tags |