public static void main(String[] args) throws Exception { RIFFWriter writer = null; RIFFReader reader = null; File tempfile = File.createTempFile("test", ".riff"); try { writer = new RIFFWriter(tempfile, "TEST"); RIFFWriter chunk = writer.writeChunk("TSCH"); chunk.writeByte((byte) 33); writer.close(); writer = null; FileInputStream fis = new FileInputStream(tempfile); reader = new RIFFReader(fis); assertEquals(reader.getFormat(), "RIFF"); assertEquals(reader.getType(), "TEST"); RIFFReader readchunk = reader.nextChunk(); assertEquals(readchunk.getFormat(), "TSCH"); assertEquals((int) reader.readByte(), 33); fis.close(); reader = null; } finally { if (writer != null) writer.close(); if (reader != null) reader.close(); if (tempfile.exists()) if (!tempfile.delete()) tempfile.deleteOnExit(); } }