本文整理汇总了Java中net.mindview.util.BinaryFile.read方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryFile.read方法的具体用法?Java BinaryFile.read怎么用?Java BinaryFile.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.mindview.util.BinaryFile
的用法示例。
在下文中一共展示了BinaryFile.read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}