ReadInt.java revision 2362
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync/*
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync *
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync * This code is free software; you can redistribute it and/or modify it
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync * under the terms of the GNU General Public License version 2 only, as
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * published by the Free Software Foundation. Oracle designates this
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * particular file as subject to the "Classpath" exception as provided
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * by Oracle in the LICENSE file that accompanied this code.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * This code is distributed in the hope that it will be useful, but WITHOUT
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * version 2 for more details (a copy is included in the LICENSE file that
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * accompanied this code).
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You should have received a copy of the GNU General Public License version
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * 2 along with this work; if not, write to the Free Software Foundation,
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * or visit www.oracle.com if you need additional information or have any
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * questions.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync */
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync/* @test
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync @summary Test RiffReader readInt method */
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync
7db630a55be9d955c8ac125da609b304cbcc6010vboxsyncimport java.io.File;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsyncimport java.io.FileInputStream;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync
7db630a55be9d955c8ac125da609b304cbcc6010vboxsyncimport javax.sound.sampled.*;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync
4db428018b0a098eec7231fc88b688d70b814933vboxsyncimport com.sun.media.sound.*;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync
bd53394d08b77c8294f14b32dd26aa4670f888eevboxsyncpublic class ReadInt {
bd53394d08b77c8294f14b32dd26aa4670f888eevboxsync
bd53394d08b77c8294f14b32dd26aa4670f888eevboxsync private static void assertEquals(Object a, Object b) throws Exception
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync {
4db428018b0a098eec7231fc88b688d70b814933vboxsync if(!a.equals(b))
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync throw new RuntimeException("assertEquals fails!");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync }
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync public static void main(String[] args) throws Exception {
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync RIFFWriter writer = null;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync RIFFReader reader = null;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync File tempfile = File.createTempFile("test",".riff");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync try
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync {
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync writer = new RIFFWriter(tempfile, "TEST");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync RIFFWriter chunk = writer.writeChunk("TSCH");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync chunk.writeInt(133);
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync writer.close();
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync writer = null;
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync FileInputStream fis = new FileInputStream(tempfile);
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync reader = new RIFFReader(fis);
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync assertEquals(reader.getFormat(), "RIFF");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync assertEquals(reader.getType(), "TEST");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync RIFFReader readchunk = reader.nextChunk();
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync assertEquals(readchunk.getFormat(), "TSCH");
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync assertEquals(reader.readInt(), 133);
7db630a55be9d955c8ac125da609b304cbcc6010vboxsync fis.close();
reader = null;
}
finally
{
if(writer != null)
writer.close();
if(reader != null)
reader.close();
if(tempfile.exists())
if(!tempfile.delete())
tempfile.deleteOnExit();
}
}
}