File: hamilton1.html

package info (click to toggle)
lg-issue28 1-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,396 kB
  • ctags: 158
  • sloc: makefile: 30; sh: 3
file content (94 lines) | stat: -rw-r--r-- 4,326 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Building an Audio CD Player, Listing 2</title>
</head>
<body bgcolor="#FFFFFF" text="000000">
<p><HR> <P> 
<h3>Listing 1. Jcd.java</h3>
<p><HR> <P> 
<pre>
package Jcd;                                 //  1
/**                                              2
  Jcd - Java CD Audio Player                     3
  Michael Hamilton   (michael@actrix.gen.nz).    4
  All rights reserved.  See the README for details
 */                                          //  6
import java.io.*;                            //  8
import Jcd.Drive;                            // 10
public class Jcd {                           // 12
  public static void main(String[] args)     // 14
  {                                          // 15
    Drive cd_drive = new Drive(              // 16
      &quot;/dev/cdrom&quot;, 
      &quot;native/ix86-Linux/Jcd_Drive.so&quot;,      // 17
      0);                                    // 18
    DataInputStream cmd_stream = 
      new DataInputStream(System.in);        // 19
    String cmd;                              // 20
    try {                                    // 22
      System.out.println(
      &quot;Enter: info play stop pause resume eject&quot;); 
      for (cmd = cmd_stream.readLine();      // 26
           cmd.compareTo(&quot;exit&quot;) != 0;       // 27
           cmd = cmd_stream.readLine()) {    // 28
        try {                                // 30
          if (cmd.compareTo(&quot;play&quot;) == 0) {  // 31
            cd_drive.play(1);                // 32
          }                                  // 33
          else if (cmd.startsWith(&quot;goto&quot;)) { // 34
            try {                            // 35
              cd_drive.play(Integer.parseInt(
                cmd.substring(4).trim()));   // 37
	    }
	    catch (NumberFormatException badnum) {
	      System.out.println(&quot;Bad number &quot; +
				 badnum);    // 39
	    }                                // 40
	  }                                  // 41
          else if (cmd.compareTo(&quot;stop&quot;) == 0) { 
            cd_drive.stop();                 // 43
          }                                  // 44
          else if (cmd.compareTo(&quot;pause&quot;) == 0) { 
            cd_drive.pause();                // 46
          }                                  // 47
          else if (cmd.compareTo(&quot;resume&quot;) == 0) {
            cd_drive.resume();               // 49
          }                                  // 50
          else if (cmd.compareTo(&quot;eject&quot;) == 0) { 
            cd_drive.eject();                // 52
          }                                  // 53
          else if (cmd.compareTo(&quot;info&quot;) == 0) { 
            System.out.println(&quot;CDDB ID    = &quot; +
              cd_drive.cddbID());         
            System.out.println(&quot;Num Tracks = &quot; +
              cd_drive.numberOfTracks());
            System.out.println(&quot;End address= &quot; +
               cd_drive.cdEndAddress());
            System.out.println(&quot;&quot;);          // 58
            System.out.println(&quot;Track      = &quot; +
              cd_drive.currentTrack());
            System.out.println(&quot;Index      = &quot; + 
              cd_drive.currentIndex());
            System.out.println(&quot;Address    = &quot; +
              cd_drive.currentAddress());
            System.out.println(&quot;Trk address= &quot; + 
              cd_drive.trackAddress());
            System.out.println(&quot;Trk length = &quot; + 
              cd_drive.trackLength());
          }                                  // 65
        }                                    // 66
        catch (DriveException drive_problem) {
          System.out.println(&quot;Exception: &quot; +
                             drive_problem); // 68
        }                                    // 69
        System.out.println(&quot;Enter:&quot;);        // 70
      }                                      // 71
    }                                        // 72
    catch (IOException cmd_exception) {      // 73
    }                                        // 74
  }                                          // 75
}                                            // 76
</pre>
</body>
</html>