KickJava   Java API By Example, From Geeks To Geeks.

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


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 XP environment.
26  *
27  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:29 $
29  */

30 public final class WindowsXP implements CPUParser
31 {
32     private final int m_processors;
33     private final String JavaDoc m_cpuInfo;
34
35     /**
36      * Create this instance of CPUParser and gather information from
37      * the Windows XP system.
38      */

39     public WindowsXP()
40     {
41         int procs = 1;
42         String JavaDoc info = "";
43
44         try
45         {
46             Runtime JavaDoc rt = Runtime.getRuntime();
47             Process JavaDoc proc = rt.exec( "cmd.exe /C echo %NUMBER_OF_PROCESSORS%" );
48             BufferedReader JavaDoc reader = new BufferedReader JavaDoc( new InputStreamReader JavaDoc(
49                 proc.getInputStream() ) );
50             String JavaDoc numProcs = reader.readLine();
51
52             proc = rt.exec( "cmd.exe /C echo %PROCESSOR_IDENTIFIER%" );
53             reader = new BufferedReader JavaDoc( new InputStreamReader JavaDoc( proc.getInputStream() ) );
54             info = reader.readLine();
55
56             procs = Integer.parseInt( numProcs );
57         }
58         catch( Exception JavaDoc e )
59         {
60         }
61
62         m_processors = procs;
63         m_cpuInfo = info;
64     }
65
66     /**
67      * Return the number of processors available on the machine
68      */

69     public int numProcessors()
70     {
71         return m_processors;
72     }
73
74     /**
75      * Return the cpu info for the processors (assuming symetric multiprocessing
76      * which means that all CPUs are identical). The format is:
77      *
78      * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
79      */

80     public String JavaDoc cpuInfo()
81     {
82         return m_cpuInfo;
83     }
84 }
85
86
Popular Tags