ReadUnsignedInt.java revision 12278:6fb5ee377870
1153187Spjd/* 2153187Spjd * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. 3153187Spjd * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4153187Spjd * 5153187Spjd * This code is free software; you can redistribute it and/or modify it 6153187Spjd * under the terms of the GNU General Public License version 2 only, as 7153187Spjd * published by the Free Software Foundation. 8153187Spjd * 9153187Spjd * This code is distributed in the hope that it will be useful, but WITHOUT 10153187Spjd * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11153187Spjd * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12153187Spjd * version 2 for more details (a copy is included in the LICENSE file that 13153187Spjd * accompanied this code). 14153187Spjd * 15153187Spjd * You should have received a copy of the GNU General Public License version 16153187Spjd * 2 along with this work; if not, write to the Free Software Foundation, 17153187Spjd * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18153187Spjd * 19153187Spjd * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20153187Spjd * or visit www.oracle.com if you need additional information or have any 21153187Spjd * questions. 22153187Spjd */ 23153187Spjd 24153187Spjd/* @test 25153187Spjd @summary Test RiffReader readUnsignedInt method 26153187Spjd @modules java.desktop/com.sun.media.sound 27153187Spjd*/ 28153187Spjd 29153187Spjdimport java.io.File; 30153187Spjdimport java.io.FileInputStream; 31153187Spjd 32153187Spjdimport javax.sound.sampled.*; 33153187Spjd 34153187Spjdimport com.sun.media.sound.*; 35153187Spjd 36153187Spjdpublic class ReadUnsignedInt { 37153187Spjd 38153187Spjd private static void assertEquals(Object a, Object b) throws Exception 39153187Spjd { 40153187Spjd if(!a.equals(b)) 41153187Spjd throw new RuntimeException("assertEquals fails!"); 42153187Spjd } 43153187Spjd 44 public static void main(String[] args) throws Exception { 45 RIFFWriter writer = null; 46 RIFFReader reader = null; 47 File tempfile = File.createTempFile("test",".riff"); 48 try 49 { 50 writer = new RIFFWriter(tempfile, "TEST"); 51 RIFFWriter chunk = writer.writeChunk("TSCH"); 52 chunk.writeUnsignedInt(55377); 53 writer.close(); 54 writer = null; 55 FileInputStream fis = new FileInputStream(tempfile); 56 reader = new RIFFReader(fis); 57 assertEquals(reader.getFormat(), "RIFF"); 58 assertEquals(reader.getType(), "TEST"); 59 RIFFReader readchunk = reader.nextChunk(); 60 assertEquals(readchunk.getFormat(), "TSCH"); 61 assertEquals(reader.readUnsignedInt(), 55377L); 62 fis.close(); 63 reader = null; 64 65 66 } 67 finally 68 { 69 if(writer != null) 70 writer.close(); 71 if(reader != null) 72 reader.close(); 73 74 if(tempfile.exists()) 75 if(!tempfile.delete()) 76 tempfile.deleteOnExit(); 77 } 78 } 79} 80