/** * Gets the DTD for the specified doctype file name. * * @param doctype the doctype file name (e.g., "osp10.dtd") * @return the DTD as a string */ public static String getDTD(String doctype) { if (dtdName != doctype) { // set to defaults in case doctype is not found dtdName = defaultName; try { String dtdPath = "/org/opensourcephysics/resources/controls/doctypes/"; // $NON-NLS-1$ java.net.URL url = XML.class.getResource(dtdPath + doctype); if (url == null) { return dtd; } Object content = url.getContent(); if (content instanceof InputStream) { BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) content)); StringBuffer buffer = new StringBuffer(0); String line; while ((line = reader.readLine()) != null) { buffer.append(line + NEW_LINE); } dtd = buffer.toString(); dtdName = doctype; } } catch (IOException ex) { ex.printStackTrace(); } } return dtd; }
public String toString() { StringBuffer s = new StringBuffer(); s.append("ed:"); for (int i = 0; i < count; i++) s.append(" " + args[i]); if (size != null) s.append(" (" + size + ")"); return s.toString(); }
private ClassLoaderStrategy getClassLoaderStrategy(String fullyQualifiedClassName) throws Exception { try { // Get just the package name StringBuffer sb = new StringBuffer(fullyQualifiedClassName); sb.delete(sb.lastIndexOf("."), sb.length()); currentPackage = sb.toString(); // Retrieve the Java classpath from the system properties String cp = System.getProperty("java.class.path"); String sepChar = System.getProperty("path.separator"); String[] paths = StringUtils.pieceList(cp, sepChar.charAt(0)); ClassLoaderStrategy cl = ClassLoaderUtil.getClassLoader(ClassLoaderUtil.FILE_SYSTEM_CLASS_LOADER, new String[] {}); // Iterate through paths until class with the specified name is found String classpath = StringUtils.replaceChar(currentPackage, '.', File.separatorChar); for (int i = 0; i < paths.length; i++) { Class[] classes = cl.getClasses(paths[i] + File.separatorChar + classpath, currentPackage); for (int j = 0; j < classes.length; j++) { if (classes[j].getName().equals(fullyQualifiedClassName)) { return ClassLoaderUtil.getClassLoader( ClassLoaderUtil.FILE_SYSTEM_CLASS_LOADER, new String[] {paths[i]}); } } } throw new Exception("Class could not be found."); } catch (Exception e) { System.err.println("Exception creating class loader strategy."); System.err.println(e.getMessage()); throw e; } }
static String javaSignature(Class<?> type) { if (!type.isArray()) { return type.getName(); } else { int arrayDimension = 0; do { ++arrayDimension; type = type.getComponentType(); } while (type.isArray()); String name = type.getName(); String suffix = "[]"; if (arrayDimension == 1) { return name.concat(suffix); } else { int length = name.length() + arrayDimension * suffix.length(); StringBuffer sb = new StringBuffer(length); sb.append(name); while (arrayDimension != 0) { --arrayDimension; sb.append(suffix); } return sb.toString(); } } }
public ProxiedMethod(Method method) { this.method = method; this.name = // method instanceof Constructor ? "<init>" : method.getName(); this.owner = method.getDeclaringClass(); StringBuffer jni_sig = new StringBuffer("("), c_sig = new StringBuffer(); retCapitalized = jni_capitalized(method.getReturnType()); String[] sigArg = c_signature(method.getReturnType(), "?"); c_sig.append(retType = sigArg[0]).append(" ").append(name).append("("); int i = 0; for (Class c : method.getParameterTypes()) { jni_sig.append(jni_signature(c)); if (i > 0) c_sig.append(", "); String argName = "arg" + (i + 1); sigArg = c_signature(c, argName); String argType = sigArg[0]; argTypes.add(argType); argNames.add(argName); argValues.add(sigArg[1]); c_sig.append(argType).append(" ").append(argName); i++; } c_sig.append(")"); jni_sig.append(")").append(jni_signature(method.getReturnType())); this.jni_signature = jni_sig.toString(); this.c_signature = c_sig.toString(); }
/** * This function performs an individual formatting test after the input and output streams have * been created. * * @param commands the input that decides which tests to perform * @return a String holding the error messages for any failed tests or null if no tests are * failed. */ private static /*@Nullable*/ String performTest(LineNumberReader commands) { StringBuffer output = new StringBuffer(); // List invariantTestCases = new Vector(); boolean noTestFailed = true; while (true) { // Create a new test case // FormatTestCase currentCase = FormatTestCase.instantiate(commands, generateGoals); // if (currentCase == null) // break; // else { // invariantTestCases.add(currentCase); String results = AddAndCheckTestCase.runTest(commands); if (results == null) break; if (!(results.length() == 0)) { // output.print(currentCase.getDiffString()); output.append(results); noTestFailed = false; } } if (noTestFailed) { return null; } else { return output.toString(); } }
/** * Print this EmitterSet readably. * * @return a string describing this EmitterSet */ public String toString() { StringBuffer s = new StringBuffer(); s.append("Emitter Set of:\n"); Iterator<EmitterDescriptor> i = emitters.iterator(); while (i.hasNext()) s.append(i.next().toString() + "\n"); s.append("-------------\n"); return s.toString(); }
public String toString() { StringBuffer buf = new StringBuffer(); buf.append("(Union (" + unionTypes.size() + "): "); for (InferredType it : unionTypes) { buf.append(it.toString() + ", "); } buf.append(") "); return buf.toString(); }
public String toString() { StringBuffer buf = new StringBuffer(); buf.append("(Struct: "); for (InferredType it : structTypes) { buf.append(it.toString() + ", "); } buf.append(") "); return buf.toString(); }
public String toString(Object v) { StringBuffer sb = new StringBuffer(); if (this.isHelp()) { sb.append("# --- ").append(this.getHelp()); } else { sb.append(this.getKey()).append("="); sb.append((v != null) ? v : NULL_VALUE); } return sb.toString(); }
private static String generateCommands(LineNumberReader input) { StringBuffer output = new StringBuffer(); while (true) { String commands = AddAndCheckTestCase.generateTest(input); if (commands == null) break; output.append(commands); } return output.toString(); }
/** * ** Returns the bean method name for the specified field ** @param prefix Either "get" or "set" * ** @param fieldName The field name ** @return The 'getter'/'setter' method name */ protected static String _beanMethodName(String prefix, String fieldName) { if ((prefix != null) && (fieldName != null)) { StringBuffer sb = new StringBuffer(prefix); sb.append(fieldName.substring(0, 1).toUpperCase()); sb.append(fieldName.substring(1)); return sb.toString(); } else { return ""; } }
public String getPropertyName(String name) { // Set the first letter of the property name to lower-case StringBuffer propertyName = new StringBuffer(name); char c = propertyName.charAt(0); if (c >= 'A' && c <= 'Z') { c -= 'A' - 'a'; propertyName.setCharAt(0, c); } return propertyName.toString(); }
public String getCompUniqueID() { UUID tempID = null; long longID = 0L; StringBuffer result = new StringBuffer(); tempID = getId(); result.append(Long.toHexString(tempID.getMostSignificantBits())); result.append(Long.toHexString(tempID.getLeastSignificantBits())); return result.toString(); }
/** * _more_ * * @param properties _more_ * @return _more_ */ public String makePropertiesString(Hashtable properties) { StringBuffer sb = new StringBuffer(); for (java.util.Enumeration keys = properties.keys(); keys.hasMoreElements(); ) { Object key = keys.nextElement(); sb.append(key); sb.append("="); sb.append(properties.get(key)); sb.append("\n"); } return sb.toString(); }
public String getCompUniqueID() { UUID tempID = null; long longID = 0L; StringBuffer result = new StringBuffer(); tempID = getArg_id(); if (IdAssigner.NULL_UUID.equals(tempID)) tempID = getArg_idCachedValue(); result.append(Long.toHexString(tempID.getMostSignificantBits())); result.append(Long.toHexString(tempID.getLeastSignificantBits())); return result.toString(); }
public String getDocString() { StringBuffer buf = new StringBuffer(); buf.append("Example data: "); for (Iterator<String> it = sampleStrs.iterator(); it.hasNext(); ) { String tokStr = it.next(); buf.append("'" + tokStr + "'"); if (it.hasNext()) { buf.append(", "); } } return buf.toString(); }
public static void setElement(Object[] oArr, Object value, int index) throws Throwable { StringBuffer tempMessage = new StringBuffer(); tempMessage.append( "配列に値を代入。 インデックス: " + index + " " + "要素型: " + value.getClass().getName() + "\r\n"); int size = oArr.length; if (index >= 0 && index < size) { oArr[index] = (Object) value; } else { tempMessage.append("インデックスが不正です\r\n"); } message = tempMessage.toString(); display.append(message); }
/** * クラスのオブジェクトを取得する * * @param String name クラスの名前 */ public static Class<?> getClass(String name) { StringBuffer tempMessage = new StringBuffer(); Class<?> cls = null; try { cls = Class.forName(name); tempMessage.append("以下のクラスオブジェクトを取得: " + name + "\r\n"); } catch (ClassNotFoundException e) { e.printStackTrace(); tempMessage.append("ClassNotFoundException\r\n"); } message = tempMessage.toString(); display.append(message); return cls; }
static int appendMethodSignature(Class[] argTypes, Class returnType, StringBuffer sb) { sb.append('('); int firstLocal = 1 + argTypes.length; // includes this. for (int i = 0; i < argTypes.length; i++) { Class type = argTypes[i]; appendTypeString(sb, type); if (type == Long.TYPE || type == Double.TYPE) { // adjust for duble slot ++firstLocal; } } sb.append(')'); appendTypeString(sb, returnType); return firstLocal; }
public static String toString(byte[] b) { if (b == null) { return "(null)"; } StringBuffer sb = new StringBuffer(b.length * 3); for (int i = 0; i < b.length; i++) { int k = b[i] & 0xff; if (i != 0) { sb.append(':'); } sb.append(hexDigits[k >>> 4]); sb.append(hexDigits[k & 0xf]); } return sb.toString(); }
String openUrlAsString(String address, int maxLines) { StringBuffer sb; try { URL url = new URL(address); InputStream in = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); sb = new StringBuffer(); int count = 0; String line; while ((line = br.readLine()) != null && count++ < maxLines) sb.append(line + "\n"); in.close(); } catch (IOException e) { sb = null; } return sb != null ? new String(sb) : null; }
/** Receive notification of character data inside an element. */ @Override public void characters(char ch[], int start, int len) { while (len > 0 && Character.isWhitespace(ch[start])) { ++start; --len; } while (len > 0 && Character.isWhitespace(ch[start + len - 1])) { --len; } if (len > 0) { if (_chars.length() > 0) { _chars.append(' '); } _chars.append(ch, start, len); } }
/** * _more_ * * @param request _more_ * @param entry _more_ * @param tabTitles _more_ * @param tabContents _more_ */ public void addToInformationTabs( Request request, Entry entry, List<String> tabTitles, List<String> tabContents) { // super.addToInformationTabs(request, entry, tabTitles, tabContents); try { RecordOutputHandler outputHandler = getRecordOutputHandler(); if (outputHandler != null) { tabTitles.add(msg("File Format")); StringBuffer sb = new StringBuffer(); RecordEntry recordEntry = outputHandler.doMakeEntry(request, entry); outputHandler.getFormHandler().getEntryMetadata(request, recordEntry, sb); tabContents.add(sb.toString()); } } catch (Exception exc) { throw new RuntimeException(exc); } }
/** Given a line from an input file, generates appropriate check or add command. */ private static void generateCheckOrAddCommand(String command, int lineNumber) { // remove the command String args = command.substring(command.indexOf(":") + 1); StringTokenizer tokens = new StringTokenizer(args, argDivider); if (tokens.countTokens() != types.length) { throw new RuntimeException( "Number of arguments to generate an add command on line: " + lineNumber + " is: " + tokens.countTokens() + " but should be: " + types.length); } Object[] params = getParams(tokens); assert !tokens.hasMoreTokens(); InvariantStatus goalStatus = null; if (isCheckCommand(command)) { goalStatus = getCheckStatus(params); } else { goalStatus = getAddStatus(params); } String invariantFormat = getInvariantFormat(); results.append( command + argDivider + " " + goalStatus.toString() + argDivider + " " + invariantFormat + lineSep); }
/** Return a nicely formatted message for when the actual value did not equal the expected one. */ protected String notEqualsMessage(String message, Object expected, Object actual) { StringBuffer buffer = new StringBuffer(250); if ((message != null) && (message.length() != 0)) { buffer.append(message); buffer.append(" "); } buffer.append("expected: \""); buffer.append(expected); buffer.append("\" but was: \""); buffer.append(actual); buffer.append("\""); return buffer.toString(); }
private static void printDebug(String msg, MemberBox member, Object[] args) { if (debug) { StringBuffer sb = new StringBuffer(); sb.append(" ----- "); sb.append(msg); sb.append(member.getDeclaringClass().getName()); sb.append('.'); if (member.isMethod()) { sb.append(member.getName()); } sb.append(JavaMembers.liveConnectSignature(member.argTypes)); sb.append(" for arguments ("); sb.append(scriptSignature(args)); sb.append(')'); System.out.println(sb); } }
/** * Initializes the fields of this class based on the first two lines of a case which include the * class name and parameter types. * * @return true is end of file is reached. */ private static boolean initFields(LineNumberReader commands, boolean generatingCommands) { results = new StringBuffer(); String className = getNextRealLine(commands); // End of file reached if (className == null) return true; // Load the class from file Class<? extends Invariant> classToTest = asInvClass(getClass(className)); try { classToTest.getField("dkconfig_enabled"); // Enable if needs to be done InvariantAddAndCheckTester.config.apply(className + ".enabled", "true"); } catch (NoSuchFieldException e) { // Otherwise do nothing } if (generatingCommands) { results.append(className + lineSep); } // Instantiate variables to be used as the names in the // invariants, variables are labeled a,b,c and so on as they // appear String typeString = getNextRealLine(commands); types = getTypes(typeString); VarInfo[] vars = getVarInfos(classToTest, types); PptSlice sl = createSlice(vars, daikon.test.Common.makePptTopLevel("Test:::OBJECT", vars)); // Create an actual instance of the class invariantToTest = instantiateClass(classToTest, sl); addModified = getAddModified(invariantToTest.getClass()); checkModified = getCheckModified(invariantToTest.getClass()); outputProducer = getOutputProducer(invariantToTest.getClass()); assert getArity(invariantToTest.getClass()) == types.length; if (generatingCommands) { results.append(typeString + lineSep); } return false; }
/** Converts a byte array into a String. */ protected static String byteArrayToString(byte[] array, boolean quote) { StringBuffer sb = new StringBuffer(); if (quote) sb.append('"'); for (int i = 0; i < array.length; i++) { int b = array[i] & 0xFF; if (b < 0x20 || b >= 0x7f) { sb.append('\\'); sb.append(byteFormat.format(b)); } else if (b == '"' || b == ';' || b == '\\') { sb.append('\\'); sb.append((char) b); } else sb.append((char) b); } if (quote) sb.append('"'); return sb.toString(); }
public String toString() { OJClass declarer = getDeclaringClass(); String declarername = (declarer == null) ? "*" : declarer.getName(); StringBuffer buf = new StringBuffer(); String modif = getModifiers().toString(); if (!modif.equals("")) { buf.append(modif); buf.append(" "); } buf.append(getType().getName()); buf.append(" "); buf.append(declarername); buf.append("."); buf.append(getName()); return buf.toString(); }