Project

General

Profile

Revision a0c384e7

IDa0c384e7583468d947672ab962ea2c4c3e097723
Parent e75532a6
Child f6b1d0ad

Added by Katja Luther over 3 years ago

save cdm light export to zip file

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java
10 10
package eu.etaxonomy.taxeditor.io;
11 11

  
12 12
import java.io.BufferedWriter;
13
import java.io.ByteArrayOutputStream;
13 14
import java.io.File;
14 15
import java.io.FileOutputStream;
16
import java.io.IOException;
15 17
import java.io.OutputStreamWriter;
16 18
import java.io.Writer;
19
import java.text.SimpleDateFormat;
20
import java.util.Calendar;
17 21
import java.util.List;
18 22
import java.util.Map;
19 23
import java.util.Set;
24
import java.util.zip.ZipEntry;
25
import java.util.zip.ZipOutputStream;
20 26

  
21 27
import org.apache.log4j.Logger;
22 28
import org.eclipse.core.runtime.Assert;
......
59 65
public class ExportManager extends AbstractIOManager<IExportConfigurator> {
60 66

  
61 67
    private static final Logger logger = Logger.getLogger(ExportManager.class);
62

  
68
    /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
69
	public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
63 70
	/**
64 71
	 *
65 72
	 * @param applicationConfiguration
......
308 315
                         } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
309 316
                             Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
310 317
                             Set<String> keySet = resultMap.keySet();
311
                             for (String key: keySet){
318
                             SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
319
                             Calendar cal = Calendar.getInstance();
320
                            
321

  
322
                             File file = new File(urlString+File.separator + "csv_light_" + sdf.format(cal.getTime())+ ".zip");                              
323
                             FileOutputStream stream = new FileOutputStream(file);
324
                             ZipOutputStream zos = new ZipOutputStream(stream);
325
							 for (String key: keySet){
312 326
                                 byte[] fileData = resultMap.get(key);
313 327
                                 String fileEnding ="";
314 328
                                 if (configurator instanceof OutputModelConfigurator){
315 329
                                     fileEnding  = ".csv";
316 330
                                 }
317
                                 File file = new File(urlString+File.separator + key + fileEnding);
318
                                 FileOutputStream stream = new FileOutputStream(file);
319
                                 Writer out = new BufferedWriter(new OutputStreamWriter(
320
                             			stream, "UTF8"));
321
                                 stream.write(fileData);
322
                                 stream.close();
323
                             }
331

  
332
								ZipEntry entry = new ZipEntry( key + fileEnding); 
333
								zos.putNextEntry(entry);
334
								zos.write(fileData);
335
								zos.closeEntry();
336
							 }
337
                           
338
                            zos.close();
339
                        
324 340

  
325 341
                         }else{
326 342
                             logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)