Skip to content

Commit

Permalink
Prefer a Reader above raw InputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Jun 21, 2023
1 parent 63e7dc9 commit eba27bb
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import static com.thoughtworks.go.config.parser.GoConfigClassLoader.classParser;
import static com.thoughtworks.go.util.CachedDigestUtils.md5Hex;
import static com.thoughtworks.go.util.XmlUtils.buildXmlDocument;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.IOUtils.toInputStream;

public class MagicalGoConfigXmlLoader {
public static final List<GoConfigPreprocessor> PREPROCESSORS = List.of(
Expand Down Expand Up @@ -150,11 +149,14 @@ private Element parseInputStream(InputStream inputStream) throws Exception {
}

public <T> T fromXmlPartial(String partial, Class<T> o) throws Exception {
return fromXmlPartial(toInputStream(partial, UTF_8), o);
return fromXmlPartial(new SAXBuilder().build(new StringReader(partial)), o);
}

public <T> T fromXmlPartial(InputStream inputStream, Class<T> o) throws Exception {
Document document = new SAXBuilder().build(inputStream);
public <T> T fromXmlPartial(InputStream inputStream, Class<T> clazz) throws Exception {
return fromXmlPartial(new SAXBuilder().build(inputStream), clazz);
}

private <T> T fromXmlPartial(Document document, Class<T> o) {
Element element = document.getRootElement();
return classParser(element, o, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse();
}
Expand Down

0 comments on commit eba27bb

Please sign in to comment.