1 8 9 package com.sleepycat.je.utilint; 10 11 import java.io.File ; 12 13 import com.sleepycat.je.DatabaseException; 14 import com.sleepycat.je.EnvironmentConfig; 15 import com.sleepycat.je.config.EnvironmentParams; 16 import com.sleepycat.je.dbi.EnvironmentImpl; 17 18 21 public class CmdUtil { 22 public static String getArg(String [] argv, int whichArg) 23 throws IllegalArgumentException { 24 25 if (whichArg < argv.length) { 26 return argv[whichArg]; 27 } else { 28 throw new IllegalArgumentException (); 29 } 30 } 31 32 36 public static long readLongNumber(String longVal) { 37 if (longVal.startsWith("0x")) { 38 return Long.parseLong(longVal.substring(2), 16); 39 } else { 40 return Long.parseLong(longVal); 41 } 42 } 43 44 private static final String printableChars = 45 "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" + 46 "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; 47 48 public static void formatEntry(StringBuffer sb, 49 byte[] entryData, 50 boolean formatUsingPrintable) { 51 for (int i = 0; i < entryData.length; i++) { 52 int b = entryData[i] & 0xff; 53 if (formatUsingPrintable) { 54 if (isPrint(b)) { 55 if (b == 0134) { 56 sb.append('\\'); 57 } 58 sb.append(printableChars.charAt(b - 33)); 59 } else { 60 sb.append('\\'); 61 String hex = Integer.toHexString(b); 62 if (b < 16) { 63 sb.append('0'); 64 } 65 sb.append(hex); 66 } 67 } else { 68 String hex = Integer.toHexString(b); 69 if (b < 16) { 70 sb.append('0'); 71 } 72 sb.append(hex); 73 } 74 } 75 } 76 77 private static boolean isPrint(int b) { 78 return (b < 0177) && (040 < b); 79 } 80 81 85 public static EnvironmentImpl makeUtilityEnvironment(File envHome, 86 boolean readOnly) 87 throws DatabaseException { 88 89 EnvironmentConfig config = new EnvironmentConfig(); 90 config.setReadOnly(readOnly); 91 92 93 config.setConfigParam(EnvironmentParams.JE_LOGGING_DBLOG.getName(), 94 "false"); 95 96 config.setConfigParam(EnvironmentParams.JE_LOGGING_CONSOLE.getName(), 97 "true"); 98 99 100 config.setConfigParam(EnvironmentParams.JE_LOGGING_LEVEL.getName(), 101 "SEVERE"); 102 103 104 config.setConfigParam(EnvironmentParams.ENV_RECOVERY.getName(), 105 "false"); 106 107 EnvironmentImpl envImpl = new EnvironmentImpl(envHome, config); 108 return envImpl; 109 } 110 111 116 public static String getJavaCommand(Class cls) { 117 118 String clsName = cls.getName(); 119 String lastName = clsName.substring(clsName.lastIndexOf('.') + 1); 120 121 return "java { " + cls.getName() + " | -jar je-<version>.jar " + lastName + " }"; 122 } 123 } 124 | Popular Tags |