1
2
3
4
5
6
7 package com.octo.captcha.sound;
8
9 import java.io.IOException;
10 import java.io.InputStream;
11 import java.util.Locale;
12
13 import javax.sound.sampled.AudioInputStream;
14 import javax.sound.sampled.AudioSystem;
15 import javax.sound.sampled.UnsupportedAudioFileException;
16
17 import com.octo.captcha.CaptchaException;
18 import com.octo.captcha.component.sound.wordtosound.WordToSound;
19
20 /***
21 * Allow to test Sound captcha support without a real implementation
22 *
23 * @author <a href="mailto:antoine.veret@gmail.com">Antoine Véret</a>
24 * @date 19 avr. 2007
25 */
26 public class WordToSoundMock implements WordToSound {
27
28 private AudioInputStream audioInputStream = null;
29
30 public WordToSoundMock() throws IOException, UnsupportedAudioFileException {
31 InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("challenge1.wav");
32 audioInputStream = AudioSystem.getAudioInputStream(inputStream);
33 }
34
35 public int getMaxAcceptedWordLenght() {
36 return 0;
37 }
38
39 public int getMaxAcceptedWordLength() {
40 return 6;
41 }
42
43 public int getMinAcceptedWordLenght() {
44 return 0;
45 }
46
47 public int getMinAcceptedWordLength() {
48 return 2;
49 }
50
51 public AudioInputStream getSound(String word) throws CaptchaException {
52 return audioInputStream;
53 }
54
55 public AudioInputStream getSound(String word, Locale locale) throws CaptchaException {
56 return audioInputStream;
57 }
58 }