Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/audio/ContinuousAudioDataStream.java
38829 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.audio;2627/**28* Create a continuous audio stream. This wraps a stream29* around an AudioData object, the stream is restarted30* at the beginning everytime the end is reached, thus31* creating continuous sound.<p>32* For example:33* <pre>34* AudioData data = AudioData.getAudioData(url);35* ContinuousAudioDataStream audiostream = new ContinuousAudioDataStream(data);36* AudioPlayer.player.start(audiostream);37* </pre>38*39* @see AudioPlayer40* @see AudioData41* @author Arthur van Hoff42*/4344public final class ContinuousAudioDataStream extends AudioDataStream {454647/**48* Create a continuous stream of audio.49*/50public ContinuousAudioDataStream(AudioData data) {5152super(data);53}545556public int read() {5758int i = super.read();5960if (i == -1) {61reset();62i = super.read();63}6465return i;66}676869public int read(byte ab[], int i1, int j) {7071int k;7273for (k = 0; k < j; ) {74int i2 = super.read(ab, i1 + k, j - k);75if (i2 >= 0) k += i2;76else reset();77}7879return k;80}81}828384