Search in sources :

Example 6 with CSVWriter

use of com.talend.csv.CSVWriter in project tdq-studio-se by Talend.

the class ReportFileHelper method saveReportListFile.

/**
 * DOC xqliu Comment method "saveReportListFile".
 *
 * @param reportListFile
 * @param repList
 * @throws IOException
 * @throws PersistenceException
 */
public static void saveReportListFile(final File reportListFile, final List<ReportListParameters> repList) throws PersistenceException {
    RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit(ProjectManager.getInstance().getCurrentProject(), // $NON-NLS-1$
    "saveReportListFile") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            try {
                CSVWriter out = FileUtils.createCSVWriter(reportListFile, FileUtils.TEXT_QUAL, FileUtils.ESCAPE_CHAR);
                ReportListEnum[] values = ReportListEnum.values();
                String[] temp = new String[values.length];
                for (int i = 0; i < repList.size() + 1; i++) {
                    if (i == 0) {
                        temp[0] = ReportListEnum.Name.getLiteral();
                        temp[1] = ReportListEnum.Path.getLiteral();
                        temp[2] = ReportListEnum.CreateTime.getLiteral();
                    } else {
                        temp[0] = repList.get(i - 1).name;
                        temp[1] = repList.get(i - 1).path;
                        temp[2] = repList.get(i - 1).createTime;
                    }
                    out.writeNext(temp);
                }
                out.flush();
                out.close();
            } catch (FileNotFoundException e) {
                log.error(e);
            } catch (IOException e) {
                log.error(e);
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    repositoryWorkUnit.throwPersistenceExceptionIfAny();
}
Also used : FileNotFoundException(java.io.FileNotFoundException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) CSVWriter(com.talend.csv.CSVWriter) IOException(java.io.IOException)

Aggregations

CSVWriter (com.talend.csv.CSVWriter)6 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)3 BufferedWriter (java.io.BufferedWriter)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 TdExpression (org.talend.cwm.relational.TdExpression)1 BufferedLineWriter (org.talend.daikon.runtime.BufferedLineWriter)1 ParserRuleToExcelEnum (org.talend.dataprofiler.core.ui.wizard.parserrule.ParserRuleToExcelEnum)1 Pattern (org.talend.dataquality.domain.pattern.Pattern)1 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)1 ParserRule (org.talend.dataquality.rules.ParserRule)1 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)1