001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Eric HARDESTY
022: * --------------------------------------------------------------------------
023: * $Id: JJarFile.java,v 1.0
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.common;
028:
029: import java.io.File;
030: import java.io.FileOutputStream;
031: import java.io.InputStream;
032: import java.io.IOException;
033: import java.util.jar.JarFile;
034: import java.util.jar.JarEntry;
035:
036: /**
037: * This class implements a JarFile that adds a extract/write method
038: * @author Eric Hardesty
039: */
040: public class JJarFile extends JarFile {
041:
042: /**
043: * Size of the buffer.
044: */
045: private static final int BUFFER_SIZE = 2048;
046:
047: /**
048: * Constructs a new JarFile with the specified File.
049: * @param file the jar file to be opened
050: */
051: public JJarFile(File file) throws IOException {
052: super (file);
053: }
054:
055: /**
056: * Constructs a new JarFile with the specified File.
057: * @param file the jar file to be opened
058: * @param verity boolean to verify if the JarFile is signed
059: */
060: public JJarFile(File file, boolean verify) throws IOException {
061: super (file, verify);
062: }
063:
064: /**
065: * Constructs a new JarFile with the specified File.
066: * @param file the jar file to be opened
067: * @param verity boolean to verify if the JarFile is signed
068: * @param mode int of the mode to open the jar
069: */
070: public JJarFile(File file, boolean verify, int mode)
071: throws IOException {
072: super (file, verify, mode);
073: }
074:
075: /**
076: * Constructs a new JarFile with the specified File.
077: * @param name the name of the jar file to be opened
078: */
079: public JJarFile(String name) throws IOException {
080: super (name);
081: }
082:
083: /**
084: * Constructs a new JarFile with the specified File.
085: * @param name the name of the jar file to be opened
086: * @param verity boolean to verify if the JarFile is signed
087: */
088: public JJarFile(String name, boolean verify) throws IOException {
089: super (name, verify);
090: }
091:
092: /**
093: * Extract the specified Jar Entry to the path given
094: * @param jEnt the JarEntry to extract
095: * @param filename the filename to write the extracted file
096: */
097: public void extract(JarEntry jEnt, String filename)
098: throws IOException {
099:
100: try {
101: //File output
102: FileOutputStream out = new FileOutputStream(filename);
103: InputStream jis = this .getInputStream(jEnt);
104: int n = 0;
105: try {
106: //buffer
107: byte buffer[] = new byte[BUFFER_SIZE];
108:
109: while ((n = jis.read(buffer)) > 0) {
110: out.write(buffer, 0, n);
111: }
112: } finally {
113: out.close();
114: jis.close();
115: }
116: } catch (IOException e) {
117: throw new IOException("Error while uncompressing the file "
118: + filename + ": " + e.getMessage());
119: }
120:
121: }
122:
123: }
|