import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Properties;


public class RandomAccessTests {
	public static void main(String[] args) throws IOException
	{
		Runtime rt = Runtime.getRuntime();
		long free = rt.totalMemory()-rt.freeMemory();
		System.out.println("Java used memory: " + free + " bytes");
		
		System.out.println("Loading file...");
		RandomAccessFile raf = new RandomAccessFile("audio/01 Get Up.aif","r");
		System.out.println("File length: " + raf.length() + " bytes");
		
		free = rt.totalMemory()-rt.freeMemory();
		System.out.println("Java used memory: " + free + " bytes");
		
		System.out.println("Reading some random bytes...");
		byte[] rb = new byte[1024];
		for(int i=0;i<1024;i++)
		{
			raf.seek((int)(Math.random()*(raf.length()-1)));
			raf.read(rb, i, 1);
		}
		
		free = rt.totalMemory()-rt.freeMemory();
		System.out.println("Java used memory: " + free + " bytes");
				
		System.out.println("Reading all file bytes..");
		byte[] b;
		b = new byte[(int) raf.length()];
		raf.seek(0);
		raf.readFully(b);
		
		free = rt.totalMemory()-rt.freeMemory();
		System.out.println("Java used memory: " + free + " bytes");
	}
}
