Project

General

Profile

Download (2.03 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.dwca.out;
10

    
11
import java.io.IOException;
12
import java.io.PrintWriter;
13

    
14
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
16
import org.springframework.stereotype.Component;
17

    
18
/**
19
 * Final result processor for Darwin Core Archive exports.
20
 *
21
 * @author a.mueller
22
 * @since 25.06.2017
23
 */
24
@Component
25
public class DwcaResultWriter extends DwcaExportBase {
26

    
27
    private static final long serialVersionUID = -1657568483721887287L;
28
    @SuppressWarnings("unused")
29
    private static final Logger logger = LogManager.getLogger(DwcaDescriptionExport.class);
30

    
31
    @Override
32
    protected void doInvoke(DwcaTaxExportState state) {
33
        addReport(state);
34
        closeZip(state);
35
        state.getProcessor().createFinalResult();
36
    }
37

    
38
    /**
39
     * @param state
40
     */
41
    protected void addReport(DwcaTaxExportState state) {
42
        if (state.getConfig().getDestination() != null){
43
            try {
44
                StringBuffer report = state.getResult().createReport();
45
                PrintWriter writer = createPrintWriter(state, DwcaTaxExportFile.REPORT);
46
                writer.print(report.toString());
47
                writer.flush();
48

    
49
            } catch (IOException e) {
50
                state.getResult().addError("Unexpected exception when trying to add export report.");
51
            }
52
        }
53
    }
54

    
55
    protected void closeZip(DwcaTaxExportState state) {
56
        if (state.isZip()){
57
            try {
58
                state.closeZip();
59
            } catch (IOException e) {
60
                throw new RuntimeException(e);
61
            }
62
        }
63
    }
64

    
65
    @Override
66
    protected boolean doCheck(DwcaTaxExportState state) {
67
        return false;
68
    }
69

    
70
    @Override
71
    protected boolean isIgnore(DwcaTaxExportState state) {
72
        return false;
73
    }
74
}
(20-20/33)