2013-04-11 48 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的範圍它可能有 。