Revision 34444 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/utils/Compress.java

View differences:

Compress.java
38 38
import java.util.zip.ZipEntry;
39 39
import java.util.zip.ZipOutputStream;
40 40

  
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

  
44 41
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
42
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
45 43

  
46 44
/**
47 45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
48 46
 */
49 47
public class Compress {
50 48

  
51
    static final int BUFFER = 2048;
52
    private static final Logger logger = LoggerFactory
53
        .getLogger(Compress.class);
49
    private static final int BUFFER = 2048;
54 50

  
55
    public Compress() {
56
        super();
57
    }
58

  
59 51
    public void compressPluginAsPackageSet(File file, String fileName,
60 52
        OutputStream os) throws MakePluginPackageServiceException {
61 53
        List<File> files = new ArrayList<File>();
......
92 84
            }
93 85
            zos.close();
94 86
        } catch (Exception e) {
95
            logger.error("Error compressing the plugin");
96 87
            throw new MakePluginPackageServiceException(
97
                "Error writing the plugin", e);
88
                "Error compressing as package set the plugin files: " + files,
89
                e);
98 90
        }
99 91
    }
100 92

  
......
108 100
            zos.close();
109 101
        } catch (IOException e) {
110 102
            throw new MakePluginPackageServiceException(
111
                "Error compressing the plugin folder: " + folder, e);
103
                "Error compressing as package the plugin folder: " + folder, e);
112 104
        }
113 105
    }
114 106

  
107
    public void compressPluginAsPackageIndex(File folder, OutputStream os)
108
        throws MakePluginPackageServiceException {
109
        ZipOutputStream zos = new ZipOutputStream(os);
110
        try {
111
            int parentFileLength = folder.getParentFile().toString().length();
112
            String folderName =
113
                folder.toString()
114
                    .substring(parentFileLength + 1, folder.toString().length());
115
            
116
            File infoFile =
117
                new File(folder, getPackageInfoFileName() + ".index");
118

  
119
            byte[] buf = new byte[1024];
120
            int len;
121

  
122
            ZipEntry zipEntry =
123
                new ZipEntry(folderName + File.separator
124
                    + getPackageInfoFileName());
125
            zos.putNextEntry(zipEntry);
126

  
127
            FileInputStream fin = new FileInputStream(infoFile);
128
            BufferedInputStream in = new BufferedInputStream(fin);
129
            while ((len = in.read(buf)) >= 0) {
130
                zos.write(buf, 0, len);
131
            }
132
            in.close();
133
            zos.closeEntry();
134
            zos.flush();
135
            zos.close();
136
        } catch (IOException e) {
137
            throw new MakePluginPackageServiceException(
138
                "Error compressing as package index the plugin folder: "
139
                    + folder, e);
140
        }
141
    }
142

  
115 143
    private void compressPluginFiles(File fileOrFolder, ZipOutputStream zos)
116 144
        throws IOException {
117 145
        int parentFileLenght = fileOrFolder.getParentFile().toString().length();
......
157 185
            zosPlugin.closeEntry();
158 186
        }
159 187
    }
188

  
189
    private String getPackageInfoFileName() {
190
        return InstallerProviderLocator.getProviderManager()
191
            .getPackageInfoFileName();
192
    }
160 193
}

Also available in: Unified diff