一个寻找.jar 和.zip文件中class文件的工具
相信很多人跟我一样,苦于在各种包之间,不知道Class存在什么地方,为此,自己写了一个小工具,来寻找目录下的Class文件
支持 目录查询,支持带包路径查询
入口Entrance.java
package com.freud.looking; import java.io.IOException; /**
* Entrance which contains Main Method
*
* @author Freud
*
*/
public class Entrance { public static void main(String[] args) throws IOException { UIFrame entrance = new UIFrame();
entrance.initThePanel();
entrance.repaint();
}
}
Logic.java
package com.freud.looking; import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; /**
* 1. Get all the ended tails file 2. Validate the jar files which contains the
* condition classes 3. Validate the zip files which contains the condition
* classes
*
* @author Freud
*
*/
public class Logic { /**
* Traversal all the file to get end with tail's file
*
* @param file
* Files
* @param tail
* End tail
* @return Matched files
*/
public List<File> traversalFiles(File file, String tail) { List<File> files = new ArrayList<File>(); if (file.isDirectory()) {
for (File descendant : file.listFiles()) { for (File define : traversalFiles(descendant, tail)) { if (define.getName().endsWith(tail)) {
files.add(define);
} }
}
} else { if (file.getName().endsWith(tail)) {
files.add(file);
} } return files; } /**
* Validate the jar files for the condition classes
*
* @param files
* Jar file
* @param condition
* Needed classes
* @return Validated files
* @throws IOException
*/
public Set<String> validateJarFile(List<File> files, String condition) throws IOException { Set<String> flag = new HashSet<String>(); for (File file : files) { try {
JarFile jarFile = null;
try {
jarFile = new JarFile(file); Enumeration<JarEntry> jarentrys = jarFile.entries(); while (jarentrys.hasMoreElements()) { JarEntry jarEntry = (JarEntry) jarentrys.nextElement(); String name = jarEntry.getName().replace("/", ".").replace("\\", "."); if (name.contains(condition)) {
flag.add(jarFile.getName());
} if (name.contains(condition.replace("/", "."))) {
flag.add(jarFile.getName());
} if (name.contains(condition.replace("\\", "."))) {
flag.add(jarFile.getName());
} } } finally {
if (jarFile != null)
jarFile.close();
}
} catch (Exception e) {
System.out.println("Error Occured in File - " + file.getAbsolutePath());
}
}
return flag;
} /**
* Validate the zip files for the condition classes
*
* @param files
* Zip file
* @param condition
* Needed classes
* @return Validated files
* @throws IOException
*/
public Set<String> validateZipFile(List<File> files, String condition) throws IOException { Set<String> flag = new HashSet<String>(); for (File file : files) {
try {
ZipFile zipFile = null;
try {
zipFile = new ZipFile(file); @SuppressWarnings("unchecked")
Enumeration<ZipEntry> zipentrys = (Enumeration<ZipEntry>) zipFile.entries(); while (zipentrys.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) zipentrys.nextElement(); String name = zipEntry.getName().replace("/", ".").replace("\\", "."); if (name.contains(condition)) {
flag.add(zipFile.getName());
} if (name.contains(condition.replace("/", "."))) {
flag.add(zipFile.getName());
} if (name.contains(condition.replace("\\", "."))) {
flag.add(zipFile.getName());
}
}
} finally {
if (zipFile != null) {
zipFile.close();
}
} } catch (Exception e) {
System.out.println("Error Occured in File - " + file.getAbsolutePath());
}
}
return flag;
}
}
UIFrame.java
package com.freud.looking; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List; import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField; /**
* Show the main component and do Submit logic
*
* @author Freud
*
*/
public class UIFrame extends JFrame { /**
* serialVersionUID
*/
private static final long serialVersionUID = 1L; /**
* Components For the main frame
*/
private JLabel pathLable;
private JTextField pathField;
private JLabel conditionLable;
private JTextField conditionField;
private JLabel tailLabel;
private JCheckBox jarCheckBox;
private JCheckBox zipCheckBox;
private JLabel resultLabel;
private JTextField resultField;
private JButton submit; /**
* Constructor
*/
public UIFrame() { /**
* Main Frame initialization
*/
this.setTitle("Looking for Classes!");
this.setVisible(true);
this.setBounds(100, 100, 400, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(null); } /**
* Initialization the main panel's components
*
* @return status
*/
public boolean initThePanel() { try { /**
* Location defined
*/
pathLable = new JLabel("Path Of the Location!");
pathLable.setBounds(10, 10, 350, 20); pathField = new JTextField();
pathField.setBounds(10, 40, 350, 30); tailLabel = new JLabel("Tails");
tailLabel.setBounds(10, 80, 350, 20); jarCheckBox = new JCheckBox(".jar", true);
jarCheckBox.setBounds(10, 110, 50, 30); zipCheckBox = new JCheckBox(".zip");
zipCheckBox.setBounds(60, 110, 80, 30); conditionLable = new JLabel("Condition");
conditionLable.setBounds(170, 80, 100, 20); conditionField = new JTextField();
conditionField.setBounds(170, 110, 150, 30); resultLabel = new JLabel("Result Show --");
resultLabel.setBounds(10, 150, 350, 20); resultField = new JTextField();
resultField.setBounds(10, 180, 350, 30); submit = new JButton("Submit");
submit.setBounds(120, 220, 100, 30);
submit.addActionListener(new ActionListener() { /**
* Submit operations
*/
@Override
public void actionPerformed(ActionEvent e) { try {
String tail = "";
String condition = conditionField.getText(); Logic logic = new Logic(); StringBuffer sb = new StringBuffer(); /**
* Check the jar file box
*/
if (jarCheckBox.isSelected()) { tail = ".jar"; /**
* Get all files ended with ".jar"
*/
List<File> files = logic.traversalFiles(new File(pathField.getText()), tail); int i = 0; /**
* Validate the files which have the condition
* classes
*/
for (String item : logic.validateJarFile(files, condition)) {
if (i == 0) {
sb.append(item);
} else {
sb.append(";").append(item);
} i++; }
} /**
* Check the zip file box
*/
if (zipCheckBox.isSelected()) { tail = ".zip"; /**
* Get all files ended with ".zip"
*/
List<File> files = logic.traversalFiles(new File(pathField.getText()), tail); /**
* Validate the files which have the condition
* classes
*/
for (String item : logic.validateZipFile(files, condition)) {
if (sb.toString().equals("")) {
sb.append(item);
} else {
sb.append(";").append(item);
}
}
} /**
* If no files contains
*/
if (sb.toString().equals("")) {
sb.append("No matched file find!");
} /**
* Set result field
*/
resultField.setText(sb.toString()); } catch (Exception e1) {
/**
* Error handling
*/
resultField.setText("Error Occured : " + e1.getMessage());
} }
}); this.add(pathLable);
this.add(pathField);
this.add(conditionLable);
this.add(conditionField);
this.add(tailLabel);
this.add(jarCheckBox);
this.add(zipCheckBox);
this.add(resultLabel);
this.add(resultField);
this.add(submit); this.repaint(); return true; } catch (Exception e) {
return false;
}
}
}
一个寻找.jar 和.zip文件中class文件的工具的更多相关文章
- jar命令+7z:创建,替换,修改,删除Jar, war, ear包中的文件
虽然现在已经有各种智能的IDE可以为我们生成jar包,war包,ear包,甚至带上了自动替换,部署的功能.但一定会有那么些时候,你需要修改或是替换jar包,war包,ear包中的某个文件而不是整个重新 ...
- 文件_ _android从资源文件中读取文件流并显示的方法
======== 1 android从资源文件中读取文件流并显示的方法. 在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样: private ...
- pip freeze > requirements.txt` 命令输出文件中出现文件路径而非版本号
pip freeze > requirements.txt 命令输出文件中出现文件路径而非版本号 解决办法: pip list --format=freeze > requirements ...
- 推荐一个SAM文件或者bam文件中flag含义解释工具
SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这样的文件.samtools网站上有专门的文档介绍SAM文件.具体地址:http://samtools. ...
- 推荐一个SAM文件中flag含义解释工具--转载
SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这样的文件.samtools网站上有专门的文档介绍SAM文件.具体地址:http://samtools. ...
- VS2010在C#头文件中添加文件注释的方法
步骤: 1.VS2010 中找到安装盘符(本人安装目录在D盘,所以以D盘为例)D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\I ...
- VS2010在C#头文件中添加文件注释的方法(转)
步骤: 1.VS2010 中找到(安装盘符以D盘为例)D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTempl ...
- 31、SAM文件中flag含义解释工具--转载
转载:http://www.cnblogs.com/nkwy2012/p/6362996.html SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这 ...
- python移动多个子文件中的文件到一个文件夹
import os import os.path import shutil def listDir(dirTemp): if None == dirTemp: return global nameL ...
随机推荐
- task_struct
Linux中task_struct用来控制管理进程,结构如下: struct task_struct { //说明了该进程是否可以执行,还是可中断等信息 volatile long state; ...
- bzoj3677: [Apio2014]连珠线
Description 在列奥纳多·达·芬奇时期,有一个流行的童年游戏,叫做“连珠线”.不出所料,玩这个游戏只需要珠子和线,珠子从1到礼编号,线分为红色和蓝色.游戏 开始时,只有1个珠子,而接下来新的 ...
- xcode 升级插件失效问题
摘要 Xcode 升级到7之后VVDocumenter-Xcode,OMColorSense,KSImageNamed等一系列的插件失效的解决办法,以及不小心误点了 Skipbundle 的解决办法 ...
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取”产品付费数量等于0的问题”】
转的别人的 看到很多童鞋问到,为什么每次都返回数量等于0?? 其实有童鞋已经找到原因了,原因是你在 ItunesConnect 里的 “Contracts, Tax, and Banking”没有完成 ...
- [wikioi]关押罪犯
错误半天还是因为并查集写错了.写错的地方是合并X和Y的时候,应该把FX挂到FY上去,而不是把X挂到Y上或FY上去,因为FX和FY下面有一树别的节点. http://www.nocow.cn/index ...
- ANDROID_MARS学习笔记_S04_005_用sing-post向腾讯微博发一条信息
一.代码流程 1.组织好sign-post需要的token,secrect 2.组织好发微博需要的信息 3.用sign-post进行签名 4.把签名结果从header中拿出来,转成entity,用ht ...
- linux和windows双系统导致的时间日
我的博客:www.while0.com系统中有两种时间区分,一为UTC,另一为LT(地方时)两者的区别为时区不同,UTC就是0时区的时间,而我们当地是用的北京时间要慢8小时.linux采用的UTC时间 ...
- JavaScript 判断对象是否为空
/** **判断是否null *@param data */ function isNull(data) { return (data == "" || data == u ...
- Android上按钮解决快速点击问题
//代码2 public abstract class NoDoubleClickListener implements OnClickListener { ...
- HDU-2568 前进
http://acm.hdu.edu.cn/showproblem.php?pid=2568 前进 Time Limit: 2000/1000 MS (Java/Others) Memory L ...