public static File getSparseBinarySVDLIBCFile() throws Exception { File f = File.createTempFile("unit-test", ".dat"); DataOutputStream pw = new DataOutputStream(new FileOutputStream(f)); pw.writeInt(3); pw.writeInt(3); pw.writeInt(6); pw.writeInt(2); pw.writeInt(0); pw.writeFloat(2.3f); pw.writeInt(2); pw.writeFloat(3.8f); pw.writeInt(1); pw.writeInt(1); pw.writeFloat(1.3f); pw.writeInt(3); pw.writeInt(0); pw.writeFloat(4.2f); pw.writeInt(1); pw.writeFloat(2.2f); pw.writeInt(2); pw.writeFloat(0.5f); pw.close(); return f; }
@Test public void dataRoundTrip() throws IOException { dos.writeUTF("Hello, world!"); dos.writeInt(0xCAFEBABE); dos.writeUTF("Over & out."); dos.close(); // aos.close(); // important? byte[] bs = bos.toByteArray(); if (verbose) { for (int i = 0; i < bs.length; i++) { System.out.printf("%02x ", bs[i]); if (i % 16 == 15) System.out.println(); } System.out.println(); } PPMModel pi = new PPMModel(4); ByteArrayInputStream bis = new ByteArrayInputStream(bs); ArithCodeInputStream ais = new ArithCodeInputStream(bis, pi); DataInputStream dis = new DataInputStream(ais); String s1 = dis.readUTF(); assert s1.equals("Hello, world!") : s1; int i1 = dis.readInt(); assert 0xCAFEBABE == i1 : i1; String s2 = dis.readUTF(); assert s2.equals("Over & out.") : s2; int i2 = dis.read(); assert -1 == i2 : i2; }