Refine search
@Override public String toEditString() { StringWriter buf = new StringWriter(); buf.append(LABEL); buf.append("\t"); buf.append(LABEL); return buf.toString(); } }
protected String replaceResourceContents(String contents) throws IOException { InputStream inputStream = null; try { Properties prop = new Properties(); String propFileName = getOpenAdminMessagesProperties(); inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); if (inputStream != null) { prop.load(inputStream); } else { throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); } StringWriter propertiesObject = new StringWriter(); propertiesObject.append("{"); // get the property value and print it out for(Map.Entry<Object,Object> property : prop.entrySet()) { propertiesObject.append(property.getKey() + ": \"" + property.getValue() + "\", "); } contents = contents.replace("//BLC-ADMIN-JS-MESSAGES", propertiesObject.getBuffer().toString().substring(0, propertiesObject.getBuffer().toString().length() - 2) + "}"); } catch (Exception e) { throw new RuntimeException(e); } finally { if(inputStream != null) { inputStream.close(); } } return contents; }
@Override public void testRunStarted(Description description) { System.err.println("Installing aggressive uncaught exception handler"); oldDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { StringWriter errorText = new StringWriter(256); errorText.append("Uncaught exception in OkHttp thread \""); errorText.append(thread.getName()); errorText.append("\"\n"); throwable.printStackTrace(new PrintWriter(errorText)); errorText.append("\n"); if (lastTestStarted != null) { errorText.append("Last test to start was: "); errorText.append(lastTestStarted.getDisplayName()); errorText.append("\n"); } System.err.print(errorText.toString()); synchronized (exceptions) { exceptions.put(throwable, lastTestStarted.getDisplayName()); } }); }
static String exceptionToString(Throwable ex) { if (ex == null) { return "null"; } StringWriter str = new StringWriter(); str.append("Exception: ").append(ex.getClass().getSimpleName()); str.append(" Message: ").append(ex.getMessage()); str.append(" Stacktrace: "); Throwable cause = ex.getCause(); if (cause != null) { str.append("\nCause: ").append(exceptionToString(cause)); } PrintWriter writer = new PrintWriter(str); try { ex.printStackTrace(writer); return str.getBuffer().toString(); } finally { try { str.close(); writer.close(); } catch (IOException e) {} } }
private String getInPlaceProgressBar(double percent) { StringWriter bar = new StringWriter(); bar.append("["); int remainingChars = PROGRESS_BAR_CHARS - 4; int completed = (int) (remainingChars * percent); int pending = remainingChars - completed; for (int i = 0; i < completed; i++) { bar.append("="); } bar.append(">>"); for (int i = 0; i < pending; i++) { bar.append("-"); } bar.append("]"); return bar.toString(); }
@Override public String toString() { StringWriter sw = new StringWriter(); boolean first = true; for (String line : lines) { sw.append(line).append("\n"); if (first && this.breadcrumbs != null) { for (String bline : breadcrumbs) { sw.append(bline).append("\n"); } } first = false; } return sw.toString(); }
@Override public String toString() { StringWriter result = new StringWriter().append( super.toString() ); for ( Diagnostic<?> diagnostic : diagnostics ) { format( result.append( "\n\t\t" ), diagnostic ); } return result.toString(); }
public static String stringify(Throwable t) { StringWriter sw = new StringWriter(); sw.append(t.toString()).append('\n'); t.printStackTrace(new PrintWriter(sw)); return sw.toString(); }
public String toString(){ StringWriter sw = new StringWriter(); //addr should never be null, but just to make sure if (addr !=null) { sw.append(delimitedHostString(addr)); sw.append(":"); sw.append(String.valueOf(addr.getPort())); } if (electionAddr!=null){ sw.append(":"); sw.append(String.valueOf(electionAddr.getPort())); } if (type == LearnerType.OBSERVER) sw.append(":observer"); else if (type == LearnerType.PARTICIPANT) sw.append(":participant"); if (clientAddr!=null && !isClientAddrFromStatic){ sw.append(";"); sw.append(delimitedHostString(clientAddr)); sw.append(":"); sw.append(String.valueOf(clientAddr.getPort())); } return sw.toString(); }
private static String lineFor(String tableName, Path dataLoc, HiveConf hiveConf) throws IOException, SemanticException { StringWriter lineToWrite = new StringWriter(); lineToWrite.append(tableName).append(FIELD_SEPARATOR); Path dataLocation = PathBuilder.fullyQualifiedHDFSUri(dataLoc, dataLoc.getFileSystem(hiveConf)); byte[] encodedBytes = Base64.getEncoder() .encode(dataLocation.toString().getBytes(StandardCharsets.UTF_8)); String encodedPath = new String(encodedBytes, StandardCharsets.UTF_8); lineToWrite.append(encodedPath).append("\n"); return lineToWrite.toString(); }
private static String createErrorMessage(Throwable t) { StringWriter errorMessage = new StringWriter(); errorMessage.append(t.getClass().getName()).append("\r\n"); t.printStackTrace(new PrintWriter(errorMessage)); errorMessage.append("\r\n"); return errorMessage.toString(); } }
@Override public void handleMethodTranslateException(Method method, DexMethodNode methodNode, MethodVisitor mv, Exception e) { // replace the generated code with // 'return new RuntimeException("D2jFail translate: xxxxxxxxxxxxx");' StringWriter s = new StringWriter(); s.append("d2j fail translate: "); e.printStackTrace(new PrintWriter(s)); String msg = s.toString(); mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(msg); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.ATHROW); } }
public String stringOf(Closure cl) throws IOException { Writer old = out; StringWriter stringWriter = new StringWriter(32); out = stringWriter; Object result = cl.call(); if (result!=null && result!=this) { stringWriter.append(result.toString()); } out = old; return stringWriter.toString(); }
public String build() { StringWriter sw = new StringWriter(); if (firstLine != null) { sw.append(firstLine); sw.append('\n'); } rootNode.toXml("", sw); return sw.toString(); }
/** * Pretty printers */ public static String printEdges(Iterable<SemanticGraphEdge> edges) { StringWriter buf = new StringWriter(); for (SemanticGraphEdge edge : edges) { buf.append("\t"); buf.append(edge.getRelation().toString()); buf.append("("); buf.append(edge.getGovernor().toString()); buf.append(", "); buf.append(edge.getDependent().toString()); buf.append(")\n"); } return buf.toString(); }
@Override public void uncaughtException(Thread t, Throwable e) { StringWriter stringWriter = new StringWriter(); stringWriter.append("Exception in thread \"").append(t.getName()).append("\" "); e.printStackTrace(new PrintWriter(stringWriter)); String trace = stringWriter.toString(); // Not logger.error() because it needs to show up red (and linked) in the IDE console System.err.print(trace); displayException(e, trace); }
/** * Converts the provided map as a JSON object according to the configured JSON mapper. * * @param map the provided map * @return the JSON as a string */ @Nullable public String toJson(@Nullable Map<String, Object> map) { if (map == null || map.isEmpty()) { return null; } try (StringWriter writer = new StringWriter(bufferSize)) { objectMapper.writeValue(writer, map); if (doesAppendLineSeparator) { writer.append(CoreConstants.LINE_SEPARATOR); } return writer.toString(); } catch (IOException e) { throw new IllegalArgumentException("Unable to format map as a JSON", e); } } }
@Override public String toString() { StringWriter buf = new StringWriter(); buf.append("Semgrex Pattern: UID="); buf.write(getUID()); buf.write("\nNotes: "); buf.write(getNotes()); buf.write("\n"); buf.append(semgrexPattern.toString()); if (predicateTest != null) { buf.write("\nPredicate: "); buf.write(predicateTest.toString()); } buf.append("\nEdit script:\n"); for (SsurgeonEdit edit : editScript) { buf.append("\t"); buf.append(edit.toString()); buf.append("\n"); } return buf.toString(); }