-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post-process classes from 1.6 to 1.4 via antrun
I don't want to make a Maven Mojo out of it, because it will also need to work with Gradle. So a standalone Java tool is the right way to go.
- Loading branch information
1 parent
082e09a
commit 72a2b0d
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.FilenameFilter; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class Java6to4 { | ||
|
||
private static byte[] transform(InputStream classfile, ByteArrayOutputStream buffer) throws IOException { | ||
buffer.reset(); | ||
int nRead; | ||
byte[] data = new byte[1024]; | ||
while ((nRead = classfile.read(data, 0, data.length)) != -1) { | ||
buffer.write(data, 0, nRead); | ||
} | ||
byte[] arr = buffer.toByteArray(); | ||
// patch byte 8 | ||
arr[7] = 48; // <- Java 1.4 | ||
return arr; | ||
} | ||
|
||
private static void walk(File root, ByteArrayOutputStream buffer) throws IOException { | ||
File[] list = root.listFiles(new FilenameFilter() { | ||
public boolean accept(File dir, String name) { | ||
File f = new File(dir, name); | ||
return f.isDirectory() || name.endsWith(".class"); | ||
} | ||
}); | ||
if (list == null) | ||
return; | ||
for (int i = 0; i < list.length; i++) { | ||
File f = list[i]; | ||
if (f.isDirectory()) { | ||
walk(f, buffer); | ||
} else { | ||
FileInputStream fis = new FileInputStream(f); | ||
byte[] transformed = transform(fis, buffer); | ||
fis.close(); | ||
FileOutputStream fos = new FileOutputStream(f); | ||
fos.write(transformed); | ||
fos.close(); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | ||
walk(new File(args[0]), buffer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters