source: main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java@ 29576

Last change on this file since 29576 was 29576, checked in by Jeremy Symon, 9 years ago

Fixed GS2PerlConstructor to set gsdlos correctly, and set PERL_PERTURB_KEYS=0 to avoid mangling collections when rebuilding

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1 /*
2 * Misc.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20package org.greenstone.util;
21
22import java.util.HashMap;
23import java.util.Set;
24import java.util.Map;
25import java.util.Iterator;
26import java.util.Properties;
27import java.io.InputStream;
28import java.io.BufferedReader;
29import java.io.InputStreamReader;
30import java.io.IOException;
31import java.net.HttpURLConnection;
32import java.net.URL;
33import java.net.URLConnection;
34
35/** contains miscellaneous functions */
36public class Misc {
37
38 public static void printHash(HashMap map) {
39 Set entries = map.entrySet();
40 Iterator i = entries.iterator();
41 while (i.hasNext()) {
42 Map.Entry m = (Map.Entry)i.next();
43 String name = (String)m.getKey();
44 String value = (String)m.getValue();
45 }
46 }
47
48 /** Method to determine if the host system is Windows based.
49 * @return a boolean which is true if the platform is Windows,
50 * false otherwise
51 */
52 public static boolean isWindows() {
53 Properties props = System.getProperties();
54 String os_name = props.getProperty("os.name","");
55 if(os_name.startsWith("Windows")) {
56 return true;
57 }
58 return false;
59 }
60
61 public static boolean isWindows9x() {
62 Properties props = System.getProperties();
63 String os_name = props.getProperty("os.name","");
64 if(os_name.startsWith("Windows") && os_name.indexOf("9") != -1) {
65 return true;
66 }
67 return false;
68 }
69
70 /** Method to determine if the host system is MacOS based.
71 * @return a boolean which is true if the platform is MacOS, false otherwise
72 */
73 public static boolean isMac() {
74 Properties props = System.getProperties();
75 String os_name = props.getProperty("os.name","");
76 if(os_name.startsWith("Mac OS")) {
77 return true;
78 }
79 return false;
80 }
81
82 public static String getGsdlOS() {
83 if (isWindows()) {
84 return "windows";
85 }
86 if (isMac()) {
87 return "darwin";
88 }
89 return "linux";
90 }
91
92 public static boolean isBigEndian() {
93
94 if (System.getProperty("sun.cpu.endian").equals("big")) {
95 return true;
96 }
97 return false;
98
99 }
100
101 public static BufferedReader makeHttpConnection(String url_string)
102 throws java.net.MalformedURLException, java.io.IOException {
103 BufferedReader reader = null;
104 URL url = new URL(url_string);
105 HttpURLConnection connection = (HttpURLConnection)url.openConnection();
106 InputStream input = connection.getInputStream();
107 reader = new BufferedReader(new InputStreamReader(input));
108 return reader;
109 }
110
111 public static void main(String [] args) {
112 isBigEndian();
113 }
114
115}
116
Note: See TracBrowser for help on using the repository browser.