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


Java StringWriter.toString方法代码示例

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


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

示例1: getContentHeightOfEditor

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Calculates the preferred height of the editor pane with the given fixed width.
 *
 * @param width
 *            the width of the pane
 * @return the preferred height given the current editor pane content or {@code -1} if there was
 *         a problem. Value will never exceed {@link WorkflowAnnotation#MAX_HEIGHT}
 */
private int getContentHeightOfEditor(final int width) {
	HTMLDocument document = (HTMLDocument) editPane.getDocument();
	StringWriter writer = new StringWriter();
	try {
		editPane.getEditorKit().write(writer, document, 0, document.getLength());
	} catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
		// should not happen
		return -1;
	}
	String comment = writer.toString();
	comment = AnnotationDrawUtils.removeStyleFromComment(comment);

	int maxHeight = model.getSelected() instanceof ProcessAnnotation ? ProcessAnnotation.MAX_HEIGHT
			: OperatorAnnotation.MAX_HEIGHT;
	return Math.min(
			AnnotationDrawUtils.getContentHeight(
					AnnotationDrawUtils.createStyledCommentString(comment, model.getSelected().getStyle()), width),
					maxHeight);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:AnnotationsDecorator.java

示例2: _getEventIntsAsString

import java.io.StringWriter; //导入方法依赖的package包/类
private String _getEventIntsAsString(int[] intArray)
{
  if(intArray!=null)
  {
    StringWriter sw = new StringWriter();
    for(int i=0; i<intArray.length; ++i)
    {
      if(i!=0)
        sw.append(',');
      sw.append(String.valueOf(intArray[i]));
    }
    return sw.toString();
  }
  else
    return null;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:ChartBean.java

示例3: log

import java.io.StringWriter; //导入方法依赖的package包/类
@Override
public void log(Kind msgKind, String message, String messageGroup,
		Throwable throwable) {
	StringWriter sw = new StringWriter();
	if(throwable != null){
		throwable.printStackTrace(new PrintWriter(sw));
	}
	String stackTrace = sw.toString();
	System.out.println(getKindString(msgKind)+" [" +messageGroup + "] " + message + " "+getCallerString()+"\n"+ stackTrace);
	switch (msgKind) {
	case UserERROR:
		errorTrace.add(getKindString(msgKind) + " [" +messageGroup + "] " + message + " "  + " "+getCallerString());
		break;
	case DevERROR:
		errorTrace.add(getKindString(msgKind) + " [" +messageGroup + "] " + message + " "  + " "+getCallerString());
		break;
	default:
		break;
	}
}
 
开发者ID:eclipse,项目名称:gemoc-studio,代码行数:21,代码来源:ErrorAwareMessagingSystem.java

示例4: getInkValueWithSelections

import java.io.StringWriter; //导入方法依赖的package包/类
public String getInkValueWithSelections() throws JSONException, UnsupportedEncodingException {
	JSONArray inkValueJson;
	String inkValue = getInkValue();
	if (inkValue != null && inkValue.length() > 0) {
		inkValueJson = new JSONArray(inkValue);
	} else {
		inkValueJson = new JSONArray();
	}
	StringBuilder selectionSetValueIds = new StringBuilder();
	HashMap<String, String> selectionSetValueIdToStrokesIdMap = getSelectionSetValueIdToStrokesIdMap();
	Iterator<String> it = getSelectionValueIds().iterator();
	while (it.hasNext()) {
		if (selectionSetValueIds.length() > 0) {
			selectionSetValueIds.append(WebUtil.ID_SEPARATOR_STRING);
		}
		String selectionSetValueId = it.next();
		if (selectionSetValueIdToStrokesIdMap.containsKey(selectionSetValueId)) {
			selectionSetValueIds.append(selectionSetValueIdToStrokesIdMap.get(selectionSetValueId));
		}
	}
	inkValueJson.put(selectionSetValueIds.toString());
	StringWriter output = new StringWriter();
	inkValueJson.write(output);
	return output.toString();
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:26,代码来源:InputModel.java

示例5: readFully

import java.io.StringWriter; //导入方法依赖的package包/类
static String readFully(Reader reader) throws IOException {
	try {
		StringWriter writer = new StringWriter();
		char[] buffer = new char[1024];
		int count;
		while ((count = reader.read(buffer)) != -1) {
			writer.write(buffer, 0, count);
		}
		return writer.toString();
	} finally {
		reader.close();
	}
}
 
开发者ID:Spencer231,项目名称:GifImageLoader,代码行数:14,代码来源:Util.java

示例6: getStackTraceMessage

import java.io.StringWriter; //导入方法依赖的package包/类
private String getStackTraceMessage()
{
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    super.printStackTrace(pw);

    return sw.toString();
}
 
开发者ID:dbiir,项目名称:paraflow,代码行数:9,代码来源:ParaFlowException.java

示例7: serialize

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Serialize a list of objects to a JSON String.
 *
 * @param map The map of objects to serialize.
 */
public String serialize(Map<String, T> map) throws IOException {
    StringWriter sw = new StringWriter();
    JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(sw);
    serialize(map, jsonGenerator);
    jsonGenerator.close();
    return sw.toString();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JsonMapper.java

示例8: downloadString

import java.io.StringWriter; //导入方法依赖的package包/类
public String downloadString() {
	try {
		StringWriter writer = new StringWriter();
		for (int i = this.responseStream.read(); i >= 0; i = this.responseStream.read())
			writer.write(i);

		String ret = writer.toString();

		writer.close();
		return ret;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:15,代码来源:HttpClient.java

示例9: toString

import java.io.StringWriter; //导入方法依赖的package包/类
@Override
public String toString() {
    StringWriter s = new StringWriter();
    JFormatter f = new JFormatter(new PrintWriter(s));
    this.generate(f);
    return s.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:JMods.java

示例10: parse

import java.io.StringWriter; //导入方法依赖的package包/类
public static String parse(String templateFileName, AbstractFileWrapper data) {

        // 初始化模板引擎
        VelocityEngine engine = new VelocityEngine();
        engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
        engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

        Properties props = new Properties();

        URL resource = VelocityUtil.class.getClassLoader().getResource(".");
        Objects.requireNonNull(resource);

        // 设置模板目录
        String basePath = resource.getPath() + Const.TEMPLATE_LOCATION_DIR;
        props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,  basePath);
        //设置velocity的编码
        props.setProperty(Velocity.ENCODING_DEFAULT, StandardCharsets.UTF_8.name());
        props.setProperty(Velocity.INPUT_ENCODING,   StandardCharsets.UTF_8.name());
        props.setProperty(Velocity.OUTPUT_ENCODING,  StandardCharsets.UTF_8.name());
        engine.init(props);

        Template template = engine.getTemplate(templateFileName);
        // 设置变量
        VelocityContext ctx = new VelocityContext();

        ctx.put("data", data);

        StringWriter writer = new StringWriter();
        template.merge(ctx, writer);

        return writer.toString();


    }
 
开发者ID:MrHunterZhao,项目名称:CoffeeMaker,代码行数:35,代码来源:VelocityUtil.java

示例11: printStackTrace

import java.io.StringWriter; //导入方法依赖的package包/类
private static void printStackTrace() {

        if (!IS_SHOW_LOG) {
            return;
        }

        Throwable tr = new Throwable();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        tr.printStackTrace(pw);
        pw.flush();
        String message = sw.toString();

        String traceString[] = message.split("\\n\\t");
        StringBuilder sb = new StringBuilder();
        sb.append("\n");
        for (String trace : traceString) {
            if (trace.contains("at com.socks.library.KLog")) {
                continue;
            }
            sb.append(trace).append("\n");
        }
        String[] contents = wrapperContent(STACK_TRACE_INDEX_4, null, sb.toString());
        String tag = contents[0];
        String msg = contents[1];
        String headString = contents[2];
        BaseLog.printDefault(D, tag, headString + msg);
    }
 
开发者ID:weileng11,项目名称:KUtils-master,代码行数:29,代码来源:KLog.java

示例12: makeXml

import java.io.StringWriter; //导入方法依赖的package包/类
private String makeXml ( final Component component ) throws IOException
{
    final XMIResourceImpl xmi = new XMIResourceImpl ();
    xmi.getContents ().add ( EcoreUtil.copy ( component ) );

    final StringWriter writer = new StringWriter ();
    xmi.save ( writer, null );
    return writer.toString ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:ParserDriverProcessor.java

示例13: createLockContents

import java.io.StringWriter; //导入方法依赖的package包/类
private static String createLockContents(final Options options) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  try (final Stream<Path> jvmFiles = Files.walk(options.jvmDirectory());
      final PrintWriter out = new PrintWriter(stringWriter)) {
    out.println("version\t1");
    Stream.concat(Stream.of(options.inputFile(), options.outputFile()), jvmFiles)
        .sorted()
        .forEachOrdered(file -> describeFile(options.workspaceDirectory(), file, out));
  }
  return stringWriter.toString();
}
 
开发者ID:spotify,项目名称:bazel-tools,代码行数:12,代码来源:Main.java

示例14: toJSONString

import java.io.StringWriter; //导入方法依赖的package包/类
public static String toJSONString(double[] array){
	final StringWriter writer = new StringWriter();
	
	try {
		writeJSONString(array, writer);
		return writer.toString();
	} catch(IOException e){
		// This should never happen for a StringWriter
		throw new RuntimeException(e);
	}
}
 
开发者ID:RoccoDev,项目名称:5zig-TIMV-Plugin,代码行数:12,代码来源:JSONArray.java

示例15: getStackTrace

import java.io.StringWriter; //导入方法依赖的package包/类
private String getStackTrace(Exception ex) {
    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:6,代码来源:SposhLogicController.java


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