当前位置: 首页>>代码示例>>Java>>正文


Java BinaryFile类代码示例

本文整理汇总了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") );

}
 
开发者ID:spiffykahuna,项目名称:TIJ4-code_idea,代码行数:26,代码来源:Exercise20.java

示例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();
    }

}
 
开发者ID:spiffykahuna,项目名称:TIJ4-code_idea,代码行数:26,代码来源:Exercise19.java

示例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;
}
 
开发者ID:bodydomelight,项目名称:tij-problems,代码行数:17,代码来源:ClassBytesVerifier.java

示例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)));
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:10,代码来源:ClassNameFinder.java

示例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);
  }
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:36,代码来源:AtUnitRemover.java

示例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;
}
 
开发者ID:bodydomelight,项目名称:tij-problems,代码行数:10,代码来源:ByteCounter.java


注:本文中的net.mindview.util.BinaryFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。