package sf;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class Util {
static byte XOR = 0X12;
static MappedByteBuffer buffer=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
encode();
}
@SuppressWarnings("resource")
public static void encode() {
try {
File file = new File("D:/VID_20140728_163015.3gp");
boolean fs= file.exists();
boolean fss = file.isFile();
System.out.println(fs);
System.out.println(fss);
if(file.exists()&&file.isFile()){
buffer=new RandomAccessFile("D:/VID_20140728_163015.3gp","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 10);
int sum=0;
long t1=System.currentTimeMillis();
for(int i=0;i<10;i++){
byte sd = 'a';
byte src= (byte) (buffer.get(i)+sd);
System.out.println("before :"+src);
src = (byte)(src^XOR);
System.out.println("after :"+src);
buffer.put(i,src);//修改Buffer中映射的字节的值
//new RandomAccessFile(file, mode)
}
buffer.force();
buffer.clear();
long t=System.currentTimeMillis()-t1;
System.out.println("sum:"+sum+" time:"+t);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
只能加密头文件信息,也就是
buffer=new RandomAccessFile("D:/VID_20140728_163015.3gp","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 10);
就是最后两位只能是0到 long(xxx) 就是加密头信息视频不能被视频,不能打开,如果最后两位写成long position long(xxx)
比如:
<pre name="code" class="java">buffer=new RandomAccessFile("D:/VID_20140728_163015.3gp","rw").getChannel().map(FileChannel.MapMode.READ_WRITE, 23223, 1024);
那么视频这一段将会出现小片的模糊,但是还是可以打开的。