Need to update. It commits a file with one file. You should look at the following sequence in the zip file {0, 0x08, 0x08, 0x08, 0} and replace it with {0, 0x08, 0x00, 0x08, 0}
private static void replaceWrongZipByte(File zip) throws IOException { RandomAccessFile r = new RandomAccessFile(zip, "rw"); int flag = Integer.parseInt("00001000", 2);
Update Version:
The following code removes all invalid bytes in a ZIP. KMPMatch.java is easy to find on google
public static void replaceWrongBytesInZip(File zip) throws IOException { byte find[] = new byte[] { 0, 0x08, 0x08, 0x08, 0 }; int index; while( (index = indexOfBytesInFile(zip,find)) != -1) { replaceWrongZipByte(zip, index + 2); } } private static int indexOfBytesInFile(File file,byte find[]) throws IOException { byte fileContent[] = new byte[(int) file.length()]; FileInputStream fin = new FileInputStream(file); fin.read(fileContent); fin.close(); return KMPMatch.indexOf(fileContent, find); } private static void replaceWrongZipByte(File zip, int wrongByteIndex) throws IOException { RandomAccessFile r = new RandomAccessFile(zip, "rw"); int flag = Integer.parseInt("00001000", 2); r.seek(wrongByteIndex); int realFlags = r.read(); if( (realFlags & flag) > 0) {
source share