formatting & missing import for EOFException

This commit is contained in:
Aaron authored and GitHub committed 2016-10-21 17:13:14 +02:00
1 parent e7c4ac922f
commit 15d1f32be2
1 file changed
+25 -24
@@ -3,6 +3,7 @@ package mekanism.client.voice;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import java.io.EOFException;
import mekanism.common.Mekanism;
import net.minecraftforge.fml.relauncher.Side;
@@ -30,31 +31,31 @@ public class VoiceOutput extends Thread
public void run()
{
try {
sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker));
sourceLine.open(voiceClient.format, 2200);
sourceLine.start();
byte[] audioData = new byte[4096]; // less allocation/gc (if done outside the loop)
int byteCount;
int length;
while(voiceClient.running)
{
try {
byteCount = voiceClient.input.readUnsignedShort(); //Why would we only read signed shorts? negative amount of waiting data doesn't make sense anyway :D
while(byteCount>0 && voiceClient.running){
length=audioData.length;
if(length>byteCount) length=byteCount;
length = voiceClient.input.read(audioData, 0, length); // That one returns the actual read amount of data (we can begin transferring even if input is waiting/incomplete)
if(length<0) throw new EOFException();
sourceLine.write(audioData, 0, length);
byteCount-=length;
sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker));
sourceLine.open(voiceClient.format, 2200);
sourceLine.start();
byte[] audioData = new byte[4096]; // less allocation/gc (if done outside the loop)
int byteCount;
int length;
while(voiceClient.running)
{
try {
byteCount = voiceClient.input.readUnsignedShort(); //Why would we only read signed shorts? negative amount of waiting data doesn't make sense anyway :D
while(byteCount>0 && voiceClient.running){
length=audioData.length;
if(length>byteCount) length=byteCount;
length = voiceClient.input.read(audioData, 0, length); // That one returns the actual read amount of data (we can begin transferring even if input is waiting/incomplete)
if(length<0) throw new EOFException();
sourceLine.write(audioData, 0, length);
byteCount-=length;
}
} catch(EOFException eof){
Mekanism.logger.error("VoiceServer: Unexpected input EOF Exception occured.");
break; // voiceClient.input will continue throwing EOFs -> no need to go on checking
} catch(Exception e) {
/*Would a debug output be good here?*/
}
}
} catch(EOFException eof){
Mekanism.logger.error("VoiceServer: Unexpected input EOF Exception occured.");
break; // voiceClient.input will continue throwing EOFs -> no need to go on checking
} catch(Exception e) {
/*Would a debug output be good here?*/
}
}
} catch(Exception e) {
Mekanism.logger.error("VoiceServer: Error while running client output thread.");
e.printStackTrace();