Example usage for java.io Writer close

List of usage examples for java.io Writer close

Introduction

In this page you can find the example usage for java.io Writer close.

Prototype

public abstract void close() throws IOException;

Source Link

Document

Closes the stream, flushing it first.

Usage

From source file:com.streamsets.datacollector.http.TestLogServlet.java

@Before
public void setup() throws Exception {
    server = null;//from   w  ww  .j  a va  2  s.c o  m
    baseDir = createTestDir();
    String log4jConf = new File(baseDir, "log4j.properties").getAbsolutePath();
    File logFile = new File(baseDir, "x.log");
    Writer writer = new FileWriter(log4jConf);
    IOUtils.write(LogUtils.LOG4J_APPENDER_STREAMSETS_FILE_PROPERTY + "=" + logFile.getAbsolutePath(), writer);
    writer.close();
    Assert.assertTrue(new File(baseDir, "etc").mkdir());
    Assert.assertTrue(new File(baseDir, "data").mkdir());
    Assert.assertTrue(new File(baseDir, "log").mkdir());
    Assert.assertTrue(new File(baseDir, "web").mkdir());
    System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.CONFIG_DIR, baseDir + "/etc");
    System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR, baseDir + "/data");
    System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.LOG_DIR, baseDir + "/log");
    System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.STATIC_WEB_DIR, baseDir + "/web");
}

From source file:com.palantir.stash.stashbot.servlet.BuildSuccessReportingServlet.java

private void printOutput(HttpServletRequest req, HttpServletResponse res) throws IOException {
    res.reset();//from  w  w  w . j av a 2  s . c  o m
    res.setStatus(200);
    res.setContentType("text/plain;charset=UTF-8");
    Writer w = res.getWriter();
    w.append("Status Updated");
    w.close();
}

From source file:com.netxforge.oss2.config.GroupFactory.java

/** {@inheritDoc} */
protected void saveXml(String data) throws IOException {
    if (data != null) {
        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(m_groupsConfFile), "UTF-8");
        fileWriter.write(data);/* ww w  .jav a2 s . c om*/
        fileWriter.flush();
        fileWriter.close();
    }
}

From source file:de.ingrid.iplug.csw.dsc.cache.UpdateJob.java

/**
 * Write the last exectution date of this job.
 * //from w w w . jav  a2s.c o m
 * @param Date
 */
public void writeLastExecutionDate(Date date) {
    File dateFile = new File(DATE_FILENAME);

    try {
        Writer output = new BufferedWriter(new FileWriter(dateFile));
        output.write(DATEFORMAT.format(date));
        output.close();
    } catch (Exception e) {
        // delete the date file to make sure we do not use a corrupted
        // version
        if (dateFile.exists())
            dateFile.delete();
        log.warn(
                "Could not write to " + DATE_FILENAME + ". " + "The update job fetches all records next time.");
    }
}

From source file:com.github.swt_release_fetcher.Artifact.java

public void generatePom(File pomFile) throws IOException {
    Velocity.addProperty("resource.loader", "class");
    Velocity.addProperty("class.resource.loader.class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    Velocity.init();/*w  w w.j a v a  2s . c  o m*/
    VelocityContext context = new VelocityContext();

    context.put("repositoryUrl", REPOSITORY_URL);
    context.put("version", artifactVersion);
    context.put("artifactId", artifactId);

    Writer writer = new FileWriter(pomFile);
    try {
        Velocity.mergeTemplate("pom.vm", "UTF-8", context, writer);
    } finally {
        writer.close();
    }
}

From source file:com.johnson3yo.dubem.plugin.ArtifactWizardMojo.java

private void updateAppServletXml_JFileChooser(String functionName) throws IOException, JDOMException {

    getLog().info("please select app-servlet.xml from foundation-guiwar  ");

    JFileChooser fc = new JFileChooser();

    int retValue = fc.showOpenDialog(new JPanel());

    if (retValue == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();

        SAXBuilder builder = new SAXBuilder();

        Document document = (Document) builder.build(f);
        Element rootNode = document.getRootElement();

        List<Element> list = rootNode.getChildren("component-scan",
                Namespace.getNamespace("http://www.springframework.org/schema/context"));

        Element e = list.get(0);//from   ww w.  j  a va2 s.c o m

        String cnt = "<context:exclude-filter type=\"regex\" expression=\"pegasus\\.module\\."
                + functionName.toLowerCase() + "\\..*\" />";

        e.addContent(cnt);

        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()) {
            @Override
            public String escapeElementEntities(String str) {
                return str;
            }
        };

        Writer writer = new OutputStreamWriter(new FileOutputStream(f), "utf-8");
        outputter.output(document, writer);
        writer.close();
    } else {
        getLog().info("Next time select a file.");
        System.exit(1);
    }

}

From source file:com.netxforge.oss2.config.NotifdConfigFactory.java

/** {@inheritDoc} */
@Override/* ww  w  .ja v  a 2  s. c  o m*/
protected void saveXml(String xml) throws IOException {
    if (xml != null) {
        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(m_notifdConfFile), "UTF-8");
        fileWriter.write(xml);
        fileWriter.flush();
        fileWriter.close();
    }
}

From source file:com.streamsets.pipeline.stage.origin.spooldir.TestTextSpoolDirSource.java

private File createLogFile(String charset) throws Exception {
    File f = new File(createTestDir(), "test.log");
    Writer writer = new OutputStreamWriter(new FileOutputStream(f), charset);
    IOUtils.write(LINE1 + "\n", writer);
    IOUtils.write(LINE2, writer);/*from  w ww  . j a  v  a 2s.  co m*/
    writer.close();
    return f;
}

From source file:com.tobedevoured.solrsail.SolrConfig.java

/**
 * Install Solr Config t the local file system by extracting from the
 * SolrSail jar// w  w w  .ja  v  a  2s . co  m
 * 
 * @param jar File
 * @throws IOException
 */
public void installFromJar(File jar) throws IOException {
    logger.info("Installing config from Jar to {}", this.getSolrHome());
    logger.debug("Opening Jar {}", jar.toString());

    JarFile jarFile = new JarFile(jar);

    for (Enumeration<JarEntry> enumeration = jarFile.entries(); enumeration.hasMoreElements();) {
        JarEntry entry = enumeration.nextElement();

        if (!entry.getName().equals("solr/") && entry.getName().startsWith("solr/")) {
            StringBuilder dest = new StringBuilder(getSolrHome()).append(File.separator)
                    .append(entry.getName().replaceFirst("solr/", ""));

            File file = new File(dest.toString());

            if (entry.isDirectory()) {
                file.mkdirs();
            } else {
                if (file.getParentFile() != null) {
                    file.getParentFile().mkdirs();
                }

                logger.debug("Copying {} to {}", entry.getName(), dest.toString());

                InputStream input = jarFile.getInputStream(entry);
                Writer writer = new FileWriter(file.getAbsoluteFile());
                IOUtils.copy(input, writer);

                input.close();

                writer.close();
            }
        }
    }
}

From source file:de.kp.ames.web.core.rss.RssProvider.java

public String getFeed() {

    try {//w w w . j av a 2  s .  c  o m

        SyndFeed feed = new SyndFeedImpl();

        /* 
         * Describe feed
         */
        feed.setTitle(FEED_TITLE);
        feed.setDescription(FEED_DESC);

        feed.setFeedType(FEED_TYPE);
        feed.setUri(FEED_URI);

        /* 
         * Finally we get feeds from processor
         */
        List<SyndEntry> entries = processor.getEntries();
        feed.setEntries(entries);

        Writer writer = new StringWriter();

        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);

        String content = writer.toString();
        writer.close();

        return content;

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
    }

    return null;

}