zipxf.java

来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 206 行

JAVA
206
字号
/**  * File and FTP Explorer  * Copyright 2002  * BOESCH Vincent  *  * This program is free software; you can redistribute it and/or  * modify it under the terms of the GNU General Public License  * as published by the Free Software Foundation; either version 2  * of the License, or (at your option) any later version.  *  * This program is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  * GNU General Public License for more details.  *  * You should have received a copy of the GNU General Public License  * along with this program; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  */package javaexplorer.manager.zip;import objectxml.*;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.*;import java.util.zip.*;import javaexplorer.Launcher;import javaexplorer.model.XFile;import javaexplorer.ressource.MagicNumber;import javaexplorer.util.XFileBuffer;import javaexplorer.util.XFileUtil;//import javaexplorer.util.ReadableChannel;import javaexplorer.util.comparator.XFileComparator;import javaexplorer.util.filter.XFileFilter;import java.nio.channels.*;public class ZipXF implements XFile {    private File _file = null;    private boolean _isDir = false;    private transient Launcher _launcher = null;    private long _length = 0;    private long _date = -1;    private ZipXF _parent = null;    private transient ZipFile _zf = null;    private String _zipFile = null;    private String _zx = null;    /**     * Constructeur sans argument, utilise par la xmlization     */    public ZipXF() {    }    /**     *  Constructeur objet ZipXF     *     *@param  zf    Description of the Parameter     *@param  name  Description of the Parameter     */    public ZipXF(ZipFile zf, String name) {        _zf = zf;        _zipFile = _zf.getName();        _zx = name;        if (_zx == null) {            _zx = "/";        }        ZipEntry ze = _zf.getEntry(_zx);        if (ze == null) {            _isDir = true;            _length = 0;            _date = -1;        } else {            _isDir = ze.isDirectory();            _length = ze.getSize();            _date = ze.getTime();        }    }    /**     *@param  destinationDir  Description of     *      the Parameter     */    public void copyTo(XFile destinationDir) {        _launcher.getXUtil().copyTo(this, destinationDir);    }    /**     *@param  eFile  Description of the Parameter     *@return        Description of the Return     *      Value     */    public boolean equals(XFile eFile) {        if (!(eFile instanceof ZipXF) || (eFile == null)) {            return false;        }        return toString().equalsIgnoreCase(eFile.toString());    }    /**     *@return    Description of the Return     *      Value     */    public boolean exists() {        return _zf != null;        // && _ze != null;    }    /**     */    public void freeRessource() {        //Suppression des 閘閙ents dans les listes de copie et de s閘ection 閠ant concern閟 par ce fichier Zip        //Car sinon cela peut provoquer une erreur        try {            boolean needRefresh = false;            //Parcours de la liste des 閘閙ents s閘ectionn閟            XFileBuffer lst = _launcher.getFileModel().getSelectBuffer();            for( int i = 0 ; i < lst.length(); i++ ){                XFile xf = (XFile)lst.getAt(i);                if( xf instanceof ZipXF ){                    if(((ZipXF)xf).isZipFileMatching(_zf)){                        lst.remove(xf);                        needRefresh = true;                        i--;                    }                }            }            //Parcours de la liste des 閘閙ents en copie            lst = _launcher.getFileModel().getCopyMoveBuffer();            for( int i = 0 ; i < lst.length(); i++ ){                XFile xf = (XFile)lst.getAt(i);                if( xf instanceof ZipXF ){                    if(((ZipXF)xf).isZipFileMatching(_zf)){                        lst.remove(xf);                        needRefresh = true;                        i--;                    }                }            }            _zf.close();            if( needRefresh ) _launcher.getMDIModel().updateStatus();        } catch (Exception ioe) {        }    }    /**     *  Gets the freeEF attribute of the ZipXF     *  object     *     *@param  name   Description of the Parameter     *@param  isDir  Description of the Parameter     *@return        The freeEF value     */    public XFile getFreeEF(String name, boolean isDir) {        return null;    }    /**     *  Gets the inputStream attribute of the     *  ZipXF object     *     *@param  restart       Description of     *      the Parameter     *@return               The inputStream     *      value     *@throws  IOException  Description of     *      the Exception     */    public InputStream getInputStream(long restart) throws IOException {        ZipEntry ze = _zf.getEntry(_zx);        InputStream is = null;        if (ze == null) {            return null;        } else {            is = _zf.getInputStream(ze);        }        if( is != null ){            is.skip(restart);                  }        return is;    }    /**     *  Gets the localFile attribute of the     *  ZipXF object     *     *@return    The localFile value     */    public File getLocalFile() {        if (_file != null) {            //D閖

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?