當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。