/* ItoB.java by Mark D. LaDue */ /* June 24, 1997 */ /* Copyright (c) 1997 Mark D. LaDue You may study, use, modify, and distribute this example for any purpose. This example is provided WITHOUT WARRANTY either expressed or implied. */ /* This Java application reads an input file of integers and converts each integer to its corresponding byte. In the input file each integer must appear on a separate line, and there should be no lines containing entities other than integers. When the input file is an array of integers obtained by applying the application BtoI.java to a Java class file, the resulting output is the original class file. When combined with the output of the "javap" utility, the application Inspector.java, and the application BtoI.java, this allows one to hack code in class files and convert the results back to the class file format. While decompilers and disassemblers allow one to do this in a much more elegant fashion, such tools are not always reliable and effective. */ import java.io.*; class ItoB { public static void main(String[] argv) { // How on earth do I use this thing? if (argv.length != 2) { System.out.println("Try \"java ItoB input_file output_file\""); System.exit(1); } try { // Open the specified input file for reading DataInputStream inner = new DataInputStream(new FileInputStream(argv[0])); // Open the specified output file for writing PrintStream outer = new PrintStream(new FileOutputStream(argv[1])); //Read each line as a string, convert it to an integer, and write it as a byte String str; while ((str=inner.readLine()) != null) { int intro = Integer.parseInt(str); outer.write(intro); } inner.close(); outer.close(); } catch (IOException ioe) {} } }