package iitb.con.util;
import iitb.con.ds.ItemSerializer;
import iitb.con.io.BufferedFileAdapter;
import iitb.con.io.IOAdapter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
public class FileDump {
public static void dumpFile(String name, int lineLength) {
try {
File f = new File(name);
int length = (int)f.length();
IOAdapter file = new BufferedFileAdapter(name, "r", length);
ByteBuffer buffer = file.readIntoBuffer(0);
buffer.rewind();
while (buffer.hasRemaining()) {
System.out.print(
Integer.toString( ( (byte)buffer.get() & 0xff ) + 0x100, 16 ).substring( 1 ) + " ");
if(((buffer.position()) % lineLength) == 0)
System.out.print("\n");
}
file.close();
}catch(FileNotFoundException fe){
fe.printStackTrace();
}catch(IOException ie) {
ie.printStackTrace();
}
}
public static void dumpFile(String name, int lineLength, ItemSerializer is) {
try {
File f = new File(name);
int length = (int)f.length();
IOAdapter file = new BufferedFileAdapter(name, "r", length);
ByteBuffer buffer = file.readIntoBuffer(0);
buffer.rewind();
while (buffer.hasRemaining()) {
if(((buffer.position() + 1) % lineLength) == 0)
System.out.print("\n");
System.out.print((byte)buffer.get());
}
file.close();
}catch(FileNotFoundException fe){
fe.printStackTrace();
}catch(IOException ie) {
ie.printStackTrace();
}
}
}