提交 27d3451a 编写于 作者: S serb

8005980: [findbugs] More com.sun.media.sound.* warnings

Reviewed-by: art, prr
上级 a3ba31ae
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.util.Arrays;
import javax.sound.sampled.*; import javax.sound.sampled.*;
/** /**
...@@ -46,11 +48,11 @@ public final class DataPusher implements Runnable { ...@@ -46,11 +48,11 @@ public final class DataPusher implements Runnable {
private final AudioFormat format; private final AudioFormat format;
// stream as source data // stream as source data
private AudioInputStream ais = null; private final AudioInputStream ais;
// byte array as source data // byte array as source data
private byte[] audioData = null; private final byte[] audioData;
private int audioDataByteLength = 0; private final int audioDataByteLength;
private int pos; private int pos;
private int newPos = -1; private int newPos = -1;
private boolean looping; private boolean looping;
...@@ -67,16 +69,22 @@ public final class DataPusher implements Runnable { ...@@ -67,16 +69,22 @@ public final class DataPusher implements Runnable {
private final int BUFFER_SIZE = 16384; private final int BUFFER_SIZE = 16384;
public DataPusher(SourceDataLine sourceLine, AudioFormat format, byte[] audioData, int byteLength) { public DataPusher(SourceDataLine sourceLine, AudioFormat format, byte[] audioData, int byteLength) {
this.audioData = audioData; this(sourceLine, format, null, audioData, byteLength);
this.audioDataByteLength = byteLength;
this.format = format;
this.source = sourceLine;
} }
public DataPusher(SourceDataLine sourceLine, AudioInputStream ais) { public DataPusher(SourceDataLine sourceLine, AudioInputStream ais) {
this(sourceLine, ais.getFormat(), ais, null, 0);
}
private DataPusher(final SourceDataLine source, final AudioFormat format,
final AudioInputStream ais, final byte[] audioData,
final int audioDataByteLength) {
this.source = source;
this.format = format;
this.ais = ais; this.ais = ais;
this.format = ais.getFormat(); this.audioDataByteLength = audioDataByteLength;
this.source = sourceLine; this.audioData = audioData == null ? null : Arrays.copyOf(audioData,
audioData.length);
} }
public synchronized void start() { public synchronized void start() {
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
*/ */
package com.sun.media.sound; package com.sun.media.sound;
import java.util.Arrays;
/** /**
* A standard director who chooses performers * A standard director who chooses performers
* by there keyfrom,keyto,velfrom,velto properties. * by there keyfrom,keyto,velfrom,velto properties.
...@@ -32,17 +34,16 @@ package com.sun.media.sound; ...@@ -32,17 +34,16 @@ package com.sun.media.sound;
*/ */
public final class ModelStandardDirector implements ModelDirector { public final class ModelStandardDirector implements ModelDirector {
ModelPerformer[] performers; private final ModelPerformer[] performers;
ModelDirectedPlayer player; private final ModelDirectedPlayer player;
boolean noteOnUsed = false; private boolean noteOnUsed = false;
boolean noteOffUsed = false; private boolean noteOffUsed = false;
public ModelStandardDirector(ModelPerformer[] performers, public ModelStandardDirector(final ModelPerformer[] performers,
ModelDirectedPlayer player) { final ModelDirectedPlayer player) {
this.performers = performers; this.performers = Arrays.copyOf(performers, performers.length);
this.player = player; this.player = player;
for (int i = 0; i < performers.length; i++) { for (final ModelPerformer p : this.performers) {
ModelPerformer p = performers[i];
if (p.isReleaseTriggered()) { if (p.isReleaseTriggered()) {
noteOffUsed = true; noteOffUsed = true;
} else { } else {
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
*/ */
package com.sun.media.sound; package com.sun.media.sound;
import java.util.Arrays;
/** /**
* A standard indexed director who chooses performers * A standard indexed director who chooses performers
* by there keyfrom,keyto,velfrom,velto properties. * by there keyfrom,keyto,velfrom,velto properties.
...@@ -32,22 +34,21 @@ package com.sun.media.sound; ...@@ -32,22 +34,21 @@ package com.sun.media.sound;
*/ */
public final class ModelStandardIndexedDirector implements ModelDirector { public final class ModelStandardIndexedDirector implements ModelDirector {
ModelPerformer[] performers; private final ModelPerformer[] performers;
ModelDirectedPlayer player; private final ModelDirectedPlayer player;
boolean noteOnUsed = false; private boolean noteOnUsed = false;
boolean noteOffUsed = false; private boolean noteOffUsed = false;
// Variables needed for index // Variables needed for index
byte[][] trantables; private byte[][] trantables;
int[] counters; private int[] counters;
int[][] mat; private int[][] mat;
public ModelStandardIndexedDirector(ModelPerformer[] performers, public ModelStandardIndexedDirector(final ModelPerformer[] performers,
ModelDirectedPlayer player) { final ModelDirectedPlayer player) {
this.performers = performers; this.performers = Arrays.copyOf(performers, performers.length);
this.player = player; this.player = player;
for (int i = 0; i < performers.length; i++) { for (final ModelPerformer p : this.performers) {
ModelPerformer p = performers[i];
if (p.isReleaseTriggered()) { if (p.isReleaseTriggered()) {
noteOffUsed = true; noteOffUsed = true;
} else { } else {
......
...@@ -38,7 +38,7 @@ import javax.sound.sampled.LineEvent; ...@@ -38,7 +38,7 @@ import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.LineUnavailableException;
/** /**
* Clip implemention for the SoftMixingMixer. * Clip implementation for the SoftMixingMixer.
* *
* @author Karl Helgason * @author Karl Helgason
*/ */
...@@ -357,7 +357,9 @@ public final class SoftMixingClip extends SoftMixingDataLine implements Clip { ...@@ -357,7 +357,9 @@ public final class SoftMixingClip extends SoftMixingDataLine implements Clip {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Buffer size does not represent an integral number of sample frames!"); "Buffer size does not represent an integral number of sample frames!");
this.data = data; if (data != null) {
this.data = Arrays.copyOf(data, data.length);
}
this.offset = offset; this.offset = offset;
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
this.format = format; this.format = format;
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
package sun.audio; package sun.audio;
import java.io.*; import java.io.*;
import java.util.Arrays;
import javax.sound.sampled.*; import javax.sound.sampled.*;
...@@ -65,12 +67,11 @@ public final class AudioData { ...@@ -65,12 +67,11 @@ public final class AudioData {
/** /**
* Constructor * Constructor
*/ */
public AudioData(byte buffer[]) { public AudioData(final byte[] buffer) {
// if we cannot extract valid format information, we resort to assuming
this.buffer = buffer; // the data will be 8k mono u-law in order to provide maximal backwards
// if we cannot extract valid format information, we resort to assuming the data will be 8k mono u-law // compatibility....
// in order to provide maximal backwards compatibility.... this(DEFAULT_FORMAT, buffer);
this.format = DEFAULT_FORMAT;
// okay, we need to extract the format and the byte buffer of data // okay, we need to extract the format and the byte buffer of data
try { try {
...@@ -90,9 +91,10 @@ public final class AudioData { ...@@ -90,9 +91,10 @@ public final class AudioData {
* Non-public constructor; this is the one we use in ADS and CADS * Non-public constructor; this is the one we use in ADS and CADS
* constructors. * constructors.
*/ */
AudioData(AudioFormat format, byte[] buffer) { AudioData(final AudioFormat format, final byte[] buffer) {
this.format = format; this.format = format;
this.buffer = buffer; if (buffer != null) {
this.buffer = Arrays.copyOf(buffer, buffer.length);
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册