问题
I am implementing a video steganography for my project. I came across the algorithm from here . i have tried and tested the code and the embedding part is working fine. But i encountered a problem with the readByte
which is the last method in the VideoSteganography
class. The method Gives ArrayIndexOutOfBoundsException
. Below is the method.
I pass the parameters as
String fname = jTextField3.getText();
File fil = new File(fname);
String password = "123456";
SteganoInformation cls = new SteganoInformation(fil);
VideoSteganography.retrieveFile(cls, password, true);
and the method is
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);
.......
}
Notice the method readBytes above, it throws the exception and its written as below
private static void readBytes(byte[] bytes)
{
int size= bytes.length;
for(int i=0; i<size ; i++)
{
bytes[i]= byteArrayIn[inputOutputMarker];
inputOutputMarker++;
}
}
回答1:
The problem here is "byteArrayIn[inputOutputMarker]", Recheck the value of inputOutputMarker by and the range of values it could have .
回答2:
@Mazen Wadi , thanks for your reply. But i figured what triggered the very exception and would like to share in case some one would encounter the same problem. From the two classes "VideoSteganography class" and "SteganoInformation class" , there are two loops from the methods retrieveBytes() from both classes. Change loops to the one below and make sure the loop size tally in both classes. Note: change j=6 from retrieveBytes method of the two classes and your problem is solved.
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;
}
}
来源:https://stackoverflow.com/questions/15948815/video-steganography-in-java