~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/config/generator/ConfigurationUtil.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
4
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
5
 *  you may not use this file except in compliance with the License.
16
16
 
17
17
package net.sf.ehcache.config.generator;
18
18
 
19
 
import java.io.ByteArrayOutputStream;
20
19
import java.io.PrintWriter;
 
20
import java.io.StringWriter;
21
21
 
22
22
import net.sf.ehcache.CacheManager;
23
23
import net.sf.ehcache.config.CacheConfiguration;
46
46
     * @return text representing the cacheManager {@link Configuration}
47
47
     */
48
48
    public static String generateCacheManagerConfigurationText(CacheManager cacheManager) {
49
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
50
 
        PrintWriter out = new PrintWriter(baos);
51
 
        XMLGeneratorVisitor configGenerator = new XMLGeneratorVisitor(out);
52
 
        configGenerator.disableOutputBehavior(OutputBehavior.OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES);
53
 
        visitConfiguration(cacheManager, configGenerator);
54
 
        out.flush();
55
 
        out.close();
56
 
        return baos.toString();
 
49
        StringWriter output = new StringWriter();
 
50
        PrintWriter writer = new PrintWriter(output);
 
51
        try {
 
52
            XMLGeneratorVisitor configGenerator = new XMLGeneratorVisitor(writer);
 
53
            configGenerator.disableOutputBehavior(OutputBehavior.OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES);
 
54
            visitConfiguration(cacheManager, configGenerator);
 
55
            writer.flush();
 
56
        } finally {
 
57
            writer.close();
 
58
        }
 
59
        return output.toString();
57
60
    }
58
61
 
59
62
    /**
75
78
     * @return text representing the {@link Configuration}
76
79
     */
77
80
    public static String generateCacheManagerConfigurationText(Configuration configuration) {
78
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
79
 
        PrintWriter out = new PrintWriter(baos);
80
 
        XMLGeneratorVisitor configGenerator = new XMLGeneratorVisitor(out);
81
 
        configGenerator.disableOutputBehavior(OutputBehavior.OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES);
82
 
        visitConfiguration(configuration, configGenerator);
83
 
        out.flush();
84
 
        out.close();
85
 
        return baos.toString();
 
81
        StringWriter output = new StringWriter();
 
82
        PrintWriter writer = new PrintWriter(output);
 
83
        try {
 
84
            XMLGeneratorVisitor configGenerator = new XMLGeneratorVisitor(writer);
 
85
            configGenerator.disableOutputBehavior(OutputBehavior.OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES);
 
86
            visitConfiguration(configuration, configGenerator);
 
87
            writer.flush();
 
88
        } finally {
 
89
            writer.close();
 
90
        }
 
91
        return output.toString();
86
92
    }
87
93
 
88
94
    /**
104
110
     * @return text representing the {@link CacheConfiguration}
105
111
     */
106
112
    public static String generateCacheConfigurationText(Configuration configuration, CacheConfiguration cacheConfiguration) {
107
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
108
 
        PrintWriter out = new PrintWriter(baos);
109
 
        XMLGeneratorVisitor configGenerator = new XMLGeneratorVisitor(out);
110
 
        configGenerator.disableOutputBehavior(OutputBehavior.OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES);
111
 
        visitCacheConfiguration(configuration, cacheConfiguration, configGenerator);
112
 
        out.flush();
113
 
        out.close();
114
 
        return baos.toString();
 
113
        StringWriter output = new StringWriter();
 
114
        PrintWriter writer = new PrintWriter(output);
 
115
        try {
 
116
            XMLGeneratorVisitor configGenerator = new XMLGeneratorVisitor(writer);
 
117
            configGenerator.disableOutputBehavior(OutputBehavior.OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES);
 
118
            visitCacheConfiguration(configuration, cacheConfiguration, configGenerator);
 
119
            writer.flush();
 
120
        } finally {
 
121
            writer.close();
 
122
        }
 
123
        return output.toString();
115
124
    }
116
125
 
117
126
    /**