package Cases; import java.io.*; import java.io.File; import neustore.base.DBIndex;//because we create a object of index.java import neustore.base.LRUBuffer;//because we create an object of it //NOTE: These are just for testing, so the values do not make sense. //You can change the test file as you want, ex: the for loop can be run for 10000 times. //the XML buffer delaration can be added, if you want to use the one which takes in only the numpages. public class Testcase30 { public static void main(String[] args)throws IOException { //all the pages will be stored under this file name String filename3="TESTFILE3"; File file= new File(filename3); if(file.delete()) { System.out.println("The old file with that name has been deleted"); } else { System.out.println("The file was not found"); } //'buf' is an object of XMLBuffer class. Passews 2 arguments 5=Buffer size and 120=page size in bytes XMLBuffer buf3= new XMLBuffer(5,120); // Those who just pass numPages. uncomment this and comment the previous one /* XMLBuffer buf3= new XMLBuffer(5);*/ //Creating an object of XMLContent class and passing the 'buf3'(buffer) , filename and boolean value 'true' (indicating a new file has to be created with the passed filename) //If we do not plan to create a new file for Structure index, then the Constructor of the XMLContent class should send 'false' to its super class //creating an object of XMLContent class to test its methods XMLContent XC=new XMLContent(buf3,filename3,1); //(STATE 7) //This code would append the content String s=new String("New String"); DiskAddress addr=XC.appendContent(s); for(int i=0;i<400;i++) //this loop keeps on appending the "New String" to the end of the content { addr=XC.appendContent(s); System.out.println("The appened content adress has Pageid="+addr.PageId+" and starts from "+addr.RecordNumber); } //This code will test the getContent method String str=XC.getContent(addr,100);//actaully there is not much content starting form this adress(only 10charactres are present). It is upto to you on how you handle this cases System.out.println("The returned string is "+str); if(str.equals(s)) //Check wether the arguments passed are correct depending upon your scheme of layout of pages { System.out.println("The getContent method runs fine"); } else { System.out.println("The getContent method did not return what we intended"); } //this code will get the size of the whole content int x=XC.getSize(); System.out.println("The total size of the content is"+x); addr=new DiskAddress(1,80);//starting from the 1st page 80th character, lets delete some 1000 charactres x=XC.deleteContent(addr,1000); //page merge may be needed, as some pages may become empty and first and last page may have too little of space used, so you can choose to merge those pages System.out.println("This Exit status of deleteContent is"+x); x=XC.getSize(); System.out.println("The total size of the content is"+x);//this time the content size should be reduced by 1000 // XC.close();//remove the comments if the file needs to be closed before exiting }//end of main() method }//end of TestCase3