本文整理汇总了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);
}
示例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;
}
示例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;
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
示例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();
}
示例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);
}
示例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 ();
}
示例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();
}
示例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);
}
}
示例15: getStackTrace
import java.io.StringWriter; //导入方法依赖的package包/类
private String getStackTrace(Exception ex) {
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
return sw.toString();
}