KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > util > system > Windows95


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.excalibur.util.system;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.InputStreamReader JavaDoc;
21
22 import org.apache.excalibur.util.CPUParser;
23
24 /**
25  * Parses the Windows 95 environment--the same class should work for other
26  * Windows versions, but I only have one to test. Windows 9x environments
27  * can only use one processor--even if there are more installed in the system.
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:29 $
31  */

32 public final class Windows95 implements CPUParser
33 {
34     private final int m_processors = 1;
35     private final String JavaDoc m_cpuInfo;
36
37     public Windows95()
38     {
39         String JavaDoc info = "";
40
41         try
42         {
43             // This is not the propper environment variable for Win 9x
44
Runtime JavaDoc rt = Runtime.getRuntime();
45             Process JavaDoc proc = rt.exec( "command.com /C echo %PROCESSOR_IDENTIFIER%" );
46             BufferedReader JavaDoc reader = new BufferedReader JavaDoc( new InputStreamReader JavaDoc( proc.getInputStream() ) );
47             info = reader.readLine();
48         }
49         catch( Exception JavaDoc e )
50         {
51         }
52
53         m_cpuInfo = info;
54     }
55
56     /**
57      * Return the number of processors available on the machine
58      */

59     public int numProcessors()
60     {
61         return m_processors;
62     }
63
64     /**
65      * Return the cpu info for the processors (assuming symetric multiprocessing
66      * which means that all CPUs are identical). The format is:
67      *
68      * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
69      */

70     public String JavaDoc cpuInfo()
71     {
72         return m_cpuInfo;
73     }
74 }
75
76
Popular Tags