summaryrefslogtreecommitdiffstats
path: root/pki/base/util/src/com/netscape/cmsutil/util/Utils.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2011-12-08 21:15:59 -0500
committerAde Lee <alee@redhat.com>2011-12-08 21:15:59 -0500
commit171aaece4f23709d33d180cf36eb3af5e454b0c9 (patch)
tree1485f9f0a7bd10de4ff25030db575dbb8dafae74 /pki/base/util/src/com/netscape/cmsutil/util/Utils.java
parentadad2fcee8a29fdb82376fbce07dedb11fccc182 (diff)
downloadpki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.gz
pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.xz
pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.zip
Revert "Formatting"
This reverts commit 32150d3ee32f8ac27118af7c792794b538c78a2f.
Diffstat (limited to 'pki/base/util/src/com/netscape/cmsutil/util/Utils.java')
-rw-r--r--pki/base/util/src/com/netscape/cmsutil/util/Utils.java162
1 files changed, 83 insertions, 79 deletions
diff --git a/pki/base/util/src/com/netscape/cmsutil/util/Utils.java b/pki/base/util/src/com/netscape/cmsutil/util/Utils.java
index dc1536cd1..36933da8e 100644
--- a/pki/base/util/src/com/netscape/cmsutil/util/Utils.java
+++ b/pki/base/util/src/com/netscape/cmsutil/util/Utils.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmsutil.util;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
@@ -35,59 +36,64 @@ import java.util.Date;
import java.util.Vector;
public class Utils {
- /**
- * Checks if this is NT.
- */
- public static boolean isNT() {
- return ((File.separator).equals("\\"));
- }
+ /**
+ * Checks if this is NT.
+ */
+ public static boolean isNT() {
+ return ((File.separator).equals("\\"));
+ }
- public static boolean exec(String cmd) {
- try {
- String cmds[] = null;
- if (isNT()) {
- // NT
- cmds = new String[3];
- cmds[0] = "cmd";
- cmds[1] = "/c";
- cmds[2] = cmd;
- } else {
- // UNIX
- cmds = new String[3];
- cmds[0] = "/bin/sh";
- cmds[1] = "-c";
- cmds[2] = cmd;
- }
- Process process = Runtime.getRuntime().exec(cmds);
- process.waitFor();
- BufferedReader pOut = null;
- String l = null;
+ public static boolean exec(String cmd) {
+ try {
+ String cmds[] = null;
+ if (isNT()) {
+ // NT
+ cmds = new String[3];
+ cmds[0] = "cmd";
+ cmds[1] = "/c";
+ cmds[2] = cmd;
+ } else {
+ // UNIX
+ cmds = new String[3];
+ cmds[0] = "/bin/sh";
+ cmds[1] = "-c";
+ cmds[2] = cmd;
+ }
+ Process process = Runtime.getRuntime().exec(cmds);
+ process.waitFor();
+ BufferedReader pOut = null;
+ String l = null;
- if (process.exitValue() == 0) {
- /**
- * pOut = new BufferedReader( new
- * InputStreamReader(process.getInputStream())); while ((l =
- * pOut.readLine()) != null) { System.out.println(l); }
- **/
- return true;
- } else {
- /**
- * pOut = new BufferedReader( new
- * InputStreamReader(process.getErrorStream())); l = null; while
- * ((l = pOut.readLine()) != null) { System.out.println(l); }
- **/
- return false;
- }
- } catch (Exception e) {
- return false;
- }
- }
+ if (process.exitValue() == 0) {
+ /**
+ pOut = new BufferedReader(
+ new InputStreamReader(process.getInputStream()));
+ while ((l = pOut.readLine()) != null) {
+ System.out.println(l);
+ }
+ **/
+ return true;
+ } else {
+ /**
+ pOut = new BufferedReader(
+ new InputStreamReader(process.getErrorStream()));
+ l = null;
+ while ((l = pOut.readLine()) != null) {
+ System.out.println(l);
+ }
+ **/
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
- public static String SpecialURLDecode(String s) {
+ public static String SpecialURLDecode(String s) {
if (s == null)
return null;
ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
-
+
for (int i = 0; i < s.length(); i++) {
int c = (int) s.charAt(i);
@@ -105,11 +111,11 @@ public class Utils {
return out.toString();
}
- public static byte[] SpecialDecode(String s) {
+ public static byte[] SpecialDecode(String s) {
if (s == null)
return null;
ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
-
+
for (int i = 0; i < s.length(); i++) {
int c = (int) s.charAt(i);
@@ -127,17 +133,17 @@ public class Utils {
return out.toByteArray();
}
- public static String SpecialEncode(byte data[]) {
+ public static String SpecialEncode(byte data[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < data.length; i++) {
- sb.append("%");
- if ((data[i] & 0xff) < 16) {
- sb.append("0");
- }
- sb.append(Integer.toHexString((data[i] & 0xff)));
+ sb.append("%");
+ if ((data[i] & 0xff) < 16) {
+ sb.append("0");
+ }
+ sb.append(Integer.toHexString((data[i] & 0xff)));
}
return sb.toString().toUpperCase();
- }
+ }
public static void checkHost(String hostname) throws UnknownHostException {
InetAddress addr = InetAddress.getByName(hostname);
@@ -145,23 +151,22 @@ public class Utils {
public static void copy(String orig, String dest) {
try {
- BufferedReader in = new BufferedReader(new FileReader(orig));
- PrintWriter out = new PrintWriter(new BufferedWriter(
- new FileWriter(dest)));
- String line = "";
- while (in.ready()) {
- line = in.readLine();
- if (line != null)
- out.println(line);
- }
- in.close();
- out.close();
+ BufferedReader in = new BufferedReader(new FileReader(orig));
+ PrintWriter out = new PrintWriter(
+ new BufferedWriter(new FileWriter(dest)));
+ String line = "";
+ while (in.ready()) {
+ line = in.readLine();
+ if (line != null)
+ out.println(line);
+ }
+ in.close();
+ out.close();
} catch (Exception ee) {
}
}
- public static void copyStream(InputStream in, OutputStream out)
- throws IOException {
+ public static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] buf = new byte[4096];
int len;
@@ -170,8 +175,7 @@ public class Utils {
}
}
- public static void copyStream(BufferedReader in, OutputStreamWriter out)
- throws IOException {
+ public static void copyStream(BufferedReader in, OutputStreamWriter out) throws IOException {
char[] buf = new char[4096];
int len;
@@ -180,8 +184,8 @@ public class Utils {
}
}
- // / Sorts an array of Strings.
- // Java currently has no general sort function. Sorting Strings is
+ /// Sorts an array of Strings.
+ // Java currently has no general sort function. Sorting Strings is
// common enough that it's worth making a special case.
public static void sortStrings(String[] strings) {
// Just does a bubblesort.
@@ -197,8 +201,8 @@ public class Utils {
}
}
- // / Returns a date string formatted in Unix ls style - if it's within
- // six months of now, Mmm dd hh:ss, else Mmm dd yyyy.
+ /// Returns a date string formatted in Unix ls style - if it's within
+ // six months of now, Mmm dd hh:ss, else Mmm dd yyyy.
public static String lsDateStr(Date date) {
long dateTime = date.getTime();
@@ -226,10 +230,9 @@ public class Utils {
}
return true;
}
-
+
/**
* strips out double quotes around String parameter
- *
* @param s the string potentially bracketed with double quotes
* @return string stripped of surrounding double quotes
*/
@@ -246,8 +249,9 @@ public class Utils {
}
/**
- * returns an array of strings from a vector of Strings there'll be trouble
- * if the Vector contains something other than just Strings
+ * returns an array of strings from a vector of Strings
+ * there'll be trouble if the Vector contains something other
+ * than just Strings
*/
public static String[] getStringArrayFromVector(Vector v) {
String s[] = new String[v.size()];