本文整理汇总了Java中net.mindview.util.BinaryFile类的典型用法代码示例。如果您正苦于以下问题:Java BinaryFile类的具体用法?Java BinaryFile怎么用?Java BinaryFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryFile类属于net.mindview.util包,在下文中一共展示了BinaryFile类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import net.mindview.util.BinaryFile; //导入依赖的package包/类
public static void main(String[] args) {
boolean allFilesStartWithCAFEBABE = true;
String path = "";
try {
path = new File("./").getCanonicalPath();
Directory.TreeInfo tree = Directory.walk("./", ".*\\.class");
for(File file: tree.files) {
byte[] fileBytes = BinaryFile.read(file.getCanonicalFile());
String hexString = bytesToHexString(Arrays.copyOf(fileBytes, 4));
if(!hexString.toUpperCase().equals("CAFEBABE"))
allFilesStartWithCAFEBABE = false;
System.out.println("Filename: " + file.getName() + " startsWith: " + hexString);
}
} catch(IOException e) {
System.err.println("Caught " + e);
e.printStackTrace();
}
System.out.println("All files in " + path + " start with ‘CAFEBABE’ ? : "
+ (allFilesStartWithCAFEBABE ? "Yes": "No") );
}
示例2: main
import net.mindview.util.BinaryFile; //导入依赖的package包/类
public static void main(String[] args) {
try {
byte[] fileBytes = BinaryFile.read(fileName);
Map<Byte,Integer> counter = new TreeMap<Byte, Integer>();
for(Byte b: fileBytes) {
if (counter.containsKey(b) ) {
Integer count = counter.get(b);
counter.put(b, ++count);
} else {
counter.put(b,1);
}
}
System.out.println("Result: ");
for(Map.Entry<Byte, Integer> entry: counter.entrySet()) {
System.out.println(String.format("%02X", entry.getKey()) + " : " + entry.getValue());
}
} catch(IOException e) {
System.err.println("Caught " + e);
e.printStackTrace();
}
}
示例3: checkFiles
import net.mindview.util.BinaryFile; //导入依赖的package包/类
public static boolean checkFiles(String directory) throws IOException {
System.out.println(Arrays.toString(CAFEBABE) + " : " + "CAFEBABE");
File[] files = Directory.walk(directory, ".*\\.class").files.
toArray(new File[0]);
byte[] fileByteArray;
for (File f : files) {
fileByteArray = BinaryFile.read(f);
System.out.println(Arrays.toString(Arrays.copyOf(fileByteArray, 4))
+ " : " + f.getName());
if (!verifyFileBeginning(fileByteArray)) {
System.out.println(f.getName() + " is corrupted");
return false;
}
}
return true;
}
示例4: main
import net.mindview.util.BinaryFile; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if(args.length > 0) {
for(String arg : args)
print(thisClass(BinaryFile.read(new File(arg))));
} else
// Walk the entire tree:
for(File klass : Directory.walk(".", ".*\\.class"))
print(thisClass(BinaryFile.read(klass)));
}
示例5: process
import net.mindview.util.BinaryFile; //导入依赖的package包/类
public void process(File cFile) {
boolean modified = false;
try {
String cName = ClassNameFinder.thisClass(
BinaryFile.read(cFile));
if(!cName.contains("."))
return; // Ignore unpackaged classes
ClassPool cPool = ClassPool.getDefault();
CtClass ctClass = cPool.get(cName);
for(CtMethod method : ctClass.getDeclaredMethods()) {
MethodInfo mi = method.getMethodInfo();
AnnotationsAttribute attr = (AnnotationsAttribute)
mi.getAttribute(AnnotationsAttribute.visibleTag);
if(attr == null) continue;
for(Annotation ann : attr.getAnnotations()) {
if(ann.getTypeName()
.startsWith("net.mindview.atunit")) {
print(ctClass.getName() + " Method: "
+ mi.getName() + " " + ann);
if(remove) {
ctClass.removeMethod(method);
modified = true;
}
}
}
}
// Fields are not removed in this version (see text).
if(modified)
ctClass.toBytecode(new DataOutputStream(
new FileOutputStream(cFile)));
ctClass.detach();
} catch(Exception e) {
throw new RuntimeException(e);
}
}
示例6: countBytes
import net.mindview.util.BinaryFile; //导入依赖的package包/类
public static Map<Byte, Integer> countBytes(File file) throws IOException {
byte[] bytes = BinaryFile.read(file);
Map<Byte, Integer> map = new TreeMap<>();
Integer value;
for (byte b : bytes) {
map.put(b, (value = map.get(b)) == null ? 1 : ++value);
}
return map;
}