public void onConnection(SocketChannel channel) throws IOException {
PipedInputStream is = new PipedInputStream();
final PipedOutputStream os = new PipedOutputStream(is);
userNum++;
Connection cnt = new Connection(channel) {
@Override
protected void onRead(byte[] data, int size) {
try {
os.write(data, 0, size);
os.flush();
} catch (IOException ex) {
logger.info("Audio reading error");
}
}
@Override
public void end() {
super.end();
try {
os.close();
} catch (IOException ex) {
Logger.getLogger(AudioServer.class.getName()).log(Level.SEVERE, null, ex);
}
userNum--;
if (userNum == 0) {
logger.info("Audio server closing...");
stopServer();
}
}
};
synchronized (audioList) {
audioList.add(new MyAudioInputStream(is, AudioConfig.audioFormat, AudioSystem.NOT_SPECIFIED, cnt));
}
cnt.start();
}