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


Java StringWriter.flush方法代码示例

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


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

示例1: relativizeExternalReferences

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Rewrites external references contained in SVG files.
 *
 * @param path the path of the file to be processed
 */
public static byte[] relativizeExternalReferences(String path)
                                                         throws IOException {
  // use the GenericDOMImplementation here because
  // SVGDOMImplementation adds unwanted attributes to SVG elements
  final SAXDocumentFactory fac = new SAXDocumentFactory(
    new GenericDOMImplementation(),
    XMLResourceDescriptor.getXMLParserClassName());

  final URL here = new URL("file", null, new File(path).getCanonicalPath());
  final StringWriter sw = new StringWriter();

  try {
    final Document doc = fac.createDocument(here.toString());
    relativizeElement(doc.getDocumentElement());
    DOMUtilities.writeDocument(doc, sw);
  }
  catch (DOMException e) {
    throw (IOException) new IOException().initCause(e);
  }

  sw.flush();
  return sw.toString().getBytes();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:29,代码来源:SVGImageUtils.java

示例2: exception2String

import java.io.StringWriter; //导入方法依赖的package包/类
private String exception2String(Throwable e) {

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        pw.flush();
        sw.flush();

        return sw.toString();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:11,代码来源:Logger.java

示例3: getBeakerCodeCells

import java.io.StringWriter; //导入方法依赖的package包/类
private List<BeakerCodeCell> getBeakerCodeCells(Object value) {
  List<BeakerCodeCell> beakerCodeCellList = null;
  StringWriter sw = new StringWriter();
  JsonGenerator jgen = null;
  try {
    jgen = objectMapper.getFactory().createGenerator(sw);
    objectSerializer.writeObject(value, jgen, true);
    jgen.flush();
    sw.flush();
    beakerCodeCellList = Arrays.asList(objectMapper.readValue(sw.toString(), BeakerCodeCell[].class));
  } catch (IOException e) {
    e.printStackTrace();
  }

  return beakerCodeCellList;
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:17,代码来源:GetCodeCellsHandler.java

示例4: decompile

import java.io.StringWriter; //导入方法依赖的package包/类
@Override
public String decompile(InputStream inputStream, String entryName) throws IOException {
  logger.debug("Decompiling... {}", entryName);
  File tempFile = createTempFile(entryName, inputStream);
  tempFile.deleteOnExit();

  String decompiledFileName = getDecompiledFileName(entryName);
  File decompiledFile = new File(decompiledFileName);
  decompiledFile.getParentFile().mkdirs();

  StringWriter pw = new StringWriter();
  try {
    com.strobel.decompiler.Decompiler.decompile(tempFile.getAbsolutePath(), new PlainTextOutput(pw));
  } catch (Exception e) {
    logger.info("Error while decompiling {}. " , entryName);
    throw e;
  }
  pw.flush();

  String decompiledFileContent = pw.toString();
  FileUtils.writeStringToFile(decompiledFile, decompiledFileContent);
  return decompiledFileContent;
}
 
开发者ID:fergarrui,项目名称:custom-bytecode-analyzer,代码行数:24,代码来源:ZipEntryDecompiler.java

示例5: nullSafeSet

import java.io.StringWriter; //导入方法依赖的package包/类
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
        throws HibernateException, SQLException
{
    if (value == null)
    {
        st.setNull(index, Types.VARCHAR);
        return;
    }
    try
    {
        final ObjectMapper mapper = new ObjectMapper();
        final StringWriter w = new StringWriter();
        mapper.writeValue(w, value);
        w.flush();
        st.setObject(index, w.toString(), Types.VARCHAR);
    } catch (final Exception ex)
    {
        throw new RuntimeException("Failed to convert Invoice to String: " + ex.getMessage(), ex);
    }

}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:23,代码来源:JsonUserType.java

示例6: testWriteComment

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Test of main method, of class TestXMLStreamWriter.
 */
@Test
public void testWriteComment() {
    try {
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a:html href=\"http://java.sun.com\"><!--This is comment-->java.sun.com</a:html>";
        XMLOutputFactory f = XMLOutputFactory.newInstance();
        // f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
        // Boolean.TRUE);
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = f.createXMLStreamWriter(sw);
        writer.writeStartDocument("UTF-8", "1.0");
        writer.writeStartElement("a", "html", "http://www.w3.org/TR/REC-html40");
        writer.writeAttribute("href", "http://java.sun.com");
        writer.writeComment("This is comment");
        writer.writeCharacters("java.sun.com");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        sw.flush();
        StringBuffer sb = sw.getBuffer();
        System.out.println("sb:" + sb.toString());
        Assert.assertTrue(sb.toString().equals(xml));
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:XMLStreamWriterTest.java

示例7: exc2String

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * 
 */
public static String exc2String(Throwable t) {
    StringWriter writer = new StringWriter();
    t.printStackTrace(new PrintWriter(writer));
    writer.flush();
    return writer.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:Utils.java

示例8: getLastExceptionAsString

import java.io.StringWriter; //导入方法依赖的package包/类
public String getLastExceptionAsString()
{
    String result = null;

	readLock.lock();
    try
    {
     if (lastException != null)
     {
         StringWriter sw = new StringWriter();
         PrintWriter  pw = new PrintWriter(sw, true);
         
         lastException.printStackTrace(pw);
         
         pw.flush();
         sw.flush();
         
         result = sw.toString();
     }
     
     return(result);
	}
	finally
	{
		readLock.unlock();
	}
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:28,代码来源:BulkImportStatusImpl.java

示例9: exception2String

import java.io.StringWriter; //导入方法依赖的package包/类
public static final String exception2String(Throwable e) {

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        pw.flush();
        sw.flush();
        return sw.toString();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:10,代码来源:DataConvertHelper.java

示例10: check

import java.io.StringWriter; //导入方法依赖的package包/类
void check(TreePath path, Name name) {
    StringWriter out = new StringWriter();
    DocCommentTree dc = trees.getDocCommentTree(path);
    printer.print(dc, out);
    out.flush();
    String found = out.toString().replace(NEWLINE, "\n");

    /*
     * Look for the first block comment after the first occurrence
     * of name, noting that, block comments with BI_MARKER may
     * very well be present.
     */
    int start = test.useBreakIterator
            ? source.indexOf("\n/*\n" + BI_MARKER + "\n", findName(source, name))
            : source.indexOf("\n/*\n", findName(source, name));
    int end = source.indexOf("\n*/\n", start);
    int startlen = start + (test.useBreakIterator ? BI_MARKER.length() + 1 : 0) + 4;
    String expect = source.substring(startlen, end + 1);
    if (!found.equals(expect)) {
        if (test.useBreakIterator) {
            System.err.println("Using BreakIterator");
        }
        System.err.println("Expect:\n" + expect);
        System.err.println("Found:\n" + found);
        error("AST mismatch for " + name);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:DocCommentTester.java

示例11: validate

import java.io.StringWriter; //导入方法依赖的package包/类
private static void validate(A4Solution sol) throws Exception {
	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);
	sol.writeXML(pw, null, null);
	pw.flush();
	sw.flush();
	String txt = sw.toString();
	A4SolutionReader.read(new ArrayList<Sig>(), new XMLNode(new StringReader(txt))).toString();
	StaticInstanceReader.parseInstance(new StringReader(txt));
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:11,代码来源:SimpleCLI.java

示例12: prepareCrashReport

import java.io.StringWriter; //导入方法依赖的package包/类
/** This method prepares the crash report. */
private static String prepareCrashReport(Thread thread, Throwable ex, String email, String problem) {
	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);
	pw.printf("Alloy Analyzer %s crash report (Build Date = %s) (Commit = %s)\n", Version.version(),
			Version.commit);
	pw.printf("\n========================= Email ============================\n%s\n",
			Util.convertLineBreak(email).trim());
	pw.printf("\n========================= Problem ==========================\n%s\n",
			Util.convertLineBreak(problem).trim());
	pw.printf("\n========================= Thread Name ======================\n%s\n", thread.getName().trim());
	if (ex != null)
		pw.printf("\n========================= Stack Trace ======================\n%s\n", dump(ex));
	pw.printf("\n========================= Preferences ======================\n");
	try {
		for (String key : Preferences.userNodeForPackage(Util.class).keys()) {
			String value = Preferences.userNodeForPackage(Util.class).get(key, "");
			pw.printf("%s = %s\n", key.trim(), value.trim());
		}
	} catch (BackingStoreException bse) {
		pw.printf("BackingStoreException occurred: %s\n", bse.toString().trim());
	}
	pw.printf("\n========================= System Properties ================\n");
	pw.println("Runtime.freeMemory() = " + Runtime.getRuntime().freeMemory());
	pw.println("nRuntime.totalMemory() = " + Runtime.getRuntime().totalMemory());
	for (Map.Entry<Object,Object> e : System.getProperties().entrySet()) {
		String k = String.valueOf(e.getKey()), v = String.valueOf(e.getValue());
		pw.printf("%s = %s\n", k.trim(), v.trim());
	}
	pw.printf("\n========================= The End ==========================\n\n");
	pw.close();
	sw.flush();
	return sw.toString();
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:35,代码来源:MailBug.java

示例13: doErrorJSON

import java.io.StringWriter; //导入方法依赖的package包/类
@SuppressWarnings("static-access")
public static String doErrorJSON(HttpServletRequest request,HttpServletResponse response, 
		IMSJSONRequest json, String message, Exception e) 
	throws java.io.IOException 
{
	response.setContentType(APPLICATION_JSON);
	Map<String, Object> jsonResponse = new TreeMap<String, Object>();

	Map<String, String> status = null;
	if ( json == null ) {
		status = IMSJSONRequest.getStatusFailure(message);
	} else {
		status = json.getStatusFailure(message);
		if ( json.base_string != null ) {
			jsonResponse.put("base_string", json.base_string);
		}
	}
	jsonResponse.put(IMSJSONRequest.STATUS, status);
	if ( e != null ) {
		jsonResponse.put("exception", e.getLocalizedMessage());
		try {
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw, true);
			e.printStackTrace(pw);
			pw.flush();
			sw.flush();
			jsonResponse.put("traceback", sw.toString() );
		} catch ( Exception f ) {
			jsonResponse.put("traceback", f.getLocalizedMessage());
		}
	}
	Gson gson = new Gson(); 
	String jsonText = gson.toJson(jsonResponse);
	PrintWriter out = response.getWriter();
	out.println(jsonText);
	return jsonText;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:IMSJSONRequest.java

示例14: runTest

import java.io.StringWriter; //导入方法依赖的package包/类
private void runTest(String code, String expectedDesugar) throws Exception {
    List<JavaFileObject> files = List.nil();

    for (String file : code.split("---")) {
        files = files.prepend(new ToolBox.JavaSource(file));
    }

    Path classes = Paths.get("classes");

    if (Files.exists(classes)) {
        tb.cleanDirectory(classes);
    } else {
        Files.createDirectories(classes);
    }

    JavacTool compiler = (JavacTool) ToolProvider.getSystemJavaCompiler();
    StringWriter out = new StringWriter();
    Context context = new Context();
    TestLower.preRegister(context);
    Iterable<String> options = Arrays.asList("-d", classes.toString());
    JavacTask task = (JavacTask) compiler.getTask(out, null, null, options, null, files, context);

    task.generate();

    out.flush();

    String actual = out.toString().replace(System.getProperty("line.separator"), "\n");

    if (!expectedDesugar.equals(actual)) {
        throw new IllegalStateException("Actual does not match expected: " + actual);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:BoxingAndSuper.java

示例15: message

import java.io.StringWriter; //导入方法依赖的package包/类
private String message() throws IOException, TemplateException {
	Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
	cfg.setClassForTemplateLoading(EventEmail.class, "");
	cfg.setLocale(Localization.getJavaLocale());
	cfg.setOutputEncoding("utf-8");
	Template template = cfg.getTemplate("confirmation.ftl");
	Map<String, Object> input = new HashMap<String, Object>();
	input.put("msg", MESSAGES);
	input.put("const", CONSTANTS);
	input.put("subject", subject());
	input.put("event", event());
	input.put("operation", request().getOperation() == null ? "NONE" : request().getOperation().name());
	if (response().hasCreatedMeetings())
		input.put("created", EventInterface.getMultiMeetings(response().getCreatedMeetings(), true, false));
	if (response().hasDeletedMeetings())
		input.put("deleted", EventInterface.getMultiMeetings(response().getDeletedMeetings(), true, false));
	if (response().hasCancelledMeetings())
		input.put("cancelled", EventInterface.getMultiMeetings(response().getCancelledMeetings(), true, false));
	if (response().hasUpdatedMeetings())
		input.put("updated", EventInterface.getMultiMeetings(response().getUpdatedMeetings(), true, false));
	if (request().hasMessage())
		input.put("message", request().getMessage());
	if (request().getEvent().getId() != null) {
		if (event().hasMeetings()) {
			input.put("meetings", EventInterface.getMultiMeetings(event().getMeetings(), true, false));
		} else
			input.put("meetings", new TreeSet<MultiMeetingInterface>());
	}
	input.put("version", MESSAGES.pageVersion(Constants.getVersion(), Constants.getReleaseDate()));
	input.put("ts", new Date());
	input.put("link", ApplicationProperty.UniTimeUrl.value());
	input.put("sessionId", iRequest.getSessionId());
	
	StringWriter s = new StringWriter();
	template.process(input, new PrintWriter(s));
	s.flush(); s.close();

	return s.toString();
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:40,代码来源:EventEmail.java


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