View Javadoc

1   /*
2    * Copyright 2003-2004 Michael Franken, Zilverline.
3    *
4    * The contents of this file, or the files included with this file, are subject to
5    * the current version of ZILVERLINE Collaborative Source License for the
6    * Zilverline Search Engine (the "License"); You may not use this file except in
7    * compliance with the License.
8    *
9    * You may obtain a copy of the License at
10   *
11   *     http://www.zilverline.org.
12   *
13   * See the License for the rights, obligations and
14   * limitations governing use of the contents of the file.
15   *
16   * The Original and Upgraded Code is the Zilverline Search Engine. The developer of
17   * the Original and Upgraded Code is Michael Franken. Michael Franken owns the
18   * copyrights in the portions it created. All Rights Reserved.
19   *
20   */
21  
22  package org.zilverline.util;
23  
24  import java.io.File;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  /***
32   * The SystemErrors holds possible errorcodes for Various platforms.
33   * 
34   * @author Michael Franken
35   * @version $Revision: 1.5 $
36   * 
37   * @since 18 september 2004
38   */
39  public final class SysUtils {
40      /*** logger for Commons logging. */
41      private static Log log = LogFactory.getLog(SysUtils.class);
42  
43      /***
44       * Windows System Error Codes from http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes__0-499_.asp
45       */
46      private static Map WINDOWS_SYSTEM_ERROR_CODES = new HashMap();
47  
48      private SysUtils() {
49      }
50  
51      static {
52          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(0), "The operation completed successfully.");
53          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(1), "Incorrect function.");
54          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(2), "The system cannot find the file specified.");
55          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(3), "The system cannot find the path specified.");
56          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(4), "The system cannot open the file.");
57          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(5), "Access is denied.");
58          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(6), "The handle is invalid.");
59          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(7), "The storage control blocks were destroyed.");
60          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(8), "Not enough storage is available to process this command.");
61          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(9), "The storage control block address is invalid.");
62          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(10), "The environment is incorrect.");
63          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(11), "An attempt was made to load a program with an incorrect format.");
64          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(12), "The access code is invalid.");
65          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(13), "The data is invalid.");
66          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(14), "Not enough storage is available to complete this operation.");
67          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(15), "The system cannot find the drive specified.");
68          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(16), "The directory cannot be removed.");
69          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(17), "The system cannot move the file to a different disk drive.");
70          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(18), "There are no more files.");
71          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(19), "The media is write protected.");
72          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(20), "The system cannot find the device specified.");
73          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(21), "The device is not ready.");
74          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(22), "The device does not recognize the command.");
75          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(23), "Data error (cyclic redundancy check).");
76          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(24), "The program issued a command but the command length is incorrect.");
77          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(25), "The drive cannot locate a specific area or track on the disk.");
78          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(26), "The specified disk or diskette cannot be accessed.");
79          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(27), "The drive cannot find the sector requested.");
80          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(28), "The printer is out of paper.");
81          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(29), "The system cannot write to the specified device.");
82          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(30), "The system cannot read from the specified device.");
83          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(31), "A device attached to the system is not functioning.");
84          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(32),
85              "The process cannot access the file because it is being used by another process.");
86          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(33),
87              "The process cannot access the file because another process has locked a portion of the file.");
88          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(34),
89              "The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1.");
90          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(36), "Too many files opened for sharing.");
91          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(38), "Reached the end of the file.");
92          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(39), "The disk is full.");
93          WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(50), "The request is not supported.");
94          WINDOWS_SYSTEM_ERROR_CODES
95              .put(
96                  new Integer(51),
97                  "Windows cannot find the network path. Verify that the network path is correct and the destination computer is not busy or turned off. If Windows still cannot find the network path, contact your network administrator.");
98          WINDOWS_SYSTEM_ERROR_CODES
99              .put(
100                 new Integer(52),
101                 "You were not connected because a duplicate name exists on the network. Go to System in the Control Panel to change the computer name and try again.");
102         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(53), "The network path was not found.");
103         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(54), "The network is busy.");
104         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(55), "The specified network resource or device is no longer available.");
105         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(56), "The network BIOS command limit has been reached.");
106         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(57), "A network adapter hardware error occurred.");
107         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(58), "The specified server cannot perform the requested operation.");
108         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(59), "An unexpected network error occurred.");
109         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(60), "The remote adapter is not compatible.");
110         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(61), "The printer queue is full.");
111         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(62),
112             "Space to store the file waiting to be printed is not available on the server.");
113         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(63), "Your file waiting to be printed was deleted.");
114         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(64), "The specified network name is no longer available.");
115         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(65), "Network access is denied.");
116         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(66), "The network resource type is not correct.");
117         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(67), "The network name cannot be found.");
118         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(68), "The name limit for the local computer network adapter card was exceeded.");
119         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(69), "The network BIOS session limit was exceeded.");
120         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(70), "The remote server has been paused or is in the process of being started.");
121         WINDOWS_SYSTEM_ERROR_CODES
122             .put(
123                 new Integer(71),
124                 "No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept.");
125         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(72), "The specified printer or disk device has been paused.");
126         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(80), "The file exists.");
127         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(82), "The directory or file cannot be created.");
128         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(83), "Fail on INT 24.");
129         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(84), "Storage to process this request is not available.");
130         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(85), "The local device name is already in use.");
131         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(86), "The specified network password is not correct.");
132         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(87), "The parameter is incorrect.");
133         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(88), "A write fault occurred on the network.");
134         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(89), "The system cannot start another process at this time.");
135         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(100), "Cannot create another system semaphore.");
136         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(101), "The exclusive semaphore is owned by another process.");
137         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(102), "The semaphore is set and cannot be closed.");
138         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(103), "The semaphore cannot be set again.");
139         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(104), "Cannot request exclusive semaphores at interrupt time.");
140         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(105), "The previous ownership of this semaphore has ended.");
141         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(106), "Insert the diskette for drive %1.");
142         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(107), "The program stopped because an alternate diskette was not inserted.");
143         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(108), "The disk is in use or locked by another process.");
144         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(109), "The pipe has been ended.");
145         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(110), "The system cannot open the device or file specified.");
146         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(111), "The file name is too long.");
147         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(112), "There is not enough space on the disk.");
148         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(113), "No more internal file identifiers available.");
149         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(114), "The target internal file identifier is incorrect.");
150         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(117), "The IOCTL call made by the application program is not correct.");
151         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(118), "The verify-on-write switch parameter value is not correct.");
152         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(119), "The system does not support the command requested.");
153         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(120), "This function is not supported on this system.");
154         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(121), "The semaphore timeout period has expired.");
155         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(122), "The data area passed to a system call is too small.");
156         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(123), "The filename, directory name, or volume label syntax is incorrect.");
157         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(124), "The system call level is not correct.");
158         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(125), "The disk has no volume label.");
159         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(126), "The specified module could not be found.");
160         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(127), "The specified procedure could not be found.");
161         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(128), "There are no child processes to wait for.");
162         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(129), "The %1 application cannot be run in Win32 mode.");
163         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(130),
164             "Attempt to use a file handle to an open disk partition for an operation other than raw disk I/O.");
165         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(131),
166             "An attempt was made to move the file pointer before the beginning of the file.");
167         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(132), "The file pointer cannot be set on the specified device or file.");
168         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(133),
169             "A JOIN or SUBST command cannot be used for a drive that contains previously joined drives.");
170         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(134),
171             "An attempt was made to use a JOIN or SUBST command on a drive that has already been joined.");
172         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(135),
173             "An attempt was made to use a JOIN or SUBST command on a drive that has already been substituted.");
174         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(136), "The system tried to delete the JOIN of a drive that is not joined.");
175         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(137),
176             "The system tried to delete the substitution of a drive that is not substituted.");
177         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(138), "The system tried to join a drive to a directory on a joined drive.");
178         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(139),
179             "The system tried to substitute a drive to a directory on a substituted drive.");
180         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(140), "The system tried to join a drive to a directory on a substituted drive.");
181         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(141), "The system tried to SUBST a drive to a directory on a joined drive.");
182         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(142), "The system cannot perform a JOIN or SUBST at this time.");
183         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(143),
184             "The system cannot join or substitute a drive to or for a directory on the same drive.");
185         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(144), "The directory is not a subdirectory of the root directory.");
186         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(145), "The directory is not empty.");
187         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(146), "The path specified is being used in a substitute.");
188         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(147), "Not enough resources are available to process this command.");
189         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(148), "The path specified cannot be used at this time.");
190         WINDOWS_SYSTEM_ERROR_CODES
191             .put(new Integer(149),
192                 "An attempt was made to join or substitute a drive for which a directory on the drive is the target of a previous substitute.");
193         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(150),
194             "System trace information was not specified in your CONFIG.SYS file, or tracing is disallowed.");
195         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(151),
196             "The number of specified semaphore events for DosMuxSemWait is not correct.");
197         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(152), "DosMuxSemWait did not execute");
198         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(153), "The DosMuxSemWait list is not correct.");
199         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(154),
200             "The volume label you entered exceeds the label character limit of the target file system.");
201         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(155), "Cannot create another thread.");
202         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(156), "The recipient process has refused the signal.");
203         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(157), "The segment is already discarded and cannot be locked.");
204         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(158), "The segment is already unlocked.");
205         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(159), "The address for the thread ID is not correct.");
206         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(160), "The argument string passed to DosExecPgm is not correct.");
207         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(161), "The specified path is invalid.");
208         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(162), "A signal is already pending.");
209         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(164), "No more threads can be created in the system.");
210         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(167), "Unable to lock a region of a file.");
211         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(170), "The requested resource is in use.");
212         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(173), "A lock request was not outstanding for the supplied cancel region.");
213         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(174), "The file system does not support atomic changes to the lock type.");
214         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(180), "The system detected a segment number that was not correct.");
215         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(182), "The operating system cannot run %1.");
216         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(183), "Cannot create a file when that file already exists.");
217         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(186), "The flag passed is not correct.");
218         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(187), "The specified system semaphore name was not found.");
219         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(188), "The operating system cannot run %1.");
220         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(189), "The operating system cannot run %1.");
221         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(190), "The operating system cannot run %1.");
222         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(191), "Cannot run %1 in Win32 mode.");
223         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(192), "The operating system cannot run %1.");
224         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(193), "%1 is not a valid Win32 application.");
225         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(194), "The operating system cannot run %1.");
226         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(195), "The operating system cannot run %1.");
227         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(196), "The operating system cannot run this application program.");
228         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(197),
229             "The operating system is not presently configured to run this application.");
230         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(198), "The operating system cannot run %1.");
231         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(199), "The operating system cannot run this application program.");
232         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(200), "The code segment cannot be greater than or equal to 64K.");
233         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(201), "The operating system cannot run %1.");
234         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(202), "The operating system cannot run %1.");
235         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(203), "The system could not find the environment option that was entered.");
236         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(205), "No process in the command subtree has a signal handler.");
237         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(206), "The filename or extension is too long.");
238         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(207), "The ring 2 stack is in use.");
239         WINDOWS_SYSTEM_ERROR_CODES
240             .put(new Integer(208),
241                 "The global filename characters, * or ?, are entered incorrectly or too many global filename characters are specified.");
242         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(209), "The signal being posted is not correct.");
243         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(210), "The signal handler cannot be set.");
244         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(212), "The segment is locked and cannot be reallocated.");
245         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(214),
246             "Too many dynamic-link modules are attached to this program or dynamic-link module.");
247         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(215), "Cannot nest calls to LoadModule.");
248         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(216),
249             "The image file %1 is valid, but is for a machine type other than the current machine.");
250         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(217), "The image file %1 is signed, unable to modify.");
251         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(218), "The image file %1 is strong signed, unable to modify.");
252         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(230), "The pipe state is invalid.");
253         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(231), "All pipe instances are busy.");
254         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(232), "The pipe is being closed.");
255         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(233), "No process is on the other end of the pipe.");
256         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(234), "More data is available.");
257         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(240), "The session was canceled.");
258         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(254), "The specified extended attribute name was invalid.");
259         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(255), "The extended attributes are inconsistent.");
260         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(258), "The wait operation timed out.");
261         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(259), "No more data is available.");
262         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(266), "The copy functions cannot be used.");
263         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(267), "The directory name is invalid.");
264         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(275), "The extended attributes did not fit in the buffer.");
265         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(276), "The extended attribute file on the mounted file system is corrupt.");
266         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(277), "The extended attribute table file is full.");
267         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(278), "The specified extended attribute handle is invalid.");
268         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(282), "The mounted file system does not support extended attributes.");
269         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(288), "Attempt to release mutex not owned by caller.");
270         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(298), "Too many posts were made to a semaphore.");
271         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(299),
272             "Only part of a ReadProcessMemory or WriteProcessMemory request was completed.");
273         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(300), "The oplock request is denied.");
274         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(301), "An invalid oplock acknowledgment was received by the system.");
275         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(302), "The volume is too fragmented to complete this operation.");
276         WINDOWS_SYSTEM_ERROR_CODES
277             .put(new Integer(303), "The file cannot be opened because it is in the process of being deleted.");
278         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(317),
279             "The system cannot find message text for message number 0x%1 in the message file for %2.");
280         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(318), "The scope specified was not found.");
281         WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(487), "Attempt to access invalid address.");
282     }
283 
284     public static String getErrorTextById(final int id) {
285         String os = System.getProperty("os.name");
286 
287         if (os.indexOf("Windows") >= 0) {
288             return (String) WINDOWS_SYSTEM_ERROR_CODES.get(new Integer(id));
289         }
290 
291         return "";
292     }
293 
294     /***
295      * Picks a random number between 0 and (below) the givenNumber.
296      * 
297      * @param number the givenNumber
298      * 
299      * @return a number n: 0 <= n < givenNumber
300      */
301     public static boolean canExecute(final String cmd) {
302         Process proc = null;
303         log.debug("Can we Execute cmd: " + cmd);
304         try {
305             proc = Runtime.getRuntime().exec(cmd);
306             // any error message?
307             StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
308             // any output?
309             StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
310             // kick them off
311             errorGobbler.start();
312             outputGobbler.start();
313             proc.waitFor();
314             log.debug("Exit value: " + proc.exitValue());
315             log.error("Exit value: " + SysUtils.getErrorTextById(proc.exitValue()));
316             return proc.exitValue() == 0;
317         }
318         catch (Exception e) {
319             log.error("Can't execute: " + cmd, e);
320 
321             if (proc != null) {
322                 log.error(" --> Can't execute: '" + cmd + "'. Exit value: " + proc.exitValue());
323                 log.error(" --> Can't execute: '" + cmd + "'. " + SysUtils.getErrorTextById(proc.exitValue()));
324             }
325         }
326         return false;
327     }
328 
329     /***
330      * Execute a system program on a file in a certain directory.
331      * 
332      * @param unArchiveCommand the command to run, including possible options
333      * @param sourceFile the file
334      * @param unPackDestinationDirectory the directory
335      * @return true on succes, false otherwise
336      */
337     public static boolean execute(final String unArchiveCommand, File sourceFile, File unPackDestinationDirectory) {
338         Process proc = null;
339         String[] cmd = null;
340         StringBuffer cmd4Log = new StringBuffer();
341         log.debug("unArchiveCommand: " + unArchiveCommand);
342         // prepare the command by first creating a command array, containing the program, options and source file
343         // first parse the command from config
344         String[] tmpCmd = unArchiveCommand.split(" ");
345 
346         try {
347             // and then copy the thing into a new larger array
348             cmd = new String[tmpCmd.length + 1];
349             for (int i = 0; i < tmpCmd.length; i++) {
350                 cmd[i] = tmpCmd[i];
351                 // for logging, never mind the overhead
352                 cmd4Log.append(cmd[i] + " ");
353             }
354             // cmd[tmpCmd.length] = "\"" + sourceFile.getAbsolutePath() + "\"";
355             cmd[tmpCmd.length] = sourceFile.getAbsolutePath();
356             cmd4Log.append(cmd[tmpCmd.length]);
357             log.debug("Executing: '" + cmd4Log + "' from working directory '" + unPackDestinationDirectory + "'");
358             // run the command in the target directory (unPackDestinationDirectory) on the archive (sourceFile)
359             // TODO: I pass cmd4Log instead of cmd[], since hh.exe does not do well...
360             proc = Runtime.getRuntime().exec(cmd4Log.toString(), null, unPackDestinationDirectory);
361             // any error message?
362             StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
363             // any output?
364             StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
365             // kick them off
366             errorGobbler.start();
367             outputGobbler.start();
368             proc.waitFor();
369             log.debug("Exit value: " + SysUtils.getErrorTextById(proc.exitValue()));
370             // everthing OK?
371             if (proc.exitValue() == 0) {
372                 // got it right first time
373                 log.debug("Succesfully executed: '" + cmd4Log + "'.");
374                 return true;
375             } else {
376                 // error executing proc
377                 log.debug("Retrying, couldn't execute: '" + cmd4Log + "'. Exit value: "
378                     + SysUtils.getErrorTextById(proc.exitValue()));
379 
380                 // try again with cmd
381                 proc = Runtime.getRuntime().exec(cmd, null, unPackDestinationDirectory);
382                 // any error message?
383                 errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
384                 // any output?
385                 outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
386                 // kick them off
387                 errorGobbler.start();
388                 outputGobbler.start();
389                 proc.waitFor();
390                 log.debug("Exit value: " + SysUtils.getErrorTextById(proc.exitValue()));
391 
392                 if (proc.exitValue() != 0) {
393                     // error executing proc
394                     log.warn(" --> Can't execute in retry (with cmd[]): '" + cmd4Log + "'. Exit value: " + proc.exitValue());
395                     log.warn(" --> Can't execute: '" + cmd4Log + "'. " + SysUtils.getErrorTextById(proc.exitValue()));
396                 } else {
397                     log.debug("Succesfully executed in retry: '" + cmd4Log + "'.");
398                     return true;
399                 }
400             }
401         }
402         catch (Exception e) {
403             log.error("Can't execute: " + cmd4Log, e);
404 
405             if (proc != null) {
406                 log.error(" --> Can't execute: '" + cmd4Log + "'. Exit value: " + proc.exitValue());
407                 log.error(" --> Can't execute: '" + cmd4Log + "'. " + SysUtils.getErrorTextById(proc.exitValue()));
408             }
409         }
410         return false;
411     }
412 }