001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io.session; 003 004import java.io.IOException; 005import java.io.OutputStream; 006import java.util.zip.ZipEntry; 007import java.util.zip.ZipException; 008import java.util.zip.ZipOutputStream; 009 010/** 011 * Export arbitrary data from a plugin. 012 * @since 18833 013 */ 014public interface PluginSessionExporter { 015 /** 016 * Get the filename to store the data in the archive 017 * @return The filename 018 * @see PluginSessionImporter#getFileName() 019 */ 020 String getFileName(); 021 022 /** 023 * Check to see if the specified exporter needs to save anything 024 * @return {@code true} if the exporter needs to save something 025 */ 026 boolean requiresSaving(); 027 028 /** 029 * Write data to a zip file 030 * @param zipOut The zip output stream 031 * @throws IOException see {@link ZipOutputStream#putNextEntry(ZipEntry)} 032 * @throws ZipException see {@link ZipOutputStream#putNextEntry(ZipEntry)} 033 */ 034 default void writeZipEntries(ZipOutputStream zipOut) throws IOException { 035 if (requiresSaving()) { 036 final ZipEntry zipEntry = new ZipEntry(this.getFileName()); 037 zipOut.putNextEntry(zipEntry); 038 this.write(zipOut); 039 } 040 } 041 042 /** 043 * Write the plugin data to a stream 044 * @param outputStream The stream to write to 045 */ 046 void write(OutputStream outputStream); 047}