Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Reading from CD image  (Read 1001 times)
0 Members and 1 Guest are viewing this topic.
Offline NecroRomancist

JGO n00b
*

Posts: 11



« on: 2007-11-14 04:09:20 »

Hi all.
I'm trying to implement a discjuggler cd images parser and reader in Java for a project of mine.It is currently simple, just gets the number of tracks , sessions and their info. My problem is that i will need to read sectors from the image onto a java array to process them in my app, and to get the info i've got already i had to byteswap the integers i read, so if i read a full sector that would involve byteswapping the whole sector.
I'm using normal byte arrays to hold the data, because in my test's direct byte buffers read and writes are really slow when compared to normal byte array handling. Is there any way to speed this up?

Just a part of the code

##########################################################################

   public static final int CDI_V2 =  0x80000004;
   public static final int CDI_V3  = 0x80000005;
   public static final int CDI_V35 = 0x80000006;

   
   private RandomAccessFile seeker;
   private image_s ImageInfo;
   
      
   public CDI(String filename){
      try {
         seeker = new RandomAccessFile(filename,"r");
      } catch (FileNotFoundException e) {
      }
      ImageInfo = new image_s();
      cdi_init();
   }
   
   
   private final void cdi_init(){
      try {
         ImageInfo.length = seeker.length();
         
         seeker.seek(ImageInfo.length-8);
         
         System.out.println(ImageInfo.length);
         
         // LE
         ImageInfo.version = Integer.reverseBytes(seeker.readInt());
         
         printVersion();
                  
         ImageInfo.header_offset = Integer.reverseBytes(seeker.readInt());
         
         System.out.println(ImageInfo.header_offset);
         
         CDI_get_sessions();
         
         System.out.println("This image has " + ImageInfo.sessions + "sessions");
         
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
   
   private void CDI_get_sessions () throws IOException
   {
        if (ImageInfo.version == CDI_V35)
           seeker.seek(ImageInfo.length - ImageInfo.header_offset);
        else
           seeker.seek(ImageInfo.header_offset);
        
        ImageInfo.sessions = seeker.readUnsignedByte();
   }

##################################################################

As u can see to get the correct image version i had to byteswap the bytes and the same holds for the rest of my code.

All the best
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.072 seconds with 20 queries.