List of usage examples for java.io Writer close
public abstract void close() throws IOException;
From source file:jetbrick.tools.chm.TemplateWriter.java
private void renderTemplate(String fileName, Map<String, Object> context, String templateName) throws Exception { File file = new File(Config.apiLocation, fileName); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs();/* w w w. j a v a2s. c om*/ } System.out.println(file); String templateContent = IOUtils.toString(getClass().getResourceAsStream(templateName), "utf-8"); VelocityContext ctx = new VelocityContext(context); Writer writer = new OutputStreamWriter(new FileOutputStream(file), Config.encoding); ve.evaluate(ctx, writer, "", templateContent); writer.close(); }
From source file:java2typescript.jackson.module.DefinitionGeneratorTest.java
@Test public void externalModuleFormat() throws IOException { // Arrange//from w w w.j a v a2s.c o m Module module = createTestModule(); Writer out = new StringWriter(); // Act new ExternalModuleFormatWriter().write(module, out); out.close(); System.out.println(out); // Assert ExpectedOutputChecker.checkOutputFromFile(out); }
From source file:java2typescript.jackson.module.DefinitionGeneratorTest.java
@Test public void classWithMethodReturningThis() throws IOException { // Arrange/*from w w w. j a va 2 s. c om*/ Module module = TestUtil.createTestModule(null, RecursiveTestClass.class); Writer out = new StringWriter(); // Act new ExternalModuleFormatWriter().write(module, out); out.close(); System.out.println(out); // Assert ExpectedOutputChecker.checkOutputFromFile(out); }
From source file:com.google.mr4c.content.AbstractContentFactory.java
public void writeContent(URI uri, String text) throws IOException { Writer writer = getWriterForContent(uri); try {//from w ww. j a va 2s. c o m writer.write(text); } finally { writer.close(); } }
From source file:doc.doclets.WorkbenchHelpDoclet.java
/** * Generate documentation for all parameter fields of an actor. * /*from w w w . j a v a2 s . com*/ * @param classDoc The ClassDoc for the class we are documenting. * @param fieldBaseClass The base class for the field we are documenting. * @param attrTemplate * @return The documentation for all fields that are derived from the fieldBaseClass parameter. */ private static String _generateFieldDocumentation(final ClassDoc classDoc, String attrTemplate) throws Exception { Writer resultWriter = new StringWriter(); try { Context velocityContext = new VelocityContext(); velocityContext.put("actorName", _generateShortClassName(classDoc)); velocityContext.put("allActorAttributes", _generateActorAttributeElements(classDoc, Class.forName("ptolemy.data.expr.Parameter"))); velocity.evaluate(velocityContext, resultWriter, "actor help template", attrTemplate); return resultWriter.toString(); } finally { try { resultWriter.close(); } catch (Exception e) { } } }
From source file:UnpackedJarFile.java
public static void close(Writer thing) { if (thing != null) { try {//from w w w. j a v a2s . c o m thing.close(); } catch (Exception ignored) { } } }
From source file:com.athena.chameleon.web.system.controller.SystemController.java
/** * //from ww w .j a v a2 s.c o m * * @param request * @param response * @param modelMap * @param session * @return * @throws Exception */ @RequestMapping("/saveCode.do") public String saveCode(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, HttpSession session) throws Exception { String filteringCode = request.getParameter("filteringCode"); File filteringResource = new File(PropertyUtil.class.getResource("/filtering.properties").getFile()); Writer output = new BufferedWriter(new FileWriter(filteringResource)); output.write(filteringCode); output.close(); String contextCode = request.getParameter("contextCode"); File contextResource = new File(PropertyUtil.class.getResource("/config/context.properties").getFile()); output = new BufferedWriter(new FileWriter(contextResource)); output.write(contextCode); output.close(); modelMap.addAttribute("result", true); return "jsonView"; }
From source file:com.google.mr4c.content.AbstractContentFactory.java
public void writeContent(URI uri, Properties props) throws IOException { Writer writer = getWriterForContent(uri); try {/* www .j a va 2 s .co m*/ props.store(writer, ""); } finally { writer.close(); } }
From source file:com.amazonaws.scala.ProjectGenerator.java
/** * Generates a multi-module maven project structure under * {@code $baseDir/project} from the configuration in * {@code $baseDir/config.yaml}.// w w w.ja va2 s .c o m */ public void generate() throws IOException, TemplateException { File configFile = new File(baseDir, "config.yaml"); AggregatorModel aggregator = mapper.readValue(configFile, AggregatorModel.class); File project = new File(baseDir, "project"); mkdir(project); // Generate the individual client modules. Template pom = freemarker.getPomTemplate(); for (ModuleModel module : aggregator.getModules()) { File dir = new File(project, "aws-scala-sdk-" + module.getName()); mkdir(dir); Writer writer = new FileWriter(new File(dir, "pom.xml")); try { pom.process(module, writer); } finally { writer.close(); } } // Generate the aggregator module. Template agg = freemarker.getAggregatorTemplate(); Writer writer = new FileWriter(new File(project, "pom.xml")); try { agg.process(aggregator, writer); } finally { writer.close(); } }
From source file:com.google.mr4c.content.AbstractContentFactory.java
public void writeContent(URI uri, Reader reader) throws IOException { Writer writer = getWriterForContent(uri); try {/*w w w . j a v a 2 s.co m*/ IOUtils.copy(reader, writer); } finally { writer.close(); } }