1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
458 }
459 }
460
461 AudioFormat[] localFormats = getFormats();
462
463 if (localFormats != null) {
464
465 for (int i = 0; i < localFormats.length; i++) {
466 if (! (localFormats[i] == null) ) {
467 if (! (dataLineInfo.isFormatSupported(localFormats[i])) ) {
468 return false;
469 }
470 }
471 }
472 }
473
474 return true;
475 }
476
477 /**
478 * Obtains a textual description of the data line info.
479 *
480 * @return a string description
481 */
482 @Override
483 public String toString() {
484
485 StringBuilder sb = new StringBuilder();
486
487 if ( (formats.length == 1) && (formats[0] != null) ) {
488 sb.append(" supporting format " + formats[0]);
489 } else if (getFormats().length > 1) {
490 sb.append(" supporting " + getFormats().length + " audio formats");
491 }
492
493 if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (maxBufferSize != AudioSystem.NOT_SPECIFIED) ) {
494 sb.append(", and buffers of " + minBufferSize + " to " + maxBufferSize + " bytes");
495 } else if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (minBufferSize > 0) ) {
496 sb.append(", and buffers of at least " + minBufferSize + " bytes");
497 } else if (maxBufferSize != AudioSystem.NOT_SPECIFIED) {
498 sb.append(", and buffers of up to " + minBufferSize + " bytes");
499 }
500
501 return new String(super.toString() + sb);
502 }
503 }
504 }
|
1 /*
2 * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
458 }
459 }
460
461 AudioFormat[] localFormats = getFormats();
462
463 if (localFormats != null) {
464
465 for (int i = 0; i < localFormats.length; i++) {
466 if (! (localFormats[i] == null) ) {
467 if (! (dataLineInfo.isFormatSupported(localFormats[i])) ) {
468 return false;
469 }
470 }
471 }
472 }
473
474 return true;
475 }
476
477 /**
478 * Returns a string representation of the info object.
479 *
480 * @return a string representation of the info object
481 */
482 @Override
483 public String toString() {
484 String format = "";
485 AudioFormat[] formats = getFormats();
486 if (formats.length == 1 && formats[0] != null) {
487 format = " supporting format " + formats[0];
488 } else if (formats.length > 1) {
489 format = " supporting " + formats.length + " audio formats";
490 }
491
492 String buffers = "";
493 int min = getMinBufferSize();
494 int max = getMaxBufferSize();
495 if (min != AudioSystem.NOT_SPECIFIED
496 && max != AudioSystem.NOT_SPECIFIED) {
497 buffers = ", and buffers of " + min + " to " + max + " bytes";
498 } else if (min > 0) {
499 buffers = ", and buffers of at least " + min + " bytes";
500 } else if (max != AudioSystem.NOT_SPECIFIED) {
501 buffers = ", and buffers of up to " + max + " bytes";
502 }
503
504 return String.format("%s%s%s", super.toString(), format, buffers);
505 }
506 }
507 }
|