|
12 | 12 | import com.intellij.psi.xml.XmlTag; |
13 | 13 | import com.intellij.psi.xml.XmlText; |
14 | 14 | import gnu.trove.THashMap; |
15 | | -import org.apache.commons.io.IOUtils; |
16 | 15 | import org.jetbrains.annotations.NotNull; |
17 | 16 |
|
18 | | -import java.io.IOException; |
19 | | -import java.io.InputStream; |
20 | | -import java.io.StringWriter; |
| 17 | +import java.io.*; |
21 | 18 | import java.util.Map; |
22 | 19 |
|
23 | 20 | public class DefaultViewHelpersProvider implements ViewHelperProvider { |
@@ -55,14 +52,14 @@ private synchronized Map<String, ViewHelper> getStringViewHelperMap(@NotNull Pro |
55 | 52 |
|
56 | 53 | private String readSchema(String schemaLocation) { |
57 | 54 | InputStream resourceAsStream = DefaultViewHelpersProvider.class.getResourceAsStream(schemaLocation); |
58 | | - StringWriter writer = new StringWriter(); |
| 55 | + String schema = ""; |
59 | 56 | try { |
60 | | - IOUtils.copy(resourceAsStream, writer); |
| 57 | + schema = readFromInputStream(resourceAsStream); |
61 | 58 | } catch (IOException e) { |
62 | 59 | e.printStackTrace(); |
63 | 60 | } |
64 | 61 |
|
65 | | - return writer.toString(); |
| 62 | + return schema; |
66 | 63 | } |
67 | 64 |
|
68 | 65 | private class ViewHelperSchemaRecursiveElementVisitor extends XmlRecursiveElementVisitor { |
@@ -137,4 +134,25 @@ String extractDocumentation(XmlTag attributeTag) { |
137 | 134 | return attributeDocumentation.toString(); |
138 | 135 | } |
139 | 136 | } |
| 137 | + |
| 138 | + private String readFromInputStream(InputStream inputStream) |
| 139 | + throws IOException { |
| 140 | + StringBuilder resultStringBuilder = new StringBuilder(); |
| 141 | + try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { |
| 142 | + String line; |
| 143 | + while ((line = br.readLine()) != null) { |
| 144 | + resultStringBuilder.append(line).append("\n"); |
| 145 | + } |
| 146 | + } finally { |
| 147 | + if (inputStream != null) { |
| 148 | + try { |
| 149 | + inputStream.close(); |
| 150 | + } catch (IOException e) { |
| 151 | + e.printStackTrace(); |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + return resultStringBuilder.toString(); |
| 157 | + } |
140 | 158 | } |
0 commit comments