Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Reading from CD image  (Read 1184 times)
0 Members and 1 Guest are viewing this topic.
Offline NecroRomancist

Senior Newbie





« Posted 2007-11-14 10: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (67 views)
2013-05-17 12:29:12

alaslipknot (76 views)
2013-05-16 12:24:48

gouessej (109 views)
2013-05-15 15:53:38

gouessej (104 views)
2013-05-15 15:17:58

theagentd (115 views)
2013-05-15 06:01:13

theagentd (104 views)
2013-05-15 06:00:54

StreetDoggy (149 views)
2013-05-14 06:56:26

kutucuk (172 views)
2013-05-12 08:10:36

kutucuk (170 views)
2013-05-12 06:36:09

UnluckyDevil (179 views)
2013-05-11 20:09:57
Complex number cookbook
by Roquen
2013-04-24 03:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 07:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 07:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 07:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 08:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 07:17:38

Java Data structures
by Roquen
2013-03-29 04:21:12

Topic Request
by kutucuk
2013-03-22 12:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.081 seconds with 20 queries.