📄 zippathcomparator.java
字号:
package ranab.jar;
import java.util.zip.ZipEntry;
/**
* Compare two zip entries based on the file name.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class ZipPathComparator extends ZipComparator {
public int compare(Object o1, Object o2) {
if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry)) {
throw new IllegalArgumentException("Not a ZipEntry object.");
}
ZipEntry z1 = (ZipEntry)o1;
ZipEntry z2 = (ZipEntry)o2;
return getPath(z1).compareTo(getPath(z2));
}
public boolean equals(Object o1, Object o2) {
if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry)) {
throw new IllegalArgumentException("Not a ZipEntry object.");
}
ZipEntry z1 = (ZipEntry)o1;
ZipEntry z2 = (ZipEntry)o2;
return getPath(z1).equals(getPath(z2));
}
/**
* get zip entry path
*/
public static String getPath(ZipEntry ze) {
String fullName = ze.getName();
int index = fullName.lastIndexOf('/');
if (index == -1) {
return "";
}
return fullName.substring(0, index + 1);
}
/**
* get header name
*/
public String getHeaderName() {
return "Path";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -