当前位置: 首页>>代码示例>>Java>>正文


Java Writer.toString方法代码示例

本文整理汇总了Java中java.io.Writer.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Writer.toString方法的具体用法?Java Writer.toString怎么用?Java Writer.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.Writer的用法示例。


在下文中一共展示了Writer.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: format

import java.io.Writer; //导入方法依赖的package包/类
@Override
public String format(LogRecord logRecord) {
    Object[] arguments = new Object[6];
    arguments[0] = logRecord.getThreadID();
    String fullClassName = logRecord.getSourceClassName();
    int lastDot = fullClassName.lastIndexOf('.');
    String className = fullClassName.substring(lastDot + 1);
    arguments[1] = className;
    arguments[2] = logRecord.getSourceMethodName();
    arguments[3] = new Date(logRecord.getMillis());
    arguments[4] = logRecord.getMessage();
    if (logRecord.getThrown() != null) {
        Writer result = new StringWriter();
        logRecord.getThrown().printStackTrace(new PrintWriter(result));
        arguments[5] = result.toString();
    } else {
        arguments[5] = "";
    }
    return messageFormat.format(arguments);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:21,代码来源:BriefLogFormatter.java

示例2: freeMarkerRender

import java.io.Writer; //导入方法依赖的package包/类
/**
 * freemarker渲染html
 */
public static String freeMarkerRender(Map<String, Object> data, String htmlTmp) {
	Writer out = new StringWriter();
	try {
		// 获取模板,并设置编码方式
		Template template = freemarkerCfg.getTemplate(htmlTmp);
		template.setEncoding("UTF-8");
		// 合并数据模型与模板
		template.process(data, out); // 将合并后的数据和模板写入到流中,这里使用的字符流
		out.flush();
		return out.toString();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			out.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
	return null;
}
 
开发者ID:Sunny0715,项目名称:java_pdf_demo,代码行数:25,代码来源:JavaToPdfImgHtmlFreeMarker.java

示例3: d

import java.io.Writer; //导入方法依赖的package包/类
public d(Context context, int i, int i2, Throwable th) {
    super(context, i);
    if (th != null) {
        Throwable th2 = new Throwable(th);
        try {
            StackTraceElement[] stackTrace = th2.getStackTrace();
            if (stackTrace != null && stackTrace.length > this.m) {
                StackTraceElement[] stackTraceElementArr = new StackTraceElement[this.m];
                for (int i3 = 0; i3 < this.m; i3++) {
                    stackTraceElementArr[i3] = stackTrace[i3];
                }
                th2.setStackTrace(stackTraceElementArr);
            }
        } catch (Throwable th3) {
            th3.printStackTrace();
        }
        Writer stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        th2.printStackTrace(printWriter);
        this.a = stringWriter.toString();
        this.l = i2;
        printWriter.close();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:d.java

示例4: createDroolRule

import java.io.Writer; //导入方法依赖的package包/类
public String createDroolRule(Rule rule) throws TemplateException, IOException {
  try {
    Template temp = cfg.getTemplate(templateName);
    Writer out = new StringWriter();
    temp.process(createMap(rule), out);
    return out.toString();
  } catch (IOException iE) {
    logger.error("Problem getting rule template file." + iE.getMessage());
    throw iE;
  } catch (TemplateException tE) {
    logger.error("Problem writing Drool rule." + tE.getMessage());
    throw tE;
  } catch (Exception e) {
    logger.error("Problem creating rule: " + e.getMessage());
    throw e;
  }
}
 
开发者ID:edgexfoundry,项目名称:support-rulesengine,代码行数:18,代码来源:RuleCreator.java

示例5: transform

import java.io.Writer; //导入方法依赖的package包/类
private String transform( String name ) throws ParserException, IOException
{
    List<Schema> schemas = new ArrayList<Schema>();
    Schema schema = new Schema();
    schema.setName( name );
    schema.setInput( getClass().getResourceAsStream( name + ".schema" ) );

    Writer out = new StringWriter( 2048 );
    schema.setOutput( out );
    schemas.add( schema );

    SchemaToLdif.transform( schemas );

    String res = out.toString();
    out.close();

    return res;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:19,代码来源:TestSchemaToLdif.java

示例6: parseResource

import java.io.Writer; //导入方法依赖的package包/类
public static String parseResource(Context context, int resource) throws IOException {
    InputStream is = context.getResources().openRawResource(resource);
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
        Reader reader = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8));
        int n;
        while ((n = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, n);
        }
    } finally {
        is.close();
    }

    return writer.toString();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:17,代码来源:JSONHandler.java

示例7: rtf2html

import java.io.Writer; //导入方法依赖的package包/类
public String rtf2html(final String rtf) {
	final JEditorPane p = new JEditorPane();
	p.setContentType("text/rtf");
	final EditorKit kitRtf = p.getEditorKitForContentType("text/rtf");
	try {
		kitRtf.read(new StringReader(rtf), p.getDocument(), 0);
		final Writer writer = new StringWriter();
		final EditorKit editorKitForContentType = p.getEditorKitForContentType("text/html");
		editorKitForContentType.write(writer, p.getDocument(), 0, p.getDocument().getLength());
		return writer.toString();
	} catch (IOException | BadLocationException e) {
		throw new RTF2HTMLException("Could not convert RTF to HTML.", e);
	}
}
 
开发者ID:bbottema,项目名称:outlook-message-parser,代码行数:15,代码来源:JEditorPaneRTF2HTMLConverter.java

示例8: uncaughtException

import java.io.Writer; //导入方法依赖的package包/类
public void uncaughtException(Thread t, Throwable e) {
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);
    String stacktrace = result.toString();
    printWriter.close();
    Logger.error(stacktrace);
    defaultUEH.uncaughtException(t, e);
}
 
开发者ID:jonasjuffinger,项目名称:TimeLapse,代码行数:10,代码来源:CustomExceptionHandler.java

示例9: normalizedNodeToJsonStreamTransformation

import java.io.Writer; //导入方法依赖的package包/类
/**
 * Returns a Normalized Node as a JSON String
 * @param writer - Writer to use
 * @param scPath - Schema Context Path for the Normalized Node
 * @param inputStructure - A Normalized Node
 * @return a String representing the Normalized Node
 * @throws IOException - if an error was encountered when writing the string
 */
public String normalizedNodeToJsonStreamTransformation(final Writer writer,
        SchemaPath scPath,
        final NormalizedNode<?, ?> inputStructure) throws IOException {
	QName lastcomp = scPath.getLastComponent();
	URI ns = lastcomp.getNamespace();
    final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.
            createExclusiveWriter(JSONCodecFactory.create(context), scPath, scPath.getLastComponent().getNamespace(),
                JsonWriterFactory.createJsonWriter(writer));
    final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream);
    nodeWriter.write(inputStructure);

    nodeWriter.close();
    return writer.toString();
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:23,代码来源:FpcCodecUtils.java

示例10: toXML

import java.io.Writer; //导入方法依赖的package包/类
public String toXML(Writer writer, Object object, String rootNodeName) throws IOException
{
	HierarchicalStreamWriter hwriter = getDefaultDriver().createWriter(writer);
	toXML(hwriter, object, rootNodeName);

	writer.flush();
	writer.close();

	return writer.toString();
}
 
开发者ID:equella,项目名称:Equella,代码行数:11,代码来源:TLEXStream.java

示例11: saveCrashInfo2File

import java.io.Writer; //导入方法依赖的package包/类
/**
 * 保存错误信息到文件中
 *
 * @return 返回文件名称, 便于将文件传送到服务器
 */
private String saveCrashInfo2File(Throwable ex) {

    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> entry : infos.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        sb.append(key).append("=").append(value).append("\n");
    }

    Writer writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    ex.printStackTrace(printWriter);
    Throwable cause = ex.getCause();
    while (cause != null) {
        cause.printStackTrace(printWriter);
        cause = cause.getCause();
    }
    printWriter.close();
    String result = writer.toString();
    sb.append(result);
    try {
        long timestamp = System.currentTimeMillis();
        String time = formatter.format(new Date());
        String fileName = "crash-" + time + "-" + timestamp + ".log";
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/app_crash/";
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream(path + fileName);
        fos.write(sb.toString().getBytes());
        fos.close();
        return fileName;
    } catch (Exception e) {
        Log.e(TAG, "an error occurred while writing file...", e);
    }
    return null;
}
 
开发者ID:woxingxiao,项目名称:GracefulMovies,代码行数:44,代码来源:CrashHandler.java

示例12: ExToString

import java.io.Writer; //导入方法依赖的package包/类
private String ExToString(Throwable ex) {
    Writer writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    ex.printStackTrace(printWriter);
    Throwable cause = ex.getCause();
    while (cause != null) {
        cause.printStackTrace(printWriter);
        cause = cause.getCause();
    }
    printWriter.close();
    return writer.toString();
}
 
开发者ID:XFY9326,项目名称:KeyBlocker,代码行数:13,代码来源:CrashHandler.java

示例13: evaluate

import java.io.Writer; //导入方法依赖的package包/类
private String evaluate(String template, Map<String, Object> context) throws PebbleException, IOException {
        Writer writer = new StringWriter();

    new PebbleEngine.Builder()
            .loader(new StringLoader())
            .strictVariables(false)
            .build()
            .getTemplate(template)
            .evaluate(writer, context);
    return writer.toString();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:12,代码来源:StringInterpolationTest.java

示例14: getPage

import java.io.Writer; //导入方法依赖的package包/类
public String getPage(String filename, Map<String, Object> data) {
    Writer stream = new StringWriter();
    try {
        Template template = cfg.getTemplate(HTML_DIR + File.separator + filename);
        template.process(data, stream);
    } catch (IOException | TemplateException e) {
        e.printStackTrace();
    }
    return stream.toString();
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:11,代码来源:PageGenerator.java

示例15: getStackTraceInfo

import java.io.Writer; //导入方法依赖的package包/类
private String getStackTraceInfo( Throwable throwable ) {

        final Writer writer = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(writer);
        throwable.printStackTrace(printWriter);

        return writer.toString();
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:9,代码来源:DbEventRequestProcessor.java


注:本文中的java.io.Writer.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。