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