--- old/src/java.desktop/share/classes/com/sun/media/sound/AuFileReader.java 2015-07-20 23:26:25.000000000 +0300 +++ new/src/java.desktop/share/classes/com/sun/media/sound/AuFileReader.java 2015-07-20 23:26:24.000000000 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,21 +25,15 @@ package com.sun.media.sound; -import java.io.BufferedInputStream; import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; - /** * AU file reader. * @@ -49,33 +43,10 @@ */ public final class AuFileReader extends SunFileReader { - // METHODS TO IMPLEMENT AudioFileReader - - /** - * Obtains the audio file format of the input stream provided. The stream must - * point to valid audio file data. In general, audio file providers may - * need to read some data from the stream before determining whether they - * support it. These parsers must - * be able to mark the stream, read enough data to determine whether they - * support the stream, and, if not, reset the stream's read pointer to its original - * position. If the input stream does not support this, this method may fail - * with an IOException. - * @param stream the input stream from which file format information should be - * extracted - * @return an AudioFileFormat object describing the audio file format - * @throws UnsupportedAudioFileException if the stream does not point to valid audio - * file data recognized by the system - * @throws IOException if an I/O exception occurs - * @see InputStream#markSupported - * @see InputStream#mark - */ - public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException { - - AudioFormat format = null; - AuFileFormat fileFormat = null; - int maxReadLength = 28; + @Override + public AudioFileFormat getAudioFileFormatImpl(final InputStream stream) + throws UnsupportedAudioFileException, IOException { boolean bigendian = false; - int magic = -1; int headerSize = -1; int dataSize = -1; int encoding_local = -1; @@ -90,15 +61,12 @@ DataInputStream dis = new DataInputStream( stream ); - dis.mark(maxReadLength); - - magic = dis.readInt(); + final int magic = dis.readInt(); nread += 4; if (! (magic == AuFileFormat.AU_SUN_MAGIC) || (magic == AuFileFormat.AU_DEC_MAGIC) || (magic == AuFileFormat.AU_SUN_INV_MAGIC) || (magic == AuFileFormat.AU_DEC_INV_MAGIC) ) { - // not AU, reset the stream, place into exception, throw exception - dis.reset(); + // not AU, throw exception throw new UnsupportedAudioFileException("not an AU file"); } @@ -112,7 +80,6 @@ sampleRate = (bigendian==true ? dis.readInt() : rllong(dis) ); nread += 4; channels = (bigendian==true ? dis.readInt() : rllong(dis) ); nread += 4; if (channels <= 0) { - dis.reset(); throw new UnsupportedAudioFileException("Invalid number of channels"); } @@ -172,7 +139,6 @@ */ default: // unsupported filetype, throw exception - dis.reset(); throw new UnsupportedAudioFileException("not a valid AU file"); } @@ -184,189 +150,13 @@ //$$fb 2003-10-20: fix for 4940459: AudioInputStream.getFrameLength() returns 0 instead of NOT_SPECIFIED length = dataSize / frameSize; } - - format = new AudioFormat( encoding, (float)sampleRate, sampleSizeInBits, - channels, frameSize, (float)frameRate, bigendian); - - fileFormat = new AuFileFormat( AudioFileFormat.Type.AU, dataSize+headerSize, - format, length); - - dis.reset(); // Throws IOException - return fileFormat; - - } - - - /** - * Obtains the audio file format of the URL provided. The URL must - * point to valid audio file data. - * @param url the URL from which file format information should be - * extracted - * @return an AudioFileFormat object describing the audio file format - * @throws UnsupportedAudioFileException if the URL does not point to valid audio - * file data recognized by the system - * @throws IOException if an I/O exception occurs - */ - public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException { - - InputStream urlStream = null; - BufferedInputStream bis = null; - AudioFileFormat fileFormat = null; - AudioFormat format = null; - - urlStream = url.openStream(); // throws IOException - - try { - bis = new BufferedInputStream( urlStream, bisBufferSize ); - - fileFormat = getAudioFileFormat( bis ); // throws UnsupportedAudioFileException - } finally { - urlStream.close(); - } - - return fileFormat; - } - - - /** - * Obtains the audio file format of the File provided. The File must - * point to valid audio file data. - * @param file the File from which file format information should be - * extracted - * @return an AudioFileFormat object describing the audio file format - * @throws UnsupportedAudioFileException if the File does not point to valid audio - * file data recognized by the system - * @throws IOException if an I/O exception occurs - */ - public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { - - FileInputStream fis = null; - BufferedInputStream bis = null; - AudioFileFormat fileFormat = null; - AudioFormat format = null; - - fis = new FileInputStream( file ); // throws IOException - // part of fix for 4325421 - try { - bis = new BufferedInputStream( fis, bisBufferSize ); - fileFormat = getAudioFileFormat( bis ); // throws UnsupportedAudioFileException - } finally { - fis.close(); - } - - return fileFormat; - } - - - /** - * Obtains an audio stream from the input stream provided. The stream must - * point to valid audio file data. In general, audio file providers may - * need to read some data from the stream before determining whether they - * support it. These parsers must - * be able to mark the stream, read enough data to determine whether they - * support the stream, and, if not, reset the stream's read pointer to its original - * position. If the input stream does not support this, this method may fail - * with an IOException. - * @param stream the input stream from which the AudioInputStream should be - * constructed - * @return an AudioInputStream object based on the audio file data contained - * in the input stream. - * @throws UnsupportedAudioFileException if the stream does not point to valid audio - * file data recognized by the system - * @throws IOException if an I/O exception occurs - * @see InputStream#markSupported - * @see InputStream#mark - */ - public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException { - - DataInputStream dis = null; - int headerSize; - AudioFileFormat fileFormat = null; - AudioFormat format = null; - - - fileFormat = getAudioFileFormat( stream ); // throws UnsupportedAudioFileException, IOException - - // if we passed this call, we have an AU file. - - format = fileFormat.getFormat(); - - dis = new DataInputStream(stream); - // now seek past the header - - dis.readInt(); // magic - headerSize = (format.isBigEndian()==true ? dis.readInt() : rllong(dis) ); - dis.skipBytes( headerSize - 8 ); - - - // we've got everything, and the stream should be at the - // beginning of the data chunk, so return an AudioInputStream. - - return new AudioInputStream(dis, format, fileFormat.getFrameLength()); - } - - - /** - * Obtains an audio stream from the URL provided. The URL must - * point to valid audio file data. - * @param url the URL for which the AudioInputStream should be - * constructed - * @return an AudioInputStream object based on the audio file data pointed - * to by the URL - * @throws UnsupportedAudioFileException if the URL does not point to valid audio - * file data recognized by the system - * @throws IOException if an I/O exception occurs - */ - public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { - - InputStream urlStream = null; - BufferedInputStream bis = null; - AudioFileFormat fileFormat = null; - - urlStream = url.openStream(); // throws IOException - AudioInputStream result = null; - try { - bis = new BufferedInputStream( urlStream, bisBufferSize ); - result = getAudioInputStream( (InputStream)bis ); - } finally { - if (result == null) { - urlStream.close(); - } - } - return result; - } - - - /** - * Obtains an audio stream from the File provided. The File must - * point to valid audio file data. - * @param file the File for which the AudioInputStream should be - * constructed - * @return an AudioInputStream object based on the audio file data pointed - * to by the File - * @throws UnsupportedAudioFileException if the File does not point to valid audio - * file data recognized by the system - * @throws IOException if an I/O exception occurs - */ - public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException { - - FileInputStream fis = null; - BufferedInputStream bis = null; - AudioFileFormat fileFormat = null; - - fis = new FileInputStream( file ); // throws IOException - AudioInputStream result = null; - // part of fix for 4325421 - try { - bis = new BufferedInputStream( fis, bisBufferSize ); - result = getAudioInputStream( (InputStream)bis ); - } finally { - if (result == null) { - fis.close(); - } - } - - return result; + dis.skipBytes(headerSize - nread); + AudioFormat format = new AudioFormat(encoding, sampleRate, + sampleSizeInBits, channels, + frameSize, (float) frameRate, + bigendian); + return new AuFileFormat(AudioFileFormat.Type.AU, dataSize + headerSize, + format, length); } }