2013-04-11 45 views
0

我正在为我的项目实施视频隐写术。我遇到了here的算法。我已经尝试和测试了代码,并且嵌入部分工作正常。但是我遇到了readByte这是VideoSteganography类中最后一种方法的问题。该方法给出ArrayIndexOutOfBoundsException。以下是方法。java中的视频隐写术

我传递参数如

String fname = jTextField3.getText(); 
    File fil = new File(fname); 
    String password = "123456"; 

    SteganoInformation cls = new SteganoInformation(fil); 

    VideoSteganography.retrieveFile(cls, password, true); 

,并且该方法是

public static boolean retrieveFile(SteganoInformation info, String password, boolean overwrite) 
    { 
     File dataFile= null; 
     features= info.getFeatures(); 
     try 
     { 
      masterFile= info.getFile(); 
      byteArrayIn= new byte[(int) masterFile.length()]; 

      DataInputStream in= new DataInputStream(new FileInputStream(masterFile)); 
      in.read(byteArrayIn, 0, (int)masterFile.length()); 
      in.close(); 
      messageSize= info.getDataLength(); 
      byte[] fileArray= new byte[messageSize]; 
      inputOutputMarker= info.getInputMarker(); 
      readBytes(fileArray); 
....... 
} 

注意上面的方法的ReadBytes,它引发异常和其如下面书面

private static void readBytes(byte[] bytes) 
    { 
     int size= bytes.length; 

     for(int i=0; i<size ; i++) 
     { 


      bytes[i]= byteArrayIn[inputOutputMarker]; 
      inputOutputMarker++; 



     } 
    } 

回答

0

@Mazen Wadi,谢谢你的回复。但我想到是什么引发了这个例外,并希望分享一些可能会遇到同样问题的情况。从“VideoSteganography类”和“SteganoInformation类”两个类中,两个类的方法retrieveBytes()有两个循环。将循环更改为下面的循环,并确保两个类中的循环大小相同。注意:从两个类的retrieveBytes方法改变j = 6,你的问题就解决了。

private static void retrieveBytes(byte[] bytes) 
     { 
      int size= bytes.length; 

      for(int i=0; i< size; i++) 
      { 
       byte1= 0; 
       for(int j=6; j>=0; j-=2) 
       { 
        byte2= byteArrayIn[inputOutputMarker]; 
        inputOutputMarker++; 

        byte2&= 0x03; 
        byte2<<= j; 
        byte1|= byte2; 
       } 
       bytes[i]= byte1; 
      } 
     } 
0

的这里的问题是“byteArrayIn [inputOutputMarker]”,请重新检查inputOutputMarker的值和va的范围它可能有 。