jdk/src/share/classes/javax/sound/sampled/DataLine.java
changeset 19368 5d7565f5978c
parent 5506 202f599c92aa
child 23010 6dadb192ad81
equal deleted inserted replaced
19367:0589099a8188 19368:5d7565f5978c
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package javax.sound.sampled;
    26 package javax.sound.sampled;
       
    27 
       
    28 import java.util.Arrays;
    27 
    29 
    28 /**
    30 /**
    29  * <code>DataLine</code> adds media-related functionality to its
    31  * <code>DataLine</code> adds media-related functionality to its
    30  * superinterface, <code>{@link Line}</code>.  This functionality includes
    32  * superinterface, <code>{@link Line}</code>.  This functionality includes
    31  * transport-control methods that start, stop, drain, and flush
    33  * transport-control methods that start, stop, drain, and flush
   280      * @author Kara Kytle
   282      * @author Kara Kytle
   281      * @since 1.3
   283      * @since 1.3
   282      */
   284      */
   283     public static class Info extends Line.Info {
   285     public static class Info extends Line.Info {
   284 
   286 
   285         private AudioFormat[] formats;
   287         private final AudioFormat[] formats;
   286         private int minBufferSize;
   288         private final int minBufferSize;
   287         private int maxBufferSize;
   289         private final int maxBufferSize;
   288 
   290 
   289         /**
   291         /**
   290          * Constructs a data line's info object from the specified information,
   292          * Constructs a data line's info object from the specified information,
   291          * which includes a set of supported audio formats and a range for the buffer size.
   293          * which includes a set of supported audio formats and a range for the buffer size.
   292          * This constructor is typically used by mixer implementations
   294          * This constructor is typically used by mixer implementations
   302             super(lineClass);
   304             super(lineClass);
   303 
   305 
   304             if (formats == null) {
   306             if (formats == null) {
   305                 this.formats = new AudioFormat[0];
   307                 this.formats = new AudioFormat[0];
   306             } else {
   308             } else {
   307                 this.formats = formats;
   309                 this.formats = Arrays.copyOf(formats, formats.length);
   308             }
   310             }
   309 
   311 
   310             this.minBufferSize = minBufferSize;
   312             this.minBufferSize = minBufferSize;
   311             this.maxBufferSize = maxBufferSize;
   313             this.maxBufferSize = maxBufferSize;
   312         }
   314         }
   327             super(lineClass);
   329             super(lineClass);
   328 
   330 
   329             if (format == null) {
   331             if (format == null) {
   330                 this.formats = new AudioFormat[0];
   332                 this.formats = new AudioFormat[0];
   331             } else {
   333             } else {
   332                 AudioFormat[] formats = { format };
   334                 this.formats = new AudioFormat[]{format};
   333                 this.formats = formats;
       
   334             }
   335             }
   335 
   336 
   336             this.minBufferSize = bufferSize;
   337             this.minBufferSize = bufferSize;
   337             this.maxBufferSize = bufferSize;
   338             this.maxBufferSize = bufferSize;
   338         }
   339         }
   371          *
   372          *
   372          * @return a set of supported audio formats.
   373          * @return a set of supported audio formats.
   373          * @see #isFormatSupported(AudioFormat)
   374          * @see #isFormatSupported(AudioFormat)
   374          */
   375          */
   375         public AudioFormat[] getFormats() {
   376         public AudioFormat[] getFormats() {
   376 
   377             return Arrays.copyOf(formats, formats.length);
   377             AudioFormat[] returnedArray = new AudioFormat[formats.length];
       
   378             System.arraycopy(formats, 0, returnedArray, 0, formats.length);
       
   379             return returnedArray;
       
   380         }
   378         }
   381 
   379 
   382         /**
   380         /**
   383          * Indicates whether this data line supports a particular audio format.
   381          * Indicates whether this data line supports a particular audio format.
   384          * The default implementation of this method simply returns <code>true</code> if
   382          * The default implementation of this method simply returns <code>true</code> if