Project

General

Profile

Download (2.04 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.csv.redlist.out;
10

    
11
import java.io.File;
12
import java.io.FileOutputStream;
13
import java.io.IOException;
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.zip.ZipEntry;
17
import java.util.zip.ZipOutputStream;
18

    
19
import org.apache.log4j.Logger;
20

    
21
import eu.etaxonomy.cdm.io.common.XmlExportState;
22

    
23
/**
24
 * @author a.mueller
25
 * @created 18.04.2011
26
 */
27
public class CsvTaxExportStateRedlist extends XmlExportState<CsvTaxExportConfiguratorRedlist>{
28
	@SuppressWarnings("unused")
29
	private static final Logger logger = Logger.getLogger(CsvTaxExportStateRedlist.class);
30

    
31
	private List<CsvMetaDataRecordRedlist> metaRecords = new ArrayList<CsvMetaDataRecordRedlist>();
32
	private boolean isZip = false;
33
	private ZipOutputStream zos;
34
	
35
	public CsvTaxExportStateRedlist(CsvTaxExportConfiguratorRedlist config) {
36
		super(config);
37
		File file = config.getDestination();
38
		if (! config.getDestination().isDirectory()){
39
			try{
40
				isZip = true;
41
				if (! file.exists()){
42
						file.createNewFile();
43
				}
44
				
45
			  	zos  = new ZipOutputStream( new FileOutputStream(file) ) ;
46
			} catch (IOException e) {
47
				throw new RuntimeException(e);
48
			}
49
		}
50
	}
51
	
52
	public void addMetaRecord(CsvMetaDataRecordRedlist record){
53
		metaRecords.add(record);
54
	}
55
	
56
	public List<CsvMetaDataRecordRedlist> getMetaRecords(){
57
		return metaRecords;
58
	}
59

    
60
	/**
61
	 * @return the isZip
62
	 */
63
	public boolean isZip() {
64
		return isZip;
65
	}
66

    
67
	public ZipOutputStream getZipStream(String fileName) throws IOException {
68
		if (isZip){
69
			zos.putNextEntry(new ZipEntry(fileName));
70
			return zos;
71
		}else{
72
			return null;
73
		}
74
	}
75

    
76
	public void closeZip() throws IOException {
77
		if (zos != null){
78
			zos.closeEntry();
79
			zos.finish();
80
			zos.close();
81
		}
82
	}
83
	
84

    
85

    
86
}
(7-7/10)